List of usage examples for org.hibernate Query setResultTransformer
@Deprecated Query<R> setResultTransformer(ResultTransformer transformer);
From source file:com.pizzaria.restaurante.dao.impl.LoginDaoImpl.java
public List<Map<String, Object>> listarDireitos(String login) { Query q = getSession().createSQLQuery("select " + " d.id as codigo, " + " d.descricao as descricao " + "from " + " Grupo_Usuario gu " + "inner join Grupo g " + " on gu.id_grupo = g.id " + "left join Grupo_Direito gd " + " on gd.id_grupo = gu.id_grupo " + "left join Direito d " + " on gd.id_direito = d.id " + "where " + " gu.login = :login "); q.setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP); q.setString("login", login); return q.list(); }
From source file:com.pizzaria.restaurante.dao.impl.LoginDaoImpl.java
public List<Map<String, Object>> getListPedidos(String login, Integer codigoPedido) { Query q = getSession().createSQLQuery( "select " + " pz.nom as nome, " + " pz.prix as preco, " + " s.descricao " + "from pedido p " + "inner join pedido_pizzas pp " + " on pp.id_pedido = p.id " + "inner join pizza pz " + " on pz.id = pp.id_pizza " + "inner join situacao s " + " on p.id_situacao = s.id " + "where " + " p.login = :login " + " and p.id = :codigo"); q.setString("login", login); q.setInteger("codigo", codigoPedido); q.setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP); return q.list(); }
From source file:com.proper.uip.common.core.dao.HibernateDao.java
License:Apache License
@SuppressWarnings("unchecked") public <K> Page<K> findPage(PageConfig pageConfig, SqlEso eso, Class<K> clazz) { Page<K> page = new Page<K>(pageConfig); Query q = createQuery(eso.getSql(), eso.getParam()); long totalCount = countHqlResult(eso.getSql(), eso.getParam()); page.setTotal(totalCount);// w w w. j ava2 s. com setPageParameterToQuery(q, page); q.setResultTransformer(Transformers.aliasToBean(clazz)); List result = q.list(); page.setRows(result); return page; }
From source file:com.querydsl.jpa.hibernate.AbstractHibernateQuery.java
License:Apache License
private Query createQuery(@Nullable QueryModifiers modifiers, boolean forCount) { JPQLSerializer serializer = serialize(forCount); String queryString = serializer.toString(); logQuery(queryString, serializer.getConstantToLabel()); Query query = session.createQuery(queryString); HibernateUtil.setConstants(query, serializer.getConstantToLabel(), getMetadata().getParams()); if (fetchSize > 0) { query.setFetchSize(fetchSize);//from ww w . j a v a 2s . c o m } if (timeout > 0) { query.setTimeout(timeout); } if (cacheable != null) { query.setCacheable(cacheable); } if (cacheRegion != null) { query.setCacheRegion(cacheRegion); } if (comment != null) { query.setComment(comment); } if (readOnly != null) { query.setReadOnly(readOnly); } for (Map.Entry<Path<?>, LockMode> entry : lockModes.entrySet()) { query.setLockMode(entry.getKey().toString(), entry.getValue()); } if (flushMode != null) { query.setFlushMode(flushMode); } if (modifiers != null && modifiers.isRestricting()) { Integer limit = modifiers.getLimitAsInteger(); Integer offset = modifiers.getOffsetAsInteger(); if (limit != null) { query.setMaxResults(limit); } if (offset != null) { query.setFirstResult(offset); } } // set transformer, if necessary Expression<?> projection = getMetadata().getProjection(); if (!forCount && projection instanceof FactoryExpression) { query.setResultTransformer(new FactoryExpressionTransformer((FactoryExpression<?>) projection)); } return query; }
From source file:com.rdsic.pcm.common.GenericHql.java
/** * Execute a native SQL query//from w ww.j ava 2s .c o m * * @param sql The SQL select query * @param maxRow Limit the number of rows to be returned * @param params List of parameters follow by name,value * @return */ public List<Map<String, T>> querySQL(String sql, int maxRow, Object... params) { Query q = HibernateUtil.currentSession().createSQLQuery(sql); q.setResultTransformer(AliasToEntityMapResultTransformer.INSTANCE); q.setMaxResults(maxRow); HibernateUtil.currentSession().setCacheMode(CacheMode.IGNORE); if (params != null) { for (int i = 0; i < params.length; i++) { q.setParameter(params[i].toString(), params[++i]); } } return q.list(); }
From source file:com.rdsic.pcm.service.pe.ProcessFunction.java
public String execute(String jsonStr) throws PCMException { String input = prepareInput(jsonStr); String hql = String.format("call %s(:param) ", new Object[] { this.function }); Query q = HibernateUtil.currentSession().createQuery(hql); q.setResultTransformer(AliasToEntityMapResultTransformer.INSTANCE); q.setParameter(":param", input); List<Map<String, Object>> list = q.list(); return new JSONObject(list).toString(); }
From source file:com.registryKit.client.clientDAO.java
/** * The 'getClientFields' function will return a list of client fields associated to the passed in programId. * /*from w w w. j a v a 2 s . com*/ * @param programId The id of the program the user is logged into * * @return This function will return a list of fields for the section * @throws Exception */ public List<programClientFields> getClientFields(Integer programId, Integer clientId) throws Exception { Query query = sessionFactory.getCurrentSession().createSQLQuery( "SELECT a.*, b.saveToTableName, b.saveToTableCol, b.answerType as fieldType FROM program_patientFields a inner join dataElements b on b.id = a.fieldId where a.programId = :programId order by a.dspPos asc") .setParameter("programId", programId); query.setResultTransformer(Transformers.aliasToBean(programClientFields.class)); List<programClientFields> fields = query.list(); if (!query.list().isEmpty()) { for (programClientFields field : fields) { /* Get the actual data */ field.setFieldValue(getTableData(field.getSaveToTableName(), field.getSaveToTableCol(), clientId)); field.setModified(isFieldModified(field.getFieldId(), clientId)); } } return fields; }
From source file:com.registryKit.client.engagementDAO.java
/** * The 'getEngagements' function will return the list of engagements for the passed in client and programId. * /*from www . j a va 2s . c om*/ * @param clientId The id of the selected client * @param programId The id of the program the logged in user is associated to * * @return This function will return a list of client engagements. */ public List<engagements> getEngagements(Integer clientId, Integer programId) throws Exception { String sql = "select e.id, e.programPatientId, e.programId, e.systemUserId, e.dateCreated, CONCAT(u.firstName,' ', u.lastName) as enteredBy " + "from patientEngagements e inner join users u on u.id = e.systemUserId " + "where e.programId = " + programId + " and e.programpatientId = " + clientId; /* Get a list of client engagements */ Query q1 = sessionFactory.getCurrentSession().createSQLQuery(sql); q1.setResultTransformer(Transformers.aliasToBean(engagements.class)); return q1.list(); }
From source file:com.registryKit.client.engagementDAO.java
/** * The 'getEngagementDetails' function will return the details of the selected engagement * /*from w w w. ja va2s .co m*/ * @param engagementId The id of the selected engagement * @return * @throws Exception */ public engagements getEngagementDetails(Integer engagementId) throws Exception { String sql = "select e.id, e.programPatientId, e.programId, e.systemUserId, e.dateCreated, CONCAT(u.firstName,' ', u.lastName) as enteredBy " + "from patientEngagements e inner join users u on u.id = e.systemUserId " + "where e.id = " + engagementId; /* Get a list of client engagements */ Query q1 = sessionFactory.getCurrentSession().createSQLQuery(sql); q1.setResultTransformer(Transformers.aliasToBean(engagements.class)); return (engagements) q1.uniqueResult(); }
From source file:com.registryKit.client.engagementDAO.java
/** * The 'getEngagementFields' function will return a list of engagement fields associated to the passed in programId. * /*w w w . j a v a 2 s . c o m*/ * @param programId The id of the program the user is logged into * * @return This function will return a list of fields for the section * @throws Exception */ public List<programEngagementFields> getEngagementFields(Integer programId, Integer engagementId, Integer clientId) throws Exception { Query query = sessionFactory.getCurrentSession().createSQLQuery( "SELECT a.*, b.saveToTableName, b.saveToTableCol, b.answerType as fieldType FROM program_engagementFields a inner join dataElements b on b.id = a.fieldId where a.programId = :programId order by a.dspPos asc") .setParameter("programId", programId); query.setResultTransformer(Transformers.aliasToBean(programEngagementFields.class)); List<programEngagementFields> fields = query.list(); if (!query.list().isEmpty()) { for (programEngagementFields field : fields) { /* Get the actual data */ field.setFieldValue(getTableData(field.getSaveToTableName(), field.getSaveToTableCol(), engagementId, clientId)); field.setModified(isFieldModified(field.getFieldId(), engagementId)); } } return fields; }