List of usage examples for org.hibernate SQLQuery setResultTransformer
@Deprecated Query<R> setResultTransformer(ResultTransformer transformer);
From source file:ispyb.server.mx.services.ws.rest.datacollectiongroup.DataCollectionGroupRestWsServiceBean.java
License:Open Source License
@Override public List<Map<String, Object>> getViewDataCollectionByProteinAcronym(int proposalId, String proteinAcronym) { String mySQLQuery = getViewTableQuery() + " where BLSession_proposalId = :proposalId and Protein_acronym = :proteinAcronym"; mySQLQuery = mySQLQuery/*from ww w . ja v a 2s. c o m*/ + " group by v_datacollection_summary.DataCollectionGroup_dataCollectionGroupId, v_datacollection_summary.DataCollectionGroup_dataCollectionGroupId"; Session session = (Session) this.entityManager.getDelegate(); SQLQuery query = session.createSQLQuery(mySQLQuery); query.setParameter("proposalId", proposalId); query.setParameter("proteinAcronym", proteinAcronym); query.setResultTransformer(AliasToEntityMapResultTransformer.INSTANCE); return executeSQLQuery(query); }
From source file:ispyb.server.mx.services.ws.rest.datacollectiongroup.DataCollectionGroupRestWsServiceBean.java
License:Open Source License
@Override public Collection<? extends Map<String, Object>> getViewDataCollectionByDataCollectionId(int proposalId, int dataCollectionId) { String mySQLQuery = getViewTableQuery() + " where DataCollection_dataCollectionId = :dataCollectionId and BLSession_proposalId = :proposalId "; mySQLQuery = mySQLQuery//from ww w . ja v a 2 s . c o m + " group by v_datacollection_summary.DataCollectionGroup_dataCollectionGroupId, v_datacollection_summary.DataCollectionGroup_dataCollectionGroupId"; Session session = (Session) this.entityManager.getDelegate(); SQLQuery query = session.createSQLQuery(mySQLQuery); query.setParameter("dataCollectionId", dataCollectionId); query.setParameter("proposalId", proposalId); query.setResultTransformer(AliasToEntityMapResultTransformer.INSTANCE); return executeSQLQuery(query); }
From source file:ispyb.server.mx.services.ws.rest.datacollectiongroup.DataCollectionGroupRestWsServiceBean.java
License:Open Source License
@Override public List<Map<String, Object>> getViewDataCollectionByWorkflowId(Integer proposalId, Integer workflowId) { String mySQLQuery = getViewTableQuery() + " where Workflow_workflowId = :Workflow_workflowId and BLSession_proposalId = :proposalId "; mySQLQuery = mySQLQuery/*from w w w. ja v a2 s . c om*/ + " group by v_datacollection_summary.DataCollectionGroup_dataCollectionGroupId, v_datacollection_summary.DataCollectionGroup_dataCollectionGroupId"; Session session = (Session) this.entityManager.getDelegate(); SQLQuery query = session.createSQLQuery(mySQLQuery); query.setParameter("Workflow_workflowId", workflowId); query.setParameter("proposalId", proposalId); query.setResultTransformer(AliasToEntityMapResultTransformer.INSTANCE); return executeSQLQuery(query); }
From source file:model.manager.PatientManager.java
License:Open Source License
public static List<ArtDto> getIedeaArtData(Session session, Patient patient) { SQLQuery query = session.createSQLQuery( "select f.form as form, atc.code as code, min(pickupdate) as startdate, max(pickupdate) as enddate" + " from prescription sc, package p, packageddrugs pd, stock s, drug d, form f, atccode atc" + " where sc.id = p.prescription" + " and p.id = pd.parentpackage" + " and pd.stock = s.id" + " and s.drug = d.id" + " and d.form = f.id" + " and d.atccode_id = atc.id" + " and d.sidetreatment = 'F'" + " and sc.patient = :patid" + " and pickupdate is not null" + " group by f.form, atc.code"); query.setInteger("patid", patient.getId()); query.setResultTransformer(new AliasToBeanResultTransformer(ArtDto.class)); @SuppressWarnings("unchecked") List<ArtDto> list = query.list(); return list;// ww w .j av a 2s . co m }
From source file:models.JournalDetail.java
public JournalDetails getSumBalanceByUntilDate(String year, Date date, String accountNo) { JournalDetails jds = null;/* w w w .j a v a 2 s. c o m*/ Session session = DatabaseUtil.getSessionFactory().openSession(); Transaction tx = null; try { tx = session.beginTransaction(); String sql = " select sum(jd.debet) as debet,sum(jd.credit) as credit " + " from journal_details jd " + " inner join journals j on j.id = jd.journal_id " + " where j.date < :date and year(j.date) = :year and jd.account_no = :no "; SQLQuery query = session.createSQLQuery(sql); query.setParameter("date", date); query.setParameter("year", year); query.setParameter("no", accountNo); query.setResultTransformer(Transformers.aliasToBean(JournalDetails.class)); session.flush(); tx.commit(); jds = (JournalDetails) query.uniqueResult(); } catch (HibernateException e) { System.out.println(e.getMessage()); if (tx != null) { tx.rollback(); } } finally { session.close(); } return jds; }
From source file:models.JournalDetail.java
public JournalDetails getSumBalanceByDate(Date dateFrom, Date dateTo, String accountNo) { JournalDetails jds = null;/*from ww w.j a v a2s. co m*/ Session session = DatabaseUtil.getSessionFactory().openSession(); Transaction tx = null; try { tx = session.beginTransaction(); String sql = " select sum(jd.debet) as debet,sum(jd.credit) as credit " + " from journal_details jd " + " inner join journals j on j.id = jd.journal_id " + " where (j.date>= :dateFrom and j.date <= :dateTo) and jd.account_no = :no "; SQLQuery query = session.createSQLQuery(sql); query.setParameter("dateFrom", dateFrom); query.setParameter("dateTo", dateFrom); query.setParameter("no", accountNo); query.setResultTransformer(Transformers.aliasToBean(JournalDetails.class)); session.flush(); tx.commit(); jds = (JournalDetails) query.uniqueResult(); } catch (HibernateException e) { System.out.println(e.getMessage()); if (tx != null) { tx.rollback(); } } finally { session.close(); } return jds; }
From source file:mpimp.assemblxweb.db.util.AssemblXWebDBUtil.java
License:Open Source License
@SuppressWarnings("unchecked") public static Boolean readUserData(AssemblXWebModel model) throws AssemblXException { Session hibernateSession = null;//from ww w . j a v a 2s .c om try { hibernateSession = HibernateSessionFactory.getSession(); hibernateSession.beginTransaction(); SQLQuery query = hibernateSession .createSQLQuery( "select us.id as operatorId, " + "us.login_name as login, us.password as password," + " us.first_name as firstName, us.last_name as lastName " + "from user us where us.login_name = :loginName") .addScalar("operatorId", IntegerType.INSTANCE).addScalar("login", StringType.INSTANCE) .addScalar("password", StringType.INSTANCE).addScalar("firstName", StringType.INSTANCE) .addScalar("lastName", StringType.INSTANCE); query.setString("loginName", model.getOperator().getLogin()); query.setResultTransformer(Transformers.aliasToBean(OperatorRecord.class)); ArrayList<OperatorRecord> operatorRecords = new ArrayList<OperatorRecord>(); operatorRecords = (ArrayList<OperatorRecord>) query.list(); hibernateSession.getTransaction().commit(); if (operatorRecords.size() == 1) { model.setOperator(operatorRecords.get(0)); return true; } else { return false; } } catch (Exception e) { // if (hibernateSession.getTransaction() != null && hibernateSession.getTransaction().isActive()) { // hibernateSession.getTransaction().rollback(); // } String message = "Error during reading user data from database. " + e.getMessage(); logger_.error(message); throw new AssemblXException(message, AssemblXWebDBUtil.class); } finally { HibernateSessionFactory.closeSession(); } }
From source file:mystical.controllerDAO.AbstractDAO.java
protected List<Map<String, Object>> consultaGenerica(String consulta) { session = Conexao.getSessionFactory().openSession(); tx = session.beginTransaction();/*from w ww .jav a 2 s. c om*/ List<Map<String, Object>> objects = null; try { System.out.println("estamos na abstract antes da query"); SQLQuery query = session.createSQLQuery(consulta); query.setResultTransformer(AliasToEntityMapResultTransformer.INSTANCE); objects = (List<Map<String, Object>>) query.list(); System.out.println("estamos na abstract depois da query"); tx.commit(); } catch (HibernateException e) { tx.rollback(); } finally { session.close(); } return objects; }
From source file:net.lc4ever.framework.activiti.engine.impl.AbstractNativeQueryHibernate.java
License:Open Source License
/** * @see org.activiti.engine.query.NativeQuery#count() */// w w w. ja va 2 s.c o m @Override public long count() { // TODO Any cute idea for count sql? return crudService.callback(new HibernateCallback<Long>() { @Override public Long doInHibernate(final Session session) throws HibernateException, SQLException { SQLQuery query = session.createSQLQuery(COUNT_PREFIX + selectClause + COUNT_SUFFIX); if (parameters != null) { for (Map.Entry<String, Object> entry : parameters.entrySet()) { query.setParameter(entry.getKey(), entry.getValue()); } } if (resultTransformer != null) query.setResultTransformer(resultTransformer); return ((Number) query.uniqueResult()).longValue(); } }); }
From source file:net.lc4ever.framework.activiti.engine.impl.AbstractNativeQueryHibernate.java
License:Open Source License
/** * @see org.activiti.engine.query.NativeQuery#singleResult() *///from w ww . java 2s . c o m @Override public U singleResult() { return crudService.callback(new HibernateCallback<U>() { @SuppressWarnings("unchecked") @Override public U doInHibernate(final Session session) throws HibernateException, SQLException { SQLQuery query = session.createSQLQuery(selectClause); if (parameters != null) { for (Map.Entry<String, Object> entry : parameters.entrySet()) { query.setParameter(entry.getKey(), entry.getValue()); } } if (resultTransformer != null) query.setResultTransformer(resultTransformer); return (U) query.uniqueResult(); } }); }