List of usage examples for javax.persistence TypedQuery setParameter
TypedQuery<X> setParameter(int position, Object value);
From source file:com.sshdemo.common.report.manage.dao.TextReportDAO.java
public List<CategoryReport> findCategoryReportByTextReportId(final Long textReportId) { String hql = "Select c From CategoryReport As c Left Join c.texts As t Where t.id=:textReportId"; TypedQuery<CategoryReport> query = this.getEntityManager().createQuery(hql, CategoryReport.class); query.setParameter("textReportId", textReportId); return query.getResultList(); }
From source file:com.sshdemo.common.report.manage.dao.TextReportDAO.java
public List<EwcmsJobReport> findEwcmsJobReportByTextReportId(final Long textReportId) { String hql = "Select e From EwcmsJobReport As e Where e.textReport.id=:textReportId"; TypedQuery<EwcmsJobReport> query = this.getEntityManager().createQuery(hql, EwcmsJobReport.class); query.setParameter("textReportId", textReportId); return query.getResultList(); }
From source file:edu.sabanciuniv.sentilab.sare.controllers.entitymanagers.PersistentDocumentStoreController.java
/** * Gets all UUIDs for {@code T} type document stores owned by the given owner. * @param em the {@link EntityManager} to use. * @param ownerId the ID of the owner./* w ww.j av a 2s. c o m*/ * @param entityClass the specific type of document stores 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 PersistentDocumentStore> List<String> getAllUuids(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"); CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<byte[]> cq = cb.createQuery(byte[].class); Root<T> store = cq.from(entityClass); cq.multiselect(store.get("id")) .where(cb.equal(store.get("ownerId"), cb.parameter(String.class, "ownerId"))); TypedQuery<byte[]> tq = em.createQuery(cq); tq.setParameter("ownerId", ownerId); return Lists.newArrayList(Iterables.transform(tq.getResultList(), UuidUtils.uuidBytesToStringFunction())); }
From source file:puma.application.webapp.documents.DocumentDAOImpl.java
@Override public List<Document> getDocumentsByOrigin(String origin) { TypedQuery<Document> query = em.createNamedQuery("documentsByOrigin", Document.class); query.setParameter("origin", origin); List<Document> results = query.getResultList(); return results; }
From source file:com.googlecode.osgienterprise.geminitx.library.service.PersistentLibraryService.java
public List<Book> findBooksByAuthor(String lastName) { String jpql = "select b from Book b where b.author.lastName = :lastName"; TypedQuery<Book> query = em.createQuery(jpql, Book.class); query.setParameter("lastName", lastName); List<Book> books = query.getResultList(); return books; }
From source file:com.googlecode.osgienterprise.geminitx.library.service.PersistentLibraryService.java
public List<Book> findBooksByTitle(String title) { String jpql = "select b from Book b where b.title = :title"; TypedQuery<Book> query = em.createQuery(jpql, Book.class); query.setParameter("title", title); List<Book> books = query.getResultList(); return books; }
From source file:com.sshdemo.common.report.manage.dao.CategoryReportDAO.java
public Boolean findTextIsEntityByTextAndCategory(final Long textReportId, final Long categoryReportId) { String hql = "Select c From CategoryReport As c Left Join c.texts As t Where t.id=:textReportId And c.id=:categoryReportId"; TypedQuery<CategoryReport> query = this.getEntityManager().createQuery(hql, CategoryReport.class); query.setParameter("textReportId", textReportId); query.setParameter("categoryReportId", categoryReportId); List<CategoryReport> list = query.getResultList(); return list.isEmpty() ? false : true; }
From source file:com.sshdemo.common.report.manage.dao.CategoryReportDAO.java
public Boolean findChartIsEntityByChartAndCategory(final Long chartReportId, final Long categoryReportId) { String hql = "Select c From CategoryReport As c Left Join c.charts As t Where t.id=:chartReportId And c.id=:categoryReportId"; TypedQuery<CategoryReport> query = this.getEntityManager().createQuery(hql, CategoryReport.class); query.setParameter("chartReportId", chartReportId); query.setParameter("categoryReportId", categoryReportId); List<CategoryReport> list = query.getResultList(); return list.isEmpty() ? false : true; }
From source file:com.beto.test.securityinterceptor.model.dao.impl.UserDaoImpl.java
@Override public SecUserDef getUser(String login) { logger.debug("getUser method called..." + login); SecUserDef user;//from w w w.j av a 2 s .c o m TypedQuery<SecUserDef> query = em.createNamedQuery("SecUserDef.findByUsername", SecUserDef.class); query.setParameter("username", login); user = query.getSingleResult(); logger.debug(user.toString()); return user; }
From source file:br.eti.danielcamargo.backend.hsnpts.core.business.AlunoService.java
public Aluno getByUserId(Long userId) throws BusinessException { try {//w w w.j ava 2 s. c om StringBuilder hql = new StringBuilder(); hql.append("SELECT "); hql.append(" a "); hql.append("FROM "); hql.append(" Aluno a "); hql.append(" JOIN a.usuario u "); hql.append("WHERE "); hql.append(" u.id = :userId "); TypedQuery<Aluno> query = em.createQuery(hql.toString(), Aluno.class); query.setParameter("userId", userId); Aluno aluno = query.getSingleResult(); return aluno; } catch (NoResultException e) { throw new BusinessException("hsnpts", new ValidationOccurrence("hsnpts.aluno-nao-encontrado")); } }