List of usage examples for org.hibernate SQLQuery setResultTransformer
@Deprecated Query<R> setResultTransformer(ResultTransformer transformer);
From source file:com.ps.dao.EventoDao.java
@Override public List<Map<String, ?>> listarEventos(String idFacultad) { List<Map<String, ?>> Lista = new ArrayList<>(); sql = "SELECT *FROM EVENTO WHERE ROWNUM='1'"; session = HibernateUtil.getSessionFactory().getCurrentSession(); try {// ww w. java 2 s . com trans = session.beginTransaction(); SQLQuery result = session.createSQLQuery(sql); result.setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP); List list = result.list(); for (Object obj : list) { Map<String, Object> a = (Map<String, Object>) obj; Lista.add(a); } trans.commit(); } catch (Exception e) { System.out.println(e); return null; } return Lista; }
From source file:com.ps.dao.UsuarioDao.java
@Override public Map loginControl(String user, String pass) { sql = "SELECT * FROM PSV_ROLES WHERE usuario='" + user + "' AND clave='" + pass + "'"; session = HibernateUtil.getSessionFactory().getCurrentSession(); try {//from w w w . jav a 2 s . c o m trans = session.beginTransaction(); SQLQuery result = session.createSQLQuery(sql); result.setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP); Object data = result.uniqueResult(); Map row = (Map) data; trans.commit(); return row; } catch (Exception e) { System.out.println(e); trans.rollback(); return null; } }
From source file:com.ps.dao.UsuarioDao.java
@Override public List<Map<String, ?>> listaPrivilegios(String idRol) { List<Map<String, ?>> Lista = new ArrayList<>(); sql = "SELECT * FROM PSV_LINKS WHERE IDROL='" + idRol + "'"; session = HibernateUtil.getSessionFactory().getCurrentSession(); try {/*w w w . ja v a 2s . c o m*/ trans = session.beginTransaction(); SQLQuery result = session.createSQLQuery(sql); result.setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP); List list = result.list(); for (Object obj : list) { Map<String, Object> a = (Map<String, Object>) obj; Lista.add(a); } trans.commit(); } catch (Exception e) { System.out.println(e); return null; } return Lista; }
From source file:com.querydsl.jpa.hibernate.sql.AbstractHibernateSQLQuery.java
License:Apache License
private Query createQuery(boolean forCount) { NativeSQLSerializer serializer = (NativeSQLSerializer) serialize(forCount); String queryString = serializer.toString(); logQuery(queryString, serializer.getConstantToLabel()); org.hibernate.SQLQuery query = session.createSQLQuery(queryString); // set constants HibernateUtil.setConstants(query, serializer.getConstantToLabel(), queryMixin.getMetadata().getParams()); if (!forCount) { ListMultimap<Expression<?>, String> aliases = serializer.getAliases(); Set<String> used = Sets.newHashSet(); // set entity paths Expression<?> projection = queryMixin.getMetadata().getProjection(); if (projection instanceof FactoryExpression) { for (Expression<?> expr : ((FactoryExpression<?>) projection).getArgs()) { if (isEntityExpression(expr)) { query.addEntity(extractEntityExpression(expr).toString(), expr.getType()); } else if (aliases.containsKey(expr)) { for (String scalar : aliases.get(expr)) { if (!used.contains(scalar)) { query.addScalar(scalar); used.add(scalar); break; }/*from ww w. ja va2 s. co m*/ } } } } else if (isEntityExpression(projection)) { query.addEntity(extractEntityExpression(projection).toString(), projection.getType()); } else if (aliases.containsKey(projection)) { for (String scalar : aliases.get(projection)) { if (!used.contains(scalar)) { query.addScalar(scalar); used.add(scalar); break; } } } // set result transformer, if projection is a FactoryExpression instance if (projection instanceof FactoryExpression) { query.setResultTransformer(new FactoryExpressionTransformer((FactoryExpression<?>) projection)); } } if (fetchSize > 0) { query.setFetchSize(fetchSize); } if (timeout > 0) { query.setTimeout(timeout); } if (cacheable != null) { query.setCacheable(cacheable); } if (cacheRegion != null) { query.setCacheRegion(cacheRegion); } if (readOnly != null) { query.setReadOnly(readOnly); } return query; }
From source file:com.salesapp.logic.controller.ModuleQueryController.java
public static List findData(String queryHQL) { SessionApp.connect();/*from w w w. j a va 2s.c o m*/ Session session = SessionApp.getSession(); SQLQuery query = session.createSQLQuery(queryHQL); query.setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP); //query.addEntity(String.class); List list = query.list(); //query.addEntity(Branch.class); return list; }
From source file:com.school.dao.UserImplement.java
@Override public Stuff getUser(String userEmail, String userPassword) { Stuff user = null;/*from w ww . j a va2s . c o m*/ try { hibernateDriver.openSession(); String getUserSql = "Select u.REC_ID , u.USER_TYPE ,u.JOIN_DATE,u.FAMILY_INFO_ID,u.PERSONAL_INFO_ID,u.CLASS_ID,u.STAGE_ID from USERS u INNER JOIN PERSONAL_INFO p ON p.EMAIL= :userEmail and p.PASSWORD= :userPassword"; SQLQuery query = hibernateDriver.getSession().createSQLQuery(getUserSql); query.addEntity(Stuff.class); query.setResultTransformer(Criteria.PROJECTION); query.setParameter("userEmail", userEmail); query.setParameter("userPassword", userPassword); user = (Stuff) query.uniqueResult(); hibernateDriver.closeSession(); } catch (Exception ex) { ex.printStackTrace(); } return user; }
From source file:com.siemens.scr.avt.ad.query.Queries.java
License:Open Source License
/** * Retrieving a list of entities satisfying the given criteria. * //from w w w. j a v a 2 s. c o m * @param <T> The type of the entities. * @param dicomCriteria a map from DICOM tag to java.lang.Object representing a conjunctive query. * @param annotationCriteria a map from predefined keys to java.lang.Object representing a conjunctive query. * @param entityClass the java.lang.Class representation of the entity type. * @return a list of entities. */ public static <T> List<T> findEntityByCriteria(Map<Integer, Object> dicomCriteria, Map<String, Object> annotationCriteria, Class<T> entityClass) { AbstractQueryBuilder builder = new DB2QueryBuilder(); String outputKey = entityClass.getCanonicalName(); String queryString = builder.buildQuery(dicomCriteria, annotationCriteria, Collections.singletonList(outputKey)); logger.debug("Query:" + queryString); Session session = HibernateUtil.currentSession(); SQLQuery query = session.createSQLQuery(queryString); query.addEntity(entityClass); List<Object> queryResult = query.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY).list(); LinkedList<T> result = new LinkedList<T>(); for (Object entity : queryResult) { result.add((T) entity); } return result; }
From source file:com.siemens.scr.avt.ad.query.Queries.java
License:Open Source License
/** * Retrieving a list of a specified column satisfying the given criteria. * /*from w w w .java2s .com*/ * @param <T> The type of the value. * @param dicomCriteria a map from DICOM tag to java.lang.Object representing a conjunctive query. * @param annotationCriteria a map from predefined keys to java.lang.Object representing a conjunctive query. * @param outputKey a key identifying the column to be retrieved. * @param clazz a <code>java.lang.Class</code> representation of the column type. * @return a list of values. */ @SuppressWarnings("unchecked") public static <T> List<T> findbyCriteria(Map<Integer, Object> dicomCriteria, Map<String, Object> annotationCriteria, String outputKey, Class<T> clazz) { AbstractQueryBuilder builder = new DB2QueryBuilder(); String queryString = builder.buildQuery(dicomCriteria, annotationCriteria, Collections.singletonList(outputKey)); logger.debug("Query:" + queryString); Session session = HibernateUtil.getSessionFactory().openSession(); SQLQuery query = session.createSQLQuery(queryString); List<Object> queryResult = query.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY).list(); LinkedList<T> result = new LinkedList<T>(); for (Object tuple : queryResult) { result.add((T) tuple); } session.close(); return result; }
From source file:com.sysware.customize.hd.investment.baseData.vendor.VendorDaoImpl.java
@SuppressWarnings("unchecked") public List<Vendor> findByMaterialIds(String materialCatalogId, int begin, int max, String type) { if (materialCatalogId != null && materialCatalogId.length() > 0) { StringBuilder sqlStr = new StringBuilder( "select distinct v.VENDORID,v.VENDORNAME,v.VENDORCODE,v.ACCOUNTID,v.ADDRESS," + "v.BANK,v.BUSINESSSCOPE,v.INITIALEVALUATIONDATE,v.VENDORLEVEL,v.PHONE," + "v.REVIEWDATE,v.TAXID,v.REPOSAL,v.PROPERTY," + // "m.MATERIALITEMNAME," + "v.simplename,v.type,v.sector "); sqlStr.append(" from t_vendor v, t_vendor_material vm, t_material m "); sqlStr.append(" where v.vendorid=vm.vendorid and vm.materialid=m.materialid and "); if (type.equals("0")) { sqlStr.append(" m.PARENTID in ("); sqlStr.append(" select mc.materialcatalogid from t_materialcatalog mc "); sqlStr.append(" start with mc.materialcatalogid='" + materialCatalogId + "'"); sqlStr.append(" connect by prior mc.materialcatalogid = mc.parentid) "); } else {/*from w w w . j a va2 s . c o m*/ sqlStr.append(" vm.materialid = '" + materialCatalogId + "'");//materialCatalogId ?ID } sqlStr.append(" order by v.vendorname "); // System.out.println("?"+sqlStr.toString()); List<Vendor> results = new ArrayList<Vendor>(); // List<Object[]> temps = this.executeNativeQuery(sqlStr.toString(), // null, begin, max); // for (Object[] objects : temps) { // Vendor vendor = new Vendor(); // vendor.setVendorID((String) objects[0]); // vendor.setVendorName(objects[1]==null?"":(String) objects[1]); // vendor.setVendorCode(objects[2]==null?"":(String) objects[2]); // vendor.setAccountID(objects[3]==null?"":(String) objects[3]); // vendor.setAddress(objects[4]==null?"":(String) objects[4]); // vendor.setBank(objects[5]==null?"":(String) objects[5]); // vendor.setBusinessScope(objects[6]==null?"":(String) objects[6]); // vendor.setInitialEvaluationDate(objects[7]==null?null:(Date) objects[7]); // vendor.setVendorLevel(objects[8]==null?"":(String) objects[8]); // vendor.setPhone(objects[9]==null?"":(String) objects[9]); //// vendor.setReviewResult(objects[10]==null?"":(String) objects[10]); // vendor.setReviewDate(objects[10]==null?null:(Date) objects[10]); // vendor.setTaxID(objects[11]==null?"":(String) objects[11]); // vendor.setReposal(objects[12]==null?"":(String) objects[12]); // vendor.setProperty(objects[13]==null?"":(String) objects[13]); // vendor.setMaterialItemName(objects[14]==null?"":(String) objects[14]); // vendor.setSimpleName(objects[15]==null?"":(String) objects[15]); // vendor.setType(objects[16]==null?"":(String) objects[16]); // vendor.setSector(objects[17]==null?"":(String) objects[17]); // results.add(vendor); // } SQLQuery query = dao.getHibernateSession().createSQLQuery(sqlStr.toString()); setFindByMaterialIds(query); query = (SQLQuery) query.setResultTransformer(Transformers.aliasToBean(Vendor.class)); results = query.list(); return results; } else { return new ArrayList<Vendor>(); } }
From source file:com.sysware.customize.hd.investment.baseData.vendor.VendorDaoImpl.java
/** * ????/*from www. java 2 s . c o m*/ * @param vendorName * @return */ @SuppressWarnings("unchecked") public List<Vendor> GetAVendor(String vendorName) { String sql = "select t.vendorcode,t.vendorname from t_vendor t where t.vendorname=?"; SQLQuery query = dao.getHibernateSession().createSQLQuery(sql); SetAVendor(query); query = (SQLQuery) query.setResultTransformer(Transformers.aliasToBean(Vendor.class)); query.setParameter(0, vendorName); return query.list(); }