List of usage examples for javax.persistence TypedQuery setParameter
TypedQuery<X> setParameter(int position, Object value);
From source file:com.agnie.useradmin.tools.dbinit.DBInitializer.java
@Transactional private Role getRoleByNameAndApplication(String name, String appId) { TypedQuery<Role> qry = em.get().createNamedQuery("Role.getByApplicationAndName", Role.class); qry.setParameter("name", name); qry.setParameter("applicationId", appId); return qry.getSingleResult(); }
From source file:io.hops.hopsworks.common.dao.user.security.audit.AccountAuditFacade.java
public List<AccountAudit> findByTarget(Users user) { TypedQuery<AccountAudit> query = em.createNamedQuery("AccountAudit.findByTarget", AccountAudit.class); query.setParameter("target", user); return query.getResultList(); }
From source file:com.epam.training.taranovski.web.project.repository.implementation.UserRepositoryImplementation.java
@Override public boolean nameExistsInDB(String name) { EntityManager em = entityManagerFactory.createEntityManager(); boolean exists = false; try {/* w w w . j av a 2 s . co m*/ em.getTransaction().begin(); TypedQuery<User> query = em.createNamedQuery("User.findByLogin", User.class); query.setParameter("login", name); query.getSingleResult(); em.getTransaction().commit(); exists = true; } catch (NoResultException ex) { Logger.getLogger(OfferBidRepositoryImplementation.class.getName()).info(ex); exists = false; } finally { if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } em.close(); } return exists; }
From source file:com.epam.ipodromproject.repository.jpa.JPAUserRepository.java
@Override public List<User> getUsersByPartOfName(String partOfName, int startingResult, int resultsCount, boolean enabled, boolean unblocked) { TypedQuery<User> query = entityManager.createNamedQuery("User.getUsersPageByPartOfNameAndEnabled", User.class); query.setParameter("code", "%" + partOfName + "%"); query.setParameter("enabled", enabled); query.setParameter("blocked", !unblocked); return query.setMaxResults(resultsCount).setFirstResult(startingResult).getResultList(); }
From source file:com.olp.jpa.domain.docu.ut.repo.EmployeeRepositoryImpl.java
@Override public EmployeeBean findByEmpNumber(String empNum) { IContext ctx = ContextManager.getContext(); String tid = ctx.getTenantId(); TypedQuery<EmployeeBean> query = getEntityManager().createNamedQuery("UtEmployeeBean.findByEmpCode", EmployeeBean.class); query.setParameter("empCode", empNum); // TODO: Sanitize input, although low risk due to binding query.setParameter("tenant", tid); EmployeeBean bean = query.getSingleResult(); return (bean); }
From source file:org.bigtester.ate.model.data.dao.ElementInputDataDaoImpl.java
/** * Gets the value./*from ww w. j a va2 s .c o m*/ * * @param inputDataID * the input data id * @return the value */ public String getValue(String inputDataID, String repeatStepName, int iteration) throws RepeatTestDataException { List<ElementInputData> retVal; String sql = "select p from ElementInputData p where repeatStepExternalLoopPath is null 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("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, "", iteration); } else if (retVal.size() > 1) { // NOPMD throw new RepeatTestDataException(ExceptionMessage.MSG_TESTDATA_DUPLICATED, ExceptionErrorCode.REPEATTESTDATA_DUPLICATED, repeatStepName, "", iteration); } else { return retVal.get(0).getDataValue(); } }
From source file:com.hartveld.commons.db.DAOBase.java
@Override public T retrieveById(final long id) { LOG.trace("retrieveById: {}", id); final TypedQuery<T> query = em.createQuery("from " + entityName + " where id = :id", entityClass); query.setParameter("id", id); return query.getSingleResult(); }
From source file:io.hops.hopsworks.common.dao.user.security.audit.AccountAuditFacade.java
public List<AccountAudit> findByInitiator(Users user) { TypedQuery<AccountAudit> query = em.createNamedQuery("AccountAudit.findByInitiator", AccountAudit.class); query.setParameter("initiator", user); return query.getResultList(); }
From source file:com.olp.jpa.domain.docu.ut.repo.EmployeeRepositoryImpl.java
@Override @Transactional(readOnly = true)//from w w w . j a va 2 s . c o m public List<EmployeeBean> findByDeptCode(String deptCode) { IContext ctx = ContextManager.getContext(); String tid = ctx.getTenantId(); TypedQuery<EmployeeBean> query = getEntityManager().createNamedQuery("UtEmployeeBean.findByDeptCode", EmployeeBean.class); query.setParameter("deptCode", deptCode); // TODO: Sanitize input, although low risk due to binding query.setParameter("tenant", tid); List<EmployeeBean> list = query.getResultList(); return (list); }
From source file:org.openmeetings.app.data.calendar.daos.AppointmentCategoryDaoImpl.java
public List<AppointmentCategory> getAppointmentCategoryList() { try {//from www. ja va 2 s.com String hql = "select a from AppointmentCategory a " + "WHERE a.deleted <> :deleted "; TypedQuery<AppointmentCategory> query = em.createQuery(hql, AppointmentCategory.class); query.setParameter("deleted", "true"); List<AppointmentCategory> listAppointmentCategory = query.getResultList(); return listAppointmentCategory; } catch (Exception ex2) { log.error("[AppointmentCategory]: " + ex2); } return null; }