@Test public void testExecuteWithMatchWithDifferentCase() { final long scopeId = 101L; FindOrInsertSharedResourceByUniqueKeyDbMapper sut = new FindOrInsertSharedResourceByUniqueKeyDbMapper(); sut.setEntityManager(getEntityManager()); SharedResource sr = sut.execute(new SharedResourceRequest("http: assertEquals(scopeId, sr.getStreamScope().getId()); assertNotNull(sr); assertEquals(5L, sr.getId()); }
@SuppressWarnings("unchecked") @Override public SharedResource execute(final SharedResourceRequest inSharedResourceRequest) { if (inSharedResourceRequest.getUniqueKey() == null) { return null; } String uniqueKey = inSharedResourceRequest.getUniqueKey().toLowerCase(); Query q = getEntityManager().createQuery("FROM SharedResource WHERE uniqueKey = :uniqueKey"); q.setParameter("uniqueKey", uniqueKey); List<SharedResource> resources = q.getResultList(); if (resources == null || resources.size() == 0) { SharedResource sr = new SharedResource(); sr.setUniqueKey(uniqueKey); List<StreamScope> scopes = getEntityManager().createQuery( "From StreamScope WHERE scopeType=:scopeType AND uniqueKey=:uniqueKey").setParameter("scopeType", ScopeType.RESOURCE).setParameter("uniqueKey", uniqueKey).getResultList(); if (scopes.size() == 1) { sr.setStreamScope(scopes.get(0)); } else { sr.setStreamScope(new StreamScope(ScopeType.RESOURCE, uniqueKey)); } getEntityManager().persist(sr); if (sr.getStreamScope().getDestinationEntityId() == null) { sr.getStreamScope().setDestinationEntityId(sr.getId()); } return sr; } return resources.get(0); }
FindOrInsertSharedResourceByUniqueKeyDbMapper extends
        BaseArgDomainMapper<SharedResourceRequest, SharedResource> { @SuppressWarnings("unchecked") @Override public SharedResource execute(final SharedResourceRequest inSharedResourceRequest) { if (inSharedResourceRequest.getUniqueKey() == null) { return null; } String uniqueKey = inSharedResourceRequest.getUniqueKey().toLowerCase(); Query q = getEntityManager().createQuery("FROM SharedResource WHERE uniqueKey = :uniqueKey"); q.setParameter("uniqueKey", uniqueKey); List<SharedResource> resources = q.getResultList(); if (resources == null || resources.size() == 0) { SharedResource sr = new SharedResource(); sr.setUniqueKey(uniqueKey); List<StreamScope> scopes = getEntityManager().createQuery( "From StreamScope WHERE scopeType=:scopeType AND uniqueKey=:uniqueKey").setParameter("scopeType", ScopeType.RESOURCE).setParameter("uniqueKey", uniqueKey).getResultList(); if (scopes.size() == 1) { sr.setStreamScope(scopes.get(0)); } else { sr.setStreamScope(new StreamScope(ScopeType.RESOURCE, uniqueKey)); } getEntityManager().persist(sr); if (sr.getStreamScope().getDestinationEntityId() == null) { sr.getStreamScope().setDestinationEntityId(sr.getId()); } return sr; } return resources.get(0); } }
FindOrInsertSharedResourceByUniqueKeyDbMapper extends
        BaseArgDomainMapper<SharedResourceRequest, SharedResource> { @SuppressWarnings("unchecked") @Override public SharedResource execute(final SharedResourceRequest inSharedResourceRequest) { if (inSharedResourceRequest.getUniqueKey() == null) { return null; } String uniqueKey = inSharedResourceRequest.getUniqueKey().toLowerCase(); Query q = getEntityManager().createQuery("FROM SharedResource WHERE uniqueKey = :uniqueKey"); q.setParameter("uniqueKey", uniqueKey); List<SharedResource> resources = q.getResultList(); if (resources == null || resources.size() == 0) { SharedResource sr = new SharedResource(); sr.setUniqueKey(uniqueKey); List<StreamScope> scopes = getEntityManager().createQuery( "From StreamScope WHERE scopeType=:scopeType AND uniqueKey=:uniqueKey").setParameter("scopeType", ScopeType.RESOURCE).setParameter("uniqueKey", uniqueKey).getResultList(); if (scopes.size() == 1) { sr.setStreamScope(scopes.get(0)); } else { sr.setStreamScope(new StreamScope(ScopeType.RESOURCE, uniqueKey)); } getEntityManager().persist(sr); if (sr.getStreamScope().getDestinationEntityId() == null) { sr.getStreamScope().setDestinationEntityId(sr.getId()); } return sr; } return resources.get(0); }  }
FindOrInsertSharedResourceByUniqueKeyDbMapper extends
        BaseArgDomainMapper<SharedResourceRequest, SharedResource> { @SuppressWarnings("unchecked") @Override public SharedResource execute(final SharedResourceRequest inSharedResourceRequest) { if (inSharedResourceRequest.getUniqueKey() == null) { return null; } String uniqueKey = inSharedResourceRequest.getUniqueKey().toLowerCase(); Query q = getEntityManager().createQuery("FROM SharedResource WHERE uniqueKey = :uniqueKey"); q.setParameter("uniqueKey", uniqueKey); List<SharedResource> resources = q.getResultList(); if (resources == null || resources.size() == 0) { SharedResource sr = new SharedResource(); sr.setUniqueKey(uniqueKey); List<StreamScope> scopes = getEntityManager().createQuery( "From StreamScope WHERE scopeType=:scopeType AND uniqueKey=:uniqueKey").setParameter("scopeType", ScopeType.RESOURCE).setParameter("uniqueKey", uniqueKey).getResultList(); if (scopes.size() == 1) { sr.setStreamScope(scopes.get(0)); } else { sr.setStreamScope(new StreamScope(ScopeType.RESOURCE, uniqueKey)); } getEntityManager().persist(sr); if (sr.getStreamScope().getDestinationEntityId() == null) { sr.getStreamScope().setDestinationEntityId(sr.getId()); } return sr; } return resources.get(0); }  @SuppressWarnings("unchecked") @Override SharedResource execute(final SharedResourceRequest inSharedResourceRequest); }
FindOrInsertSharedResourceByUniqueKeyDbMapper extends
        BaseArgDomainMapper<SharedResourceRequest, SharedResource> { @SuppressWarnings("unchecked") @Override public SharedResource execute(final SharedResourceRequest inSharedResourceRequest) { if (inSharedResourceRequest.getUniqueKey() == null) { return null; } String uniqueKey = inSharedResourceRequest.getUniqueKey().toLowerCase(); Query q = getEntityManager().createQuery("FROM SharedResource WHERE uniqueKey = :uniqueKey"); q.setParameter("uniqueKey", uniqueKey); List<SharedResource> resources = q.getResultList(); if (resources == null || resources.size() == 0) { SharedResource sr = new SharedResource(); sr.setUniqueKey(uniqueKey); List<StreamScope> scopes = getEntityManager().createQuery( "From StreamScope WHERE scopeType=:scopeType AND uniqueKey=:uniqueKey").setParameter("scopeType", ScopeType.RESOURCE).setParameter("uniqueKey", uniqueKey).getResultList(); if (scopes.size() == 1) { sr.setStreamScope(scopes.get(0)); } else { sr.setStreamScope(new StreamScope(ScopeType.RESOURCE, uniqueKey)); } getEntityManager().persist(sr); if (sr.getStreamScope().getDestinationEntityId() == null) { sr.getStreamScope().setDestinationEntityId(sr.getId()); } return sr; } return resources.get(0); }  @SuppressWarnings("unchecked") @Override SharedResource execute(final SharedResourceRequest inSharedResourceRequest);  }