OwnerContentCurator extends AbstractHibernateCurator<OwnerContent> { @Transactional public int clearContentForOwner(Owner owner) { String jpql = "DELETE FROM OwnerContent op " + "WHERE op.owner.id = :owner_id"; return this.getEntityManager() .createQuery(jpql) .setParameter("owner_id", owner.getId()) .executeUpdate(); } OwnerContentCurator(); Content getContentById(Owner owner, String contentId); @Transactional Content getContentById(String ownerId, String contentId); CandlepinQuery<Owner> getOwnersByContent(Content content); CandlepinQuery<Owner> getOwnersByContent(String contentId); Collection<String> getContentUuidsByOwner(Owner owner); Collection<String> getContentUuidsByOwner(String ownerId); CandlepinQuery<Content> getContentByOwner(Owner owner); CandlepinQuery<Content> getContentByOwner(String ownerId); CandlepinQuery<Content> getContentByIds(Owner owner, Collection<String> contentIds); CandlepinQuery<Content> getContentByIds(String ownerId, Collection<String> contentIds); @Transactional long getOwnerCount(Content content); @Transactional boolean contentExists(Owner owner, String contentId); @Transactional boolean isContentMappedToOwner(Content content, Owner owner); @Transactional boolean mapContentToOwner(Content content, Owner owner); @Transactional int mapContentToOwners(Content content, Owner... owners); @Transactional int mapOwnerToContent(Owner owner, Content... content); @Transactional boolean removeOwnerFromContent(Content content, Owner owner); @Transactional int clearOwnersForContent(Content content); @Transactional int clearContentForOwner(Owner owner); @SuppressWarnings("checkstyle:indentation") CandlepinQuery<Content> getContentByVersions(Owner owner, Map<String, Integer> contentVersions); CandlepinQuery<Content> getOrphanedContent(); @Transactional void updateOwnerContentReferences(Owner owner, Map<String, String> contentUuidMap); @Transactional void removeOwnerContentReferences(Owner owner, Collection<String> contentUuids);  }
@Test public void testClearContentForOwner() { Owner owner1 = this.createOwner(); Owner owner2 = this.createOwner(); Owner owner3 = this.createOwner(); Content content1 = this.createContent(); Content content2 = this.createContent(); Content content3 = this.createContent(); this.createOwnerContentMapping(owner1, content1); this.createOwnerContentMapping(owner1, content2); this.createOwnerContentMapping(owner1, content3); this.createOwnerContentMapping(owner2, content1); this.createOwnerContentMapping(owner2, content2); this.createOwnerContentMapping(owner2, content3); this.createOwnerContentMapping(owner3, content1); this.createOwnerContentMapping(owner3, content2); this.createOwnerContentMapping(owner3, content3); this.ownerContentCurator.clearContentForOwner(owner1); assertFalse(this.isContentMappedToOwner(content1, owner1)); assertFalse(this.isContentMappedToOwner(content2, owner1)); assertFalse(this.isContentMappedToOwner(content3, owner1)); assertTrue(this.isContentMappedToOwner(content1, owner2)); assertTrue(this.isContentMappedToOwner(content2, owner2)); assertTrue(this.isContentMappedToOwner(content3, owner2)); assertTrue(this.isContentMappedToOwner(content1, owner3)); assertTrue(this.isContentMappedToOwner(content2, owner3)); assertTrue(this.isContentMappedToOwner(content3, owner3)); }