List of usage examples for javax.persistence TypedQuery getResultList
List<X> getResultList();
From source file:org.openmeetings.app.data.basic.dao.LdapConfigDaoImpl.java
public Long selectMaxFromLdapConfig() { try {//from w w w . ja v a 2 s .co m log.debug("selectMaxFromConfigurations "); //get all users TypedQuery<Long> query = em.createQuery( "select count(c.ldapConfigId) from LdapConfig c where c.deleted LIKE 'false'", Long.class); List<Long> ll = query.getResultList(); log.debug("selectMaxFromLdapConfig" + ll.get(0)); return ll.get(0); } catch (Exception ex2) { log.error("[selectMaxFromLdapConfig] ", ex2); } return null; }
From source file:com.epam.training.taranovski.web.project.repository.implementation.VacancyRepositoryImplementation.java
@Override public List<Employee> getAppropriateAvailableEmployees(Vacancy vacancy) { EntityManager em = entityManagerFactory.createEntityManager(); List<Integer> list = null; List<Employee> list1 = new LinkedList<>(); try {// ww w .j a va2 s.c o m em.getTransaction().begin(); Query query = em.createNativeQuery( "select \"employeeId\" from (select \"employeeId\", \"vacancyId\" as \"ide\", count(*) as cou from (select \"UserSkill\".\"employeeId\", \"VacancySkill\".\"vacancyId\", \"UserSkill\".\"experience\", \"VacancySkill\".\"experience\" from \"UserSkill\" join \"VacancySkill\" on \"UserSkill\".\"allSkillsId\" = \"VacancySkill\".\"allSkillsId\" where \"UserSkill\".\"experience\" >= \"VacancySkill\".\"experience\" and \"VacancySkill\".\"vacancyId\" = ?) group by \"employeeId\", \"vacancyId\") where cou = (select count(*) from \"VacancySkill\" where \"VacancySkill\".\"vacancyId\" = \"ide\")"); query.setParameter(1, vacancy.getVacancyId()); list = query.getResultList(); if (list.isEmpty()) { list.add(0); } TypedQuery<Employee> query1 = em.createNamedQuery("Employee.findAmongIdsFreeEmployees", Employee.class); query1.setParameter("employeeIdList", list); list1 = query1.getResultList(); em.getTransaction().commit(); } catch (RuntimeException e) { Logger.getLogger(VacancyRepositoryImplementation.class.getName()).info(e); } finally { if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } em.close(); } return list1; }
From source file:com.qpark.eip.core.spring.lockedoperation.dao.LockedOperationDaoImpl.java
/** * @see com.qpark.eip.core.spring.lockedoperation.dao.LockableOperationDao#unlockOperation(com.qpark.eip.core.spring.lockedoperation.LockableOperation) *///ww w . ja v a2s.co m @Override @Transactional(value = EipLockedoperationConfig.TRANSACTION_MANAGER_NAME, propagation = Propagation.REQUIRED) public boolean unlockOperation(final LockableOperation operation) { this.logger.debug("+unlock# {} {} {}", new Object[] { this.hostName, operation.getUUID(), operation.getName() }); boolean unlocked = false; String logString = getOperationLockString(operation); CriteriaBuilder cb = this.em.getCriteriaBuilder(); CriteriaQuery<OperationLockControllType> q = cb.createQuery(OperationLockControllType.class); Root<OperationLockControllType> c = q.from(OperationLockControllType.class); q.where(cb.equal(c.<String>get("operationName"), logString)); TypedQuery<OperationLockControllType> typedQuery = this.em.createQuery(q); try { List<OperationLockControllType> locks = typedQuery.getResultList(); for (OperationLockControllType lock : locks) { this.em.remove(this.em.merge(lock)); } unlocked = true; } catch (Exception e) { e.printStackTrace(); } finally { this.logger.debug("-unlock# {} {} {} {}", new Object[] { this.hostName, unlocked ? "unlocked" : "not unlocked", operation.getUUID(), operation.getName() }); } return unlocked; }
From source file:br.ufrgs.inf.dsmoura.repository.model.dao.TypesDAO.java
public List<NonFunctionalRequirementTypeDTO> getNonFunctionalRequirementTypeDTOList() { TypedQuery<NonFunctionalRequirementTypeDTO> query = createEntityManager().createQuery( "SELECT t FROM NonFunctionalRequirementTypeDTO t", NonFunctionalRequirementTypeDTO.class); return query.getResultList(); }
From source file:com.devicehive.dao.rdbms.DeviceDaoRdbmsImpl.java
@Override public List<DeviceVO> list(String name, String namePattern, Long networkId, String networkName, Long deviceClassId, String deviceClassName, String sortField, @NotNull Boolean sortOrderAsc, Integer take, Integer skip, HivePrincipal principal) { final CriteriaBuilder cb = criteriaBuilder(); final CriteriaQuery<Device> criteria = cb.createQuery(Device.class); final Root<Device> from = criteria.from(Device.class); final Predicate[] predicates = CriteriaHelper.deviceListPredicates(cb, from, ofNullable(name), ofNullable(namePattern), ofNullable(networkId), ofNullable(networkName), ofNullable(deviceClassId), ofNullable(deviceClassName), ofNullable(principal)); criteria.where(predicates);/*from w w w. j a v a 2 s . com*/ CriteriaHelper.order(cb, criteria, from, ofNullable(sortField), sortOrderAsc); final TypedQuery<Device> query = createQuery(criteria); cacheQuery(query, of(CacheConfig.refresh())); ofNullable(take).ifPresent(query::setMaxResults); ofNullable(skip).ifPresent(query::setFirstResult); List<Device> resultList = query.getResultList(); return resultList.stream().map(Device::convertToVo).collect(Collectors.toList()); }
From source file:org.jasig.portlet.notice.service.jpa.JpaNotificationDao.java
@Override @Transactional(readOnly = true)/* ww w .j a v a 2s . co m*/ public Set<JpaEntry> getEntriesByRecipient(String username) { Validate.notEmpty(username, "Argument 'username' cannot be empty"); final String jpql = "SELECT DISTINCT v.entry FROM JpaEvent v " + "WHERE v.username = :username"; TypedQuery<JpaEntry> query = entityManager.createQuery(jpql, JpaEntry.class); log.debug("Query getEntriesByRecipient={}", query.toString()); query.setParameter("username", username); List<JpaEntry> rslt = query.getResultList(); return new HashSet<JpaEntry>(rslt); }
From source file:io.hops.hopsworks.common.dao.certificates.CertsFacade.java
public List<ProjectGenericUserCerts> findAllProjectGenericUserCerts() { TypedQuery<ProjectGenericUserCerts> query = em.createNamedQuery("ProjectGenericUserCerts.findAll", ProjectGenericUserCerts.class); try {// w ww .j a v a2 s .c om return query.getResultList(); } catch (EntityNotFoundException ex) { LOG.log(Level.SEVERE, ex.getMessage(), ex); } catch (NoResultException ex) { } return new ArrayList<>(); }
From source file:org.openmeetings.app.data.user.Emailmanagement.java
/** * Checks if a mail is already taken by someone else * /*from w ww.j av a 2s. co m*/ * @param email * @return */ public boolean checkUserEMail(String email) { try { if (email.length() == 0) return true; log.debug("checkUserMail: " + email); TypedQuery<Adresses> query = em.createQuery( "select c from Adresses as c where c.email LIKE :email AND c.deleted <> :deleted", Adresses.class); query.setParameter("email", email); query.setParameter("deleted", "true"); int count = query.getResultList().size(); log.debug("size: " + count); if (count > 0) { return false; } } catch (Exception ex2) { log.error("checkUserEMail: ", ex2); } return true; }
From source file:com.pingdu.dao.licenseDao.LicenseDao.java
private License findByCompanyCodeAndLicenseCode(int companyCode, int licenseCode) { String jpql = "select l from License l where l.entCode = :entCode AND l.licenseCode = :licenseCode"; TypedQuery<License> query = em().createQuery(jpql, License.class); // query.setHint(QueryHints.RESULT_TYPE, ResultType.Map); query.setParameter("entCode", companyCode); query.setParameter("licenseCode", licenseCode); List<License> licenses = query.getResultList(); if (licenses.size() == 1) return licenses.get(0); else// ww w . j av a 2s. c om return null; }
From source file:org.openmeetings.app.data.user.Statemanagement.java
/** * selects a state by its id//from w w w . j a va2 s. co m * * @param state_id * @return the state-object or null */ public States getStateById(long state_id) { try { TypedQuery<States> query = em.createQuery( "select c from States as c where c.state_id = :state_id AND c.deleted <> :deleted", States.class); query.setParameter("state_id", state_id); query.setParameter("deleted", "true"); List<States> ll = query.getResultList(); if (ll.size() > 0) { return ll.get(0); } } catch (Exception ex2) { log.error("getStateById", ex2); } return null; }