List of usage examples for javax.persistence TypedQuery setParameter
TypedQuery<X> setParameter(int position, Object value);
From source file:org.openmeetings.app.data.user.dao.PrivateMessageFolderDaoImpl.java
public PrivateMessageFolder getPrivateMessageFolderById(Long privateMessageFolderId) { try {//from w w w. j a v a2 s. c o m String hql = "select c from PrivateMessageFolder c " + "where c.privateMessageFolderId = :privateMessageFolderId "; TypedQuery<PrivateMessageFolder> query = em.createQuery(hql, PrivateMessageFolder.class); query.setParameter("privateMessageFolderId", privateMessageFolderId); PrivateMessageFolder privateMessageFolder = null; try { privateMessageFolder = query.getSingleResult(); } catch (NoResultException ex) { } return privateMessageFolder; } catch (Exception e) { log.error("[getPrivateMessageFolderById]", e); } return null; }
From source file:com.epam.ipodromproject.repository.jpa.JPAHorseRepository.java
@Override public List<Horse> getHorsesByPageAndPartOfName(String partOfName, int startingResult, int resultsCount) { TypedQuery<Horse> query = entityManager.createNamedQuery("Horse.getHorsesByPageAndPartOfName", Horse.class); StringBuilder partOfNameBuilder = new StringBuilder("%"); query.setParameter("partOfName", partOfNameBuilder.append(partOfName).append("%").toString()); return query.setMaxResults(resultsCount).setFirstResult(startingResult).getResultList(); }
From source file:eu.domibus.common.dao.ErrorLogDao.java
public List<ErrorLogEntry> getErrorsForMessage(String messageId) { final TypedQuery<ErrorLogEntry> query = this.em.createNamedQuery("ErrorLogEntry.findErrorsByMessageId", ErrorLogEntry.class); query.setParameter("MESSAGE_ID", messageId); return query.getResultList(); }
From source file:com.epam.ipodromproject.repository.jpa.JPAUserRepository.java
private double getTotalMoneyByResult(User user, BetResult betResult) { TypedQuery<Double> query = entityManager.createNamedQuery("User.findTotalMoneyByUsernameAndResult", Double.class); query.setParameter("user", user); query.setParameter("betResult", betResult); double moneyWon = 0; try {/*from w w w .j av a 2s .co m*/ moneyWon = query.getSingleResult(); } catch (Exception e) { } return moneyWon; }
From source file:com.epam.ipodromproject.repository.jpa.JPAUserRepository.java
@Override public long getTotalUsers(String partOfName, boolean enabled, boolean unblocked) { TypedQuery<Long> query = entityManager.createNamedQuery("User.getTotalUsersByPartOfNameAndEnabled", Long.class); query.setParameter("code", "%" + partOfName + "%"); query.setParameter("enabled", enabled); query.setParameter("blocked", !unblocked); long totalUsers = 0; try {//from w w w . java 2 s .c o m totalUsers = query.getSingleResult(); } catch (Exception e) { } return totalUsers; }
From source file:com.epam.training.taranovski.web.project.repository.implementation.EmployerRepositoryImplementation.java
@Override public List<Vacancy> getActiveVacancys(Employer employer) { EntityManager em = entityManagerFactory.createEntityManager(); List<Vacancy> list = new LinkedList<>(); try {/* ww w. j ava2s . co m*/ em.getTransaction().begin(); TypedQuery<Vacancy> query = em.createNamedQuery("Vacancy.findActiveByEmployer", Vacancy.class); query.setParameter("employer", employer); list = query.getResultList(); em.getTransaction().commit(); } catch (RuntimeException e) { Logger.getLogger(BasicSkillRepositoryImplementation.class.getName()).info(e); } finally { if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } em.close(); } return list; }
From source file:org.bigtester.ate.model.data.dao.ElementInputDataDaoImpl.java
/** * Gets the value./*from ww w . ja v a2 s .c o m*/ * * @param inputDataID * the input data id * @return the value */ public String getValue(String inputDataID, String repeatStepName, String repeatStepExternalLoopPath, int iteration) throws RepeatTestDataException { if ("".equals(repeatStepExternalLoopPath)) return getValue(inputDataID, repeatStepName, iteration);//NOPMD List<ElementInputData> retVal; String sql = "select p from ElementInputData p where repeatStepExternalLoopPath=:repeatStepExternalLoopPath and FirstTimeExecution= 'No' and p.stepEIDsetID = :stepEIDsetID and p.repeatStepName=:repeatStepName and p.iteration=:iteration"; TypedQuery<ElementInputData> query = getDbEM().createQuery(sql, ElementInputData.class); query.setParameter("repeatStepExternalLoopPath", repeatStepExternalLoopPath); query.setParameter("stepEIDsetID", inputDataID); query.setParameter("repeatStepName", repeatStepName); query.setParameter("iteration", iteration); retVal = (List<ElementInputData>) query.getResultList(); if (retVal.isEmpty()) { throw new RepeatTestDataException(ExceptionMessage.MSG_TESTDATA_NOTFOUND, ExceptionErrorCode.REPEATTESTDATA_NOTFOUND, repeatStepName, repeatStepExternalLoopPath, iteration); } else if (retVal.size() > 1) { // NOPMD throw new RepeatTestDataException(ExceptionMessage.MSG_TESTDATA_DUPLICATED, ExceptionErrorCode.REPEATTESTDATA_DUPLICATED, repeatStepName, repeatStepExternalLoopPath, iteration); } else { return retVal.get(0).getDataValue(); } }
From source file:org.mitre.oauth2.repository.impl.JpaAuthorizationCodeRepository.java
@Override public Collection<AuthorizationCodeEntity> getExpiredCodes() { TypedQuery<AuthorizationCodeEntity> query = manager .createNamedQuery(AuthorizationCodeEntity.QUERY_EXPIRATION_BY_DATE, AuthorizationCodeEntity.class); query.setParameter(AuthorizationCodeEntity.PARAM_DATE, new Date()); // this gets anything that's already expired return query.getResultList(); }
From source file:com.beto.test.securityinterceptor.model.dao.impl.MenuServiceImpl.java
@Override public List<SecPageDef> pageList() { LOGGER.debug("\n\n\nTEST OK\n\n\n"); List<SecRoleDef> secRoleDefs = userDao.getUser(ProjectUtil.getUser().getUsername()).getSecRoleDefList(); List<String> list = new ArrayList<>(); for (SecRoleDef secRoleDef : secRoleDefs) { list.add(secRoleDef.getRole());//from w w w . j av a2 s .c om } TypedQuery<SecPageDef> tq = em.createQuery( "SELECT DISTINCT(p) FROM SecPageRoleDef s,SecPageDef p WHERE s.role IN:inList AND s.viewId=p.viewId", SecPageDef.class); tq.setParameter("inList", list); return tq.getResultList(); }
From source file:org.mitre.uma.service.impl.JpaRegisteredClientService.java
private SavedRegisteredClient getSavedRegisteredClientFromStorage(String issuer) { TypedQuery<SavedRegisteredClient> query = em.createQuery( "SELECT c from SavedRegisteredClient c where c.issuer = :issuer", SavedRegisteredClient.class); query.setParameter("issuer", issuer); SavedRegisteredClient saved = JpaUtil.getSingleResult(query.getResultList()); return saved; }