List of usage examples for javax.persistence TypedQuery getResultList
List<X> getResultList();
From source file:com.music.dao.PieceDao.java
public List<Piece> getTopPieces(int page, int pageSize) { TypedQuery<Piece> query = getEntityManager().createQuery( "SELECT piece FROM Piece piece WHERE piece.likes > 0 ORDER BY likes DESC, generationTime DESC", Piece.class); query.setFirstResult(page * pageSize); query.setMaxResults(pageSize);//from ww w. j av a 2s . c o m return query.getResultList(); }
From source file:com.epam.training.taranovski.web.project.repository.implementation.OfferBidRepositoryImplementation.java
@Override public List<Vacancy> getBidsForEmployee(Employee employee) { EntityManager em = entityManagerFactory.createEntityManager(); List<Vacancy> list = new LinkedList<>(); try {// w w w .jav a2s. c om em.getTransaction().begin(); TypedQuery<Vacancy> query = em.createNamedQuery("OfferBid.findVacancyBidsForEmployee", Vacancy.class); query.setParameter("employee", employee); list = query.getResultList(); em.getTransaction().commit(); } catch (RuntimeException e) { Logger.getLogger(OfferBidRepositoryImplementation.class.getName()).info(e); } finally { if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } em.close(); } return list; }
From source file:com.epam.training.taranovski.web.project.repository.implementation.OfferBidRepositoryImplementation.java
@Override public List<Employee> getBidsForVacancy(Vacancy vacancy) { EntityManager em = entityManagerFactory.createEntityManager(); List<Employee> list = new LinkedList<>(); try {//from w w w. j a v a2 s . c o m em.getTransaction().begin(); TypedQuery<Employee> query = em.createNamedQuery("OfferBid.findEmployeeBidsForVacancy", Employee.class); query.setParameter("vacancy", vacancy); list = query.getResultList(); em.getTransaction().commit(); } catch (RuntimeException e) { Logger.getLogger(OfferBidRepositoryImplementation.class.getName()).info(e); } finally { if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } em.close(); } return list; }
From source file:eu.clarin.cmdi.virtualcollectionregistry.VirtualCollectionRegistryMaintenanceImpl.java
protected void handleCollectionsInError(EntityManager em, final Date nowDateError) { em.getTransaction().begin();/*ww w . j a v a 2s . c o m*/ TypedQuery<VirtualCollection> q = em.createNamedQuery("VirtualCollection.findAllByState", VirtualCollection.class); q.setParameter("state", VirtualCollection.State.ERROR); q.setParameter("date", nowDateError); q.setLockMode(LockModeType.PESSIMISTIC_WRITE); for (VirtualCollection vc : q.getResultList()) { VirtualCollection.State currentState = vc.getState(); logger.info("Found [{}] in error state.", vc.getName(), currentState); //TODO: handle virtual collections in error state } em.getTransaction().commit(); }
From source file:org.openmeetings.app.data.basic.Configurationmanagement.java
public List<Configuration> getConfigurations(int start, int max, String orderby, boolean asc) { try {// www .j a va 2 s . c o m CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Configuration> cq = cb.createQuery(Configuration.class); Root<Configuration> c = cq.from(Configuration.class); Predicate condition = cb.equal(c.get("deleted"), "false"); cq.where(condition); cq.distinct(asc); if (asc) { cq.orderBy(cb.asc(c.get(orderby))); } else { cq.orderBy(cb.desc(c.get(orderby))); } TypedQuery<Configuration> q = em.createQuery(cq); q.setFirstResult(start); q.setMaxResults(max); List<Configuration> ll = q.getResultList(); return ll; } catch (Exception ex2) { log.error("[getConfigurations]", ex2); } return null; }
From source file:bzzAgent.BiteSizedBzzDaoJpa.java
@Override public List<BiteSizedActivityEntity> search(BiteSizedActivitySearchParams params) { final LocalDate today = LocalDate.now(); String activeQuery;/* w w w . j a va 2 s. com*/ if (params.isActive() != null) { if (params.isActive()) { activeQuery = "where bsae.endDate >= ? " + " or bsae.phaseInt < 6 "; //Launch(6, "General Launch") } else { activeQuery = "where bsae.endDate < ? " + " and bsae.phaseInt = 6 "; } } else { activeQuery = ""; } String sql = "from BiteSizedActivityEntity bsae " + " left outer join fetch bsae.incentives incentive " + activeQuery + " order by bsae.startDate ASC"; //sql += "order by ma.mam.id asc"; TypedQuery<BiteSizedActivityEntity> query2 = em.createQuery(sql, BiteSizedActivityEntity.class) .setFirstResult(params.getOffset()) //.setMaxResults(params.getLimit()) ; if (params.isActive() != null) { query2.setParameter(1, today); } return query2.getResultList(); }
From source file:com.abiquo.server.core.cloud.VirtualMachineDAO.java
public boolean hasVirtualMachineTemplate(final Integer virtualMachineTemplateId) { TypedQuery<Long> query = getEntityManager().createNamedQuery("VIRTUAL_MACHINE.HAS_VMT", Long.class); query.setParameter("virtualMachineTplId", virtualMachineTemplateId); return query.getResultList().get(0) > 0; }
From source file:org.openmeetings.app.data.user.dao.UsersDaoImpl.java
/** * @param search/*from ww w.ja v a 2s . c om*/ * @return */ public Long selectMaxFromUsersWithSearch(String search) { try { String hql = "select count(c.user_id) from Users c " + "where c.deleted = 'false' " + "AND (" + "lower(c.login) LIKE :search " + "OR lower(c.firstname) LIKE :search " + "OR lower(c.lastname) LIKE :search " + ")"; // get all users TypedQuery<Long> query = em.createQuery(hql, Long.class); query.setParameter("search", StringUtils.lowerCase(search)); List<Long> ll = query.getResultList(); log.info("selectMaxFromUsers" + ll.get(0)); return ll.get(0); } catch (Exception ex2) { log.error("[selectMaxFromUsers] ", ex2); } return null; }
From source file:com.epam.training.taranovski.web.project.repository.implementation.OfferBidRepositoryImplementation.java
@Override public List<Vacancy> getOffersForEmployee(Employee employee) { EntityManager em = entityManagerFactory.createEntityManager(); List<Vacancy> list = new LinkedList<>(); try {// ww w.j ava2 s. co m em.getTransaction().begin(); TypedQuery<Vacancy> query = em.createNamedQuery("OfferBid.findVacancyOffersForEmployee", Vacancy.class); query.setParameter("employee", employee); list = query.getResultList(); em.getTransaction().commit(); } catch (RuntimeException e) { Logger.getLogger(OfferBidRepositoryImplementation.class.getName()).info(e); } finally { if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } em.close(); } return list; }
From source file:eu.clarin.cmdi.virtualcollectionregistry.VirtualCollectionRegistryMaintenanceImpl.java
protected void purgeDeletedCollections(EntityManager em, final Date nowDatePurge) { em.getTransaction().begin();//from w w w. j a va 2 s . c o m TypedQuery<VirtualCollection> q = em.createNamedQuery("VirtualCollection.findAllByState", VirtualCollection.class); q.setParameter("state", VirtualCollection.State.DELETED); q.setParameter("date", nowDatePurge); q.setLockMode(LockModeType.PESSIMISTIC_WRITE); for (VirtualCollection vc : q.getResultList()) { vc.setState(VirtualCollection.State.DEAD); em.remove(vc); logger.debug("purged virtual collection (id={})", vc.getId()); } em.getTransaction().commit(); }