Refine search
public Object getSingleResult() throws AuditException, NonUniqueResultException, NoResultException { List result = list(); if ( result == null || result.size() == 0 ) { throw new NoResultException(); } if ( result.size() > 1 ) { throw new NonUniqueResultException(); } return result.get( 0 ); }
TypedQuery<SampleEntity> query = em.createNamedQuery(namedQuery, SampleEntity.class); query.setMaxResults(100); Assert.assertEquals(100, query.getMaxResults()); Assert.assertEquals(0, query.executeUpdate()); Assert.assertEquals(0, query.getHints().size()); Assert.assertEquals("No result found!", e.getMessage());
Object p3 = prepareData("3", 15); Query findQuery = entityManager.createQuery("Select p from PersonCassandra p", PersonCassandra.class); List<PersonCassandra> allPersons = findQuery.getResultList(); Assert.assertNotNull(allPersons); Assert.assertTrue(allPersons.isEmpty()); findQuery = entityManager.createQuery("Select p from PersonCassandra p where p.personName = vivek"); allPersons = findQuery.getResultList(); Assert.assertNotNull(allPersons); Assert.assertTrue(allPersons.isEmpty()); findQuery = entityManager.createQuery("Select p.age from PersonCassandra p where p.personName = vivek"); allPersons = findQuery.getResultList(); Assert.assertNotNull(allPersons); Assert.assertNotNull(nrex.getMessage());
doThrow(new NoResultException()).when(query).getSingleResult(); when(mgr.createQuery("SELECT tb from TrustBundle tb WHERE tb.id = ?1")).thenReturn(query); verify(domainDao, times(1)).getDomain(new Long(1234)); verify(spyDao, times(1)).getTrustBundleById(5678); verify(mgr, never()).persist((TrustBundleDomainReltn)any());
Object p3 = prepareMongoInstance("3", 15); Query findQuery = em.createQuery("Select p from PersonMongo p"); List<PersonMongo> allPersons = findQuery.getResultList(); Assert.assertNotNull(allPersons); Assert.assertTrue(allPersons.isEmpty()); findQuery = em.createQuery("Select p from PersonMongo p where p.personName = vivek"); allPersons = findQuery.getResultList(); Assert.assertNotNull(allPersons); Assert.assertTrue(allPersons.isEmpty()); em.persist(p1); em.persist(p2); em.persist(p3); Assert.assertNotNull(nrex.getMessage());
doThrow(new NoResultException()).when(query).getSingleResult(); when(mgr.createQuery("SELECT tb from TrustBundle tb WHERE tb.id = ?1")).thenReturn(query); verify(domainDao, times(1)).getDomain(new Long(1234)); verify(spyDao, times(1)).getTrustBundleById(5678); verify(mgr, never()).remove((TrustBundleDomainReltn)any());
@Override public boolean isLocked(String orcid) { TypedQuery<Boolean> query = entityManager.createQuery("select recordLocked from ProfileEntity where orcid = :orcid", Boolean.class); query.setParameter("orcid", orcid); Boolean result; try { result = query.getSingleResult(); } catch (NoResultException nre) { throw new NoResultException("ORCID iD " + orcid + " not found"); } return result; }
/** * @param em * @param tenantId * @return */ public List<AlertTemplates> getTemplates(EntityManager em, String tenantId) { try { List<AlertTemplates> result = em.createNamedQuery(Queries.TEMPLATE_FIND_BY_TENANT_ID, AlertTemplates.class) .setParameter(PARAM_TENANT_ID, tenantId).getResultList(); return result; } catch (Exception e) { throw new NoResultException("Templates for:" + tenantId + " not found"); } }
EntityTransaction tx = em.getTransaction(); JpaJob originalJob = null; JpaJob fromDb = null; try { tx.begin(); fromDb = em.find(JpaJob.class, job.getId()); originalJob = JpaJob.from(fromDb.toJob()); if (fromDb == null) { throw new NoResultException(); em.merge(fromDb); tx.commit(); job.setVersion(fromDb.toJob().getVersion());
@Override public Optional<ResourceSet> getById(final long id) { try { val query = String.format("SELECT r FROM %s r WHERE r.id = :id", ENTITY_NAME); val r = this.entityManager.createQuery(query, ResourceSet.class) .setParameter("id", id) .getSingleResult(); return Optional.of(r); } catch (final NoResultException e) { LOGGER.debug(e.getMessage()); } return Optional.empty(); }
Query q = em.createNamedQuery("BULK_MONITOR_BUNDLE_QUERY"); StringBuilder bundleQuery = new StringBuilder(q.toString()); Query tmp = em.createQuery(bundleQuery.toString()); if (bundleObjs.isEmpty()) { final String message = "No entries found for given bundle(s)"; throw new JPAExecutorException(ErrorCode.E0603, message, new NoResultException(message));
@Override public Locale getDefaultLocale() { CriteriaBuilder cb = entityManager.getCriteriaBuilder(); CriteriaQuery<Locale> q = cb.createQuery(Locale.class); Root<Locale> l = q.from(Locale.class); q.where(cb.equal(l.get("defaultLocale"), true)); try { return entityManager.createQuery(q.select(l)).getSingleResult(); } catch (NoResultException e) { LOGGER.warn(e.getMessage(), e); return null; } }
Resource resource = entityManager.getReference(Resource.class, resourceId); if (resource == null) { throw new NoResultException("Cannot get latest plugin configuration for unknown Resource [" + resourceId + "]."); Query query = entityManager.createNamedQuery(PluginConfigurationUpdate.QUERY_FIND_CURRENTLY_ACTIVE_CONFIG); query.setParameter("resourceId", resourceId); current = (PluginConfigurationUpdate) query.getSingleResult(); subjectManager.getOverlord(), resource.getResourceType().getId()); entityManager.clear(); ConfigurationMaskingUtility.maskConfiguration(configuration, configurationDefinition); } catch (NoResultException nre) {
protected Rules getRule(EntityManager em, short ruleId) { try { Rules resultResult = em.createNamedQuery(Queries.RULES_FIND_BY_ID, Rules.class) .setParameter(PARAM_RULE_ID, ruleId).getSingleResult(); return resultResult; } catch (Exception e) { throw new NoResultException("Rule:" + ruleId + " not found"); } }
@Override public Configuration getResourceConfiguration(Subject subject, int resourceId) { Resource resource = entityManager.find(Resource.class, resourceId); if (resource == null) { throw new NoResultException("Cannot get live configuration for unknown resource [" + resourceId + "]"); } if (!authorizationManager.hasResourcePermission(subject, Permission.CONFIGURE_READ, resource.getId())) { throw new PermissionException("User [" + subject.getName() + "] does not have permission to view resource configuration for [" + resource + "]"); } Configuration result = configurationManager.getResourceConfiguration(resourceId); return result; }
if (flushMode == FlushModeType.AUTO && em.getTransaction().isActive()) em.flush(); throw new NoResultException("No results for query: " + query.toString());
personBiM12.setAddress(addressBiM1); em.persist(personBiM11); em.persist(personBiM12); em.clear(); Assert.assertEquals("No result found!", e.getMessage());
EntityTransaction tx = em.getTransaction(); try { tx.begin(); ServiceRegistrationJpaImpl fromDb; fromDb = em.find(ServiceRegistrationJpaImpl.class, registration.getId()); if (fromDb == null) { throw new NoResultException();
/** * Duplicate method use {@link ContextRepository#getContextByName(String)} * */ @Deprecated public ContextEntity getContextByName(String contextName) throws NoResultException { ContextEntity contextEntity = (ContextEntity) entityManager.createQuery("from ContextEntity c where c.name=:contextName").setParameter("contextName", contextName).getSingleResult(); if (contextEntity == null) { String message = "Der Context mit dem Namen: " + contextName + " existiert nicht auf der DB"; log.info(message); throw new NoResultException(message); } return contextEntity; }
public Comics readComics(int random, String url){ EntityManager em = EMF.get().createEntityManager(); Comics comics = null; try{ Query q = em.createNamedQuery("Comics.getComics"); q.setParameter("random", random); q.setParameter("url", url); comics = (Comics) q.getSingleResult(); Hibernate.initialize(comics.getUser()); } catch(NoResultException ex){ System.out.println("ERROR CATCHED: " + ex.getMessage()); comics = null; } finally{ em.close(); } return comics; }