List of usage examples for javax.persistence TypedQuery getResultList
List<X> getResultList();
From source file:com.carser.viamais.vo.TransactionFilter.java
public List<Transaction> resultList(final EntityManager em) { CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Transaction> cq = cb.createQuery(Transaction.class); Root<Transaction> transaction = cq.from(Transaction.class); cq.where(getPredicates(cb, transaction)); @SuppressWarnings("rawtypes") Path path;/* w ww .j av a 2 s .c o m*/ switch (orderBy) { case CUSTOMER_NAME: path = transaction.get(Transaction_.car).get(Car_.model).get(Model_.name); break; case DATE: path = transaction.get(Transaction_.transactionDate); break; case PLATE: path = transaction.get(Transaction_.car).get(Car_.licensePlate); break; case TYPE: path = transaction.get(Transaction_.type); break; case YEAR: path = transaction.get(Transaction_.car).get(Car_.yearOfModel); break; default: path = transaction.get(Transaction_.car).get(Car_.model).get(Model_.name); break; } switch (order) { case DESC: cq.orderBy(cb.desc(path)); break; default: cq.orderBy(cb.asc(path)); break; } TypedQuery<Transaction> query = em.createQuery(cq); query.setFirstResult(offset); query.setMaxResults(limit); return query.getResultList(); }
From source file:energy.usef.agr.repository.DeviceMessageRepository.java
/** * Find the device messages having the data matching the method parameters. * * @param connectionEntityAddress {@link String} optional entity address of the connection. * @param deviceMessageStatus {@link DeviceMessageStatus} optional status of the device message. * @return a {@link List} of {@link DeviceMessage}. *///from w w w .java2 s. c om public List<DeviceMessage> findDeviceMessages(String connectionEntityAddress, DeviceMessageStatus deviceMessageStatus) { StringBuilder sql = new StringBuilder(); sql.append("SELECT dm FROM DeviceMessage dm "); sql.append("WHERE 1 = 1 "); if (StringUtils.isNotBlank(connectionEntityAddress)) { sql.append(" AND dm.udi.connection.entityAddress = :connectionEntityAddress "); } if (deviceMessageStatus != null) { sql.append(" AND dm.deviceMessageStatus = :status "); } TypedQuery<DeviceMessage> query = getEntityManager().createQuery(sql.toString(), DeviceMessage.class); if (StringUtils.isNotBlank(connectionEntityAddress)) { query.setParameter("connectionEntityAddress", connectionEntityAddress); } if (deviceMessageStatus != null) { query.setParameter("status", deviceMessageStatus); } return query.getResultList(); }
From source file:edu.sabanciuniv.sentilab.sare.controllers.entitymanagers.DocumentSetCoverController.java
/** * Gets all relevant set covers.//from ww w. java 2 s .c om * @param em the {@link EntityManager} to use. * @param ownerId the ID of the owner. * @param baseCorpus the {@link DocumentCorpus} which is the base corpus for the set cover. * @param entityClass the specific type of set covers to be retrieved; must be annotated with the {@link Entity} annotation. * @return a {@link List} containing {@link String} representations of the UUIDs. */ public <T extends DocumentSetCover> List<String> getAllSetCovers(EntityManager em, String ownerId, DocumentCorpus baseCorpus, Class<T> entityClass) { Validate.notNull(em, CannedMessages.NULL_ARGUMENT, "em"); Validate.notNull(ownerId, CannedMessages.NULL_ARGUMENT, "ownerId"); Validate.notNull(baseCorpus, CannedMessages.NULL_ARGUMENT, "baseCorpus"); Validate.notNull(entityClass, CannedMessages.NULL_ARGUMENT, "entityClass"); TypedQuery<byte[]> query = em.createQuery("SELECT sc.id FROM DocumentSetCover sc " + "WHERE sc.ownerId=:ownerId " + "AND TYPE(sc)=:type " + "AND sc.baseStore=:baseCorpus", byte[].class); query.setParameter("ownerId", ownerId).setParameter("type", entityClass).setParameter("baseCorpus", baseCorpus); List<byte[]> results = query.getResultList(); return Lists.newArrayList(Iterables.transform(results, UuidUtils.uuidBytesToStringFunction())); }
From source file:edu.sabanciuniv.sentilab.sare.controllers.entitymanagers.LexiconBuilderController.java
/** * Gets the previously seen tokens for the given {@link LexiconBuilderDocumentStore}. * @param em the {@link EntityManager} to use. * @param builder the identifier of the {@link LexiconBuilderDocumentStore} to use. * @return the {@link List} of {@link LexiconDocument} objects. *//*from w ww . j ava 2 s . c o m*/ public List<LexiconDocument> getSeenTokens(EntityManager em, LexiconBuilderDocumentStore builder) { Validate.notNull(em, CannedMessages.NULL_ARGUMENT, "em"); Validate.notNull(builder, CannedMessages.NULL_ARGUMENT, "builder"); TypedQuery<LexiconDocument> query = em .createQuery("SELECT doc FROM LexiconDocument doc WHERE doc.store=:builder", LexiconDocument.class); query.setParameter("builder", builder); return query.getResultList(); }
From source file:com.music.dao.UserDao.java
public List<SocialAuthentication> getSocialAuthentications(String providerId, String providerUserId) { TypedQuery<SocialAuthentication> query = getEntityManager().createQuery( "SELECT sa FROM SocialAuthentication sa WHERE sa.providerId=:providerId AND sa.providerUserId=:providerUserId", SocialAuthentication.class); query.setParameter("providerId", providerId); query.setParameter("providerUserId", providerUserId); List<SocialAuthentication> auths = query.getResultList(); return auths; }
From source file:com.enioka.jqm.tools.ClientApiTest.java
@Test public void testCancelJob() throws Exception { CreationTools.createJobDef(null, true, "App", null, "jqm-tests/jqm-test-datetimemaven/target/test.jar", TestHelpers.qVip, 42, "MarsuApplication", null, "Franquin", "ModuleMachin", "other", "other", false, em);/*from w w w . j av a2 s . c o m*/ int i = JobRequest.create("MarsuApplication", "TestUser").submit(); JqmClientFactory.getClient().cancelJob(i); JobRequest.create("MarsuApplication", "TestUser").submit(); addAndStartEngine(); TestHelpers.waitFor(2, 5000, em); TypedQuery<History> query = em.createQuery("SELECT j FROM History j ORDER BY j.enqueueDate ASC", History.class); ArrayList<History> res = (ArrayList<History>) query.getResultList(); Assert.assertEquals(2, res.size()); Assert.assertEquals(State.CANCELLED, res.get(0).getState()); Assert.assertEquals(State.ENDED, res.get(1).getState()); }
From source file:de.taimos.dao.hibernate.EntityDAOHibernate.java
private <T> List<T> findListByQueryLimit(final String query, Class<T> clazz, final int first, final int max, final Object... params) { final TypedQuery<T> tq = this.entityManager.createQuery(query, clazz); for (int i = 0; i < params.length; i++) { tq.setParameter(i + 1, params[i]); }/*from www . j a v a 2 s . c om*/ if (first >= 0) { tq.setFirstResult(first); } if (max >= 0) { tq.setMaxResults(max); } return tq.getResultList(); }
From source file:org.openmeetings.app.data.user.dao.UsersDaoImpl.java
public Long getAllUserMax(String search) { try {//w w w. ja v a 2 s . co m String[] searchItems = search.split(" "); log.debug("getUserContactsBySearch: " + search); // log.debug("getUserContactsBySearch: "+ userId); String hql = "select count(u.user_id) from Users u " + "WHERE u.deleted = 'false' "; hql += "AND ( "; for (int i = 0; i < searchItems.length; i++) { if (i != 0) { hql += " OR "; } hql += "( " + "lower(u.lastname) LIKE '" + StringUtils.lowerCase("%" + searchItems[i] + "%") + "' " + "OR lower(u.firstname) LIKE '" + StringUtils.lowerCase("%" + searchItems[i] + "%") + "' " + "OR lower(u.login) LIKE '" + StringUtils.lowerCase("%" + searchItems[i] + "%") + "' " + "OR lower(u.adresses.email) LIKE '" + StringUtils.lowerCase("%" + searchItems[i] + "%") + "' " + ") "; } hql += " )"; log.debug("Show HQL: " + hql); TypedQuery<Long> query = em.createQuery(hql, Long.class); // log.debug("id: "+folderId); List<Long> ll = query.getResultList(); // log.error((Long)ll.get(0)); Long i = ll.get(0); return i; } catch (Exception ex2) { log.error("[getAllUserMax]: ", ex2); } return null; }
From source file:org.synyx.hades.dao.orm.GenericJpaDao.java
public Page<T> readAll(Specification<T> spec, Pageable pageable) { if (spec == null) { return readAll(pageable); }//from w ww . jav a 2 s . c o m TypedQuery<T> query = getQuery(spec, pageable); return pageable == null ? new PageImpl<T>(query.getResultList()) : readPage(query, pageable, spec); }
From source file:com.enioka.jqm.tools.ClientApiTest.java
@Test public void testRestartJob() throws Exception { JobDef jdDemoMaven = CreationTools.createJobDef(null, true, "App", null, "jqm-tests/jqm-test-datetimemaven/target/test.jar", TestHelpers.qVip, 42, "MarsuApplication", null, "Franquin", "ModuleMachin", "other", "other", true, em); int i = JobRequest.create("MarsuApplication", "TestUser").submit(); addAndStartEngine();/*from w w w .j a v a 2s . co m*/ TestHelpers.waitFor(1, 10000, em); JqmClientFactory.getClient().enqueueFromHistory(i); TestHelpers.waitFor(2, 10000, em); Assert.assertEquals(2, TestHelpers.getOkCount(em)); Assert.assertEquals(0, TestHelpers.getNonOkCount(em)); TypedQuery<History> query = em.createQuery("SELECT j FROM History j ORDER BY j.enqueueDate ASC", History.class); ArrayList<History> res = (ArrayList<History>) query.getResultList(); Assert.assertEquals(2, res.size()); Assert.assertEquals(jdDemoMaven.getId(), res.get(0).getJd().getId()); Assert.assertEquals(jdDemoMaven.getId(), res.get(1).getJd().getId()); }