List of usage examples for javax.persistence TypedQuery getResultList
List<X> getResultList();
From source file:com.siriusit.spezg.multilib.storage.jpa.JpaUnitRepository.java
@Override public BinaryAttachment findAttachmentByType(String unitId, String attachmentType) { TypedQuery<BinaryAttachmentDomainObject> query = entityManager .createNamedQuery("findAttachmentByUnitAndType", BinaryAttachmentDomainObject.class); query.setParameter("unitId", Integer.parseInt(unitId)); query.setParameter("type", attachmentType); List<BinaryAttachmentDomainObject> resultList = query.getResultList(); if (resultList.size() == 1) return resultList.get(0); return null;//w w w . j ava 2s .c o m }
From source file:com.ushahidi.swiftriver.core.api.dao.impl.JpaAccountDao.java
private List<Account> getSearchResultList(String searchTerm, int count, int offset) { String qlString = "SELECT a FROM Account a WHERE a.accountPath like :q " + "OR a.owner.name like :q OR a.owner.email like :q"; List<Account> accounts = null; try {//from w ww . ja v a 2s .c o m TypedQuery<Account> query = em.createQuery(qlString, Account.class); query.setParameter("q", searchTerm); query.setMaxResults(count); query.setFirstResult(offset); accounts = query.getResultList(); } catch (NoResultException e) { // Do nothing; } return accounts; }
From source file:com.ushahidi.swiftriver.core.api.dao.impl.JpaAccountDao.java
public Account getFollower(Account account, Long accountId) { String qlString = "FROM AccountFollower " + "WHERE account = :account " + "AND follower.id = :follower"; TypedQuery<AccountFollower> query = this.em.createQuery(qlString, AccountFollower.class); query.setParameter("account", account); query.setParameter("follower", accountId); List<AccountFollower> followers = query.getResultList(); return followers.isEmpty() ? null : followers.get(0).getFollower(); }
From source file:eu.domibus.common.dao.MessageLogDao.java
public List<String> getDownloadedUserMessagesOlderThan(Date date, String mpc) { final TypedQuery<String> query = em.createNamedQuery("MessageLogEntry.findDownloadedUserMessagesOlderThan", String.class); query.setParameter("DATE", date); query.setParameter("MPC", mpc); try {/*from w w w . ja v a 2s. c o m*/ return query.getResultList(); } catch (NoResultException e) { return Collections.EMPTY_LIST; } }
From source file:com.deltastar.task7.core.repository.api.impl.PositionRepositoryImpl.java
@Override public Position getPossessedPositionByCustomerIdAndFundId(int customerId, int fundId) { TypedQuery<Position> query = entityManager.createNamedQuery("findPositionByCustomerIdAndFundId", Position.class); query.setParameter("p_customerId", customerId); query.setParameter("p_fundId", fundId); query.setParameter("p_status", CCConstants.POSITION_STATUS_IN_POSSESSION); List<Position> tempResultList = query.getResultList(); return tempResultList != null && tempResultList.size() > 0 ? tempResultList.get(0) : null; }
From source file:edu.sabanciuniv.sentilab.sare.controllers.entitymanagers.LexiconController.java
/** * Gets all UUIDs for {@code T} type lexica owned by the given owner. * @param em the {@link EntityManager} to use. * @param ownerId the ID of the owner./*from ww w. ja v a 2 s . c o m*/ * @param entityClass the specific type of lexica 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 Lexicon> List<String> getAllLexica(EntityManager em, String ownerId, Class<T> entityClass) { Validate.notNull(em, CannedMessages.NULL_ARGUMENT, "em"); Validate.notNull(ownerId, CannedMessages.NULL_ARGUMENT, "ownerId"); Validate.notNull(entityClass, CannedMessages.NULL_ARGUMENT, "entityClass"); TypedQuery<byte[]> query = em.createQuery("SELECT lex.id FROM Lexicon lex " + "WHERE lex.ownerId=:ownerId " + "AND TYPE(lex)=:type AND (lex.baseStore IS NULL " + "OR lex.baseStore IN (SELECT d FROM DocumentCorpus d))", byte[].class); query.setParameter("ownerId", ownerId).setParameter("type", entityClass); List<byte[]> results = query.getResultList(); return Lists.newArrayList(Iterables.transform(results, UuidUtils.uuidBytesToStringFunction())); }
From source file:com.beto.test.securityinterceptor.model.dao.generic.AbstractDao.java
public List<T> getListWithNamedQuery(String query, Map<String, Object> inList) throws Exception { try {/*from www.ja v a 2 s. co m*/ TypedQuery<T> tq = getEntityManager().createNamedQuery(query, entityClass); for (Map.Entry<String, Object> entrySet : inList.entrySet()) { String key = entrySet.getKey(); Object value = entrySet.getValue(); tq.setParameter(key, value); } return tq.getResultList(); } catch (NoResultException e) { LOGGER.debug("NO DATA FOUND..."); } return null; }
From source file:eu.domibus.common.dao.MessageLogDao.java
public List<String> getUndownloadedUserMessagesOlderThan(Date date, String mpc) { final TypedQuery<String> query = em .createNamedQuery("MessageLogEntry.findUndownloadedUserMessagesOlderThan", String.class); query.setParameter("DATE", date); query.setParameter("MPC", mpc); try {//from www . ja va2 s . co m return query.getResultList(); } catch (NoResultException e) { return Collections.EMPTY_LIST; } }
From source file:com.music.dao.Dao.java
public <T> List<T> getPagedListByPropertyValue(Class<T> clazz, String propertyName, Object propertyValue, int page, int pageSize) { String queryString = "SELECT o FROM " + clazz.getName() + " o WHERE " + propertyName + "=:" + propertyName; TypedQuery<T> query = getEntityManager().createQuery(queryString, clazz); query.setFirstResult(page * pageSize); query.setMaxResults(pageSize);/*from w w w.ja va 2 s . c o m*/ query.setParameter(propertyName, propertyValue); return query.getResultList(); }
From source file:io.hops.hopsworks.common.dao.certificates.CertsFacade.java
public List<UserCerts> findUserCertsByUid(String username) { TypedQuery<UserCerts> query = em.createNamedQuery("UserCerts.findByUsername", UserCerts.class); query.setParameter("username", username); try {/*from w w w .j a v a2s. co m*/ List<UserCerts> res = query.getResultList(); return res; } catch (EntityNotFoundException e) { Logger.getLogger(CertsFacade.class.getName()).log(Level.SEVERE, null, e); } return new ArrayList<>(); }