OwnerCurator extends AbstractHibernateCurator<Owner> { public Owner lockAndLoadByKey(String key) { if (key != null && !key.isEmpty()) { return this.currentSession() .bySimpleNaturalId(Owner.class) .with(new LockOptions(LockMode.PESSIMISTIC_WRITE)) .load(key); } return null; } OwnerCurator(); Owner findOwnerById(String ownerId); @Transactional Owner replicate(Owner owner); @Transactional @Override Owner create(Owner entity); @Transactional Owner getByKeySecure(String key); Owner lockAndLoadByKey(String key); @Transactional Owner getByKey(String key); @Transactional CandlepinQuery<Owner> getByKeys(Collection<String> keys); Owner getByUpstreamUuid(String upstreamUuid); CandlepinQuery<Owner> getOwnersByActiveProduct(Collection<String> productIds); @SuppressWarnings("checkstyle:indentation") CandlepinQuery<Owner> getOwnersWithProducts(Collection<String> productIds); CandlepinQuery<String> getConsumerIds(Owner owner); @SuppressWarnings("unchecked") CandlepinQuery<String> getConsumerIds(String ownerId); CandlepinQuery<String> getConsumerUuids(Owner owner); @SuppressWarnings("unchecked") CandlepinQuery<String> getConsumerUuids(String ownerId);  }
@Test public void testLockAndLoadByKey() { String ownerKey = "test_key"; Owner owner = this.createOwner(ownerKey); this.ownerCurator.flush(); this.ownerCurator.clear(); Owner actual = this.ownerCurator.lockAndLoadByKey(ownerKey); assertNotNull(actual); assertEquals(ownerKey, actual.getKey()); }
@Test public void testLockAndLoadByKeyDoesntLoadBadKey() { String ownerKey = "test_key"; Owner owner = this.createOwner(ownerKey); this.ownerCurator.flush(); this.ownerCurator.clear(); Owner actual = this.ownerCurator.lockAndLoadByKey(ownerKey + "-bad"); assertNull(actual); }
@Test public void testLockAndLoadByKeyDoesntLoadNullKey() { String ownerKey = "test_key"; Owner owner = this.createOwner(ownerKey); this.ownerCurator.flush(); this.ownerCurator.clear(); Owner actual = this.ownerCurator.lockAndLoadByKey(null); assertNull(actual); }