List of usage examples for org.hibernate Query setResultTransformer
@Deprecated Query<R> setResultTransformer(ResultTransformer transformer);
From source file:org.mifos.framework.persistence.LegacyGenericDao.java
License:Open Source License
@SuppressWarnings("unchecked") public <T extends Object> T execUniqueResultNamedQueryWithResultTransformer(final String queryName, final Map<String, ?> queryParameters, final Class<T> clazz) { try {//w w w . ja v a 2s .c o m Query query = getSession().getNamedQuery(queryName) .setResultTransformer(Transformers.aliasToBean(clazz)); query.setProperties(queryParameters); query.setResultTransformer(Transformers.aliasToBean(clazz)); return (T) query.uniqueResult(); } catch (GenericJDBCException gje) { throw new ConnectionNotFoundException(gje); } catch (Exception e) { throw new MifosRuntimeException(e); } }
From source file:org.mifos.framework.persistence.LegacyGenericDao.java
License:Open Source License
@SuppressWarnings("unchecked") public <T extends Object> List<T> executeNamedQueryWithResultTransformer(final String queryName, final Map<String, ?> queryParameters, final Class<T> clazz) { try {//w ww . j ava 2 s .c o m Query query = getSession().getNamedQuery(queryName); query.setResultTransformer(Transformers.aliasToBean(clazz)); query.setProperties(queryParameters); return query.list(); } catch (Exception e) { throw new MifosRuntimeException(e); } }
From source file:org.mifos.framework.persistence.Persistence.java
License:Open Source License
public Object execUniqueResultNamedQueryWithResultTransformer(final String queryName, final Map<String, ?> queryParameters, final Class<?> clazz) { try {/* w ww . j av a2 s .com*/ Query query = null; Session session = getHibernateUtil().getSessionTL(); query = session.getNamedQuery(queryName).setResultTransformer(Transformers.aliasToBean(clazz)); setParametersInQuery(query, queryName, queryParameters); query.setResultTransformer(Transformers.aliasToBean(clazz)); return query.uniqueResult(); } catch (GenericJDBCException gje) { throw new ConnectionNotFoundException(gje); } catch (Exception e) { throw new MifosRuntimeException(e); } }
From source file:org.mzd.shap.domain.dao.SampleDaoSpringHibernate.java
License:Open Source License
@SuppressWarnings("unchecked") public List<AnnotationHistogramDTO> annotationHistogram(final Sample sample, final Annotator annotator, final Double confidence, final Collection<Taxonomy> excludedTaxons) { Object result = getHibernateTemplate().execute(new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException, SQLException { Query query; if (excludedTaxons == null || excludedTaxons.size() == 0) { query = session.createSQLQuery(HISTO_QUERY_NOTAX); } else { query = session.createSQLQuery(HISTO_QUERY_WITHTAX).setParameterList("excludedTaxons", excludedTaxons, new CustomType(TaxonomyUserType.class, null)); }//from w w w . j a v a2 s . c o m query.setResultTransformer(Transformers.aliasToBean(AnnotationHistogramDTO.class)); query.setInteger("sampleId", sample.getId()); query.setDouble("confidence", confidence); query.setInteger("annotatorId", annotator.getId()); return query.list(); } }); return (List<AnnotationHistogramDTO>) result; }
From source file:org.n52.sos.ds.hibernate.GetDataAvailabilityDAO.java
License:Open Source License
/** * Get time information from a named query * /*ww w.j a va2 s .co m*/ * @param seriesId * Series id * @param seriesMinMaxTransformer * Hibernate result transformator for min/max time value * @param session * Hibernate Session * @return Time period */ private TimePeriod getTimePeriodFromNamedQuery(long seriesId, SeriesMinMaxTransformer seriesMinMaxTransformer, Session session) { Query namedQuery = session.getNamedQuery(SQL_QUERY_GET_DATA_AVAILABILITY_FOR_SERIES); namedQuery.setParameter(SeriesObservationInfo.SERIES, seriesId); LOGGER.debug("QUERY getTimePeriodFromNamedQuery(series) with NamedQuery: {}", namedQuery); namedQuery.setResultTransformer(seriesMinMaxTransformer); return (TimePeriod) namedQuery.uniqueResult(); }
From source file:org.n52.sos.ds.hibernate.GetDataAvailabilityDAO.java
License:Open Source License
private List<?> executeNamedQuery(GetDataAvailabilityRequest req, Session session) { final boolean features = req.isSetFeaturesOfInterest(); final boolean observableProperties = req.isSetObservedProperties(); final boolean procedures = req.isSetProcedures(); String namedQueryName = null; Map<String, Collection<String>> parameter = Maps.newHashMap(); // all/*from w w w.ja v a2 s . co m*/ if (features && observableProperties && procedures) { namedQueryName = SQL_QUERY_GET_DATA_AVAILABILITY_FOR_FEATURES_PROCEDURES_OBSERVED_PROPERTIES; parameter.put(FEATURES, req.getFeaturesOfInterest()); parameter.put(OBSERVABLE_PROPERTIES, req.getObservedProperties()); parameter.put(PROCEDURES, req.getProcedures()); } // observableProperties and procedures else if (!features && observableProperties && procedures) { namedQueryName = SQL_QUERY_GET_DATA_AVAILABILITY_FOR_PROCEDURES_OBSERVED_PROPERTIES; parameter.put(OBSERVABLE_PROPERTIES, req.getObservedProperties()); parameter.put(PROCEDURES, req.getProcedures()); } // only observableProperties else if (!features && observableProperties && !procedures) { namedQueryName = SQL_QUERY_GET_DATA_AVAILABILITY_FOR_OBSERVED_PROPERTIES; parameter.put(OBSERVABLE_PROPERTIES, req.getObservedProperties()); } // only procedures else if (!features && !observableProperties && procedures) { namedQueryName = SQL_QUERY_GET_DATA_AVAILABILITY_FOR_PROCEDURES; parameter.put(PROCEDURES, req.getProcedures()); } // features and observableProperties else if (features && observableProperties && !procedures) { namedQueryName = SQL_QUERY_GET_DATA_AVAILABILITY_FOR_FEATURES_OBSERVED_PROPERTIES; parameter.put(FEATURES, req.getFeaturesOfInterest()); parameter.put(OBSERVABLE_PROPERTIES, req.getObservedProperties()); } // features and procedures else if (features && !observableProperties && procedures) { namedQueryName = SQL_QUERY_GET_DATA_AVAILABILITY_FOR_FEATURES_PROCEDURES; parameter.put(FEATURES, req.getFeaturesOfInterest()); parameter.put(PROCEDURES, req.getProcedures()); } // only features else if (features && !observableProperties && procedures) { namedQueryName = SQL_QUERY_GET_DATA_AVAILABILITY_FOR_FEATURES; parameter.put(FEATURES, req.getFeaturesOfInterest()); } if (StringHelper.isNotEmpty(namedQueryName)) { Query namedQuery = session.getNamedQuery(namedQueryName); for (String key : parameter.keySet()) { namedQuery.setParameterList(key, parameter.get(key)); } LOGGER.debug("QUERY getProceduresForFeatureOfInterest(feature) with NamedQuery: {}", namedQuery); namedQuery.setResultTransformer(new DataAvailabilityTransformer(session)); return namedQuery.list(); } return Lists.newLinkedList(); }
From source file:org.openhie.openempi.dao.hibernate.IdentifierDomainDaoHibernate.java
License:Open Source License
public List<IdentifierUpdateEvent> getIdentifierUpdateEvents(final int startIndex, final int maxEvents, final User eventRecipient) { @SuppressWarnings({ "unchecked", "rawtypes" }) List<IdentifierUpdateEvent> identifierUpdateEvents = (List<IdentifierUpdateEvent>) getHibernateTemplate() .execute(new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException, SQLException { Query query = session.createQuery( "from IdentifierUpdateEvent i where i.updateRecipient = :updateRecipient order by i.identifierUpdateEventId"); query.setParameter("updateRecipient", eventRecipient); query.setFirstResult(startIndex); query.setMaxResults(maxEvents); log.debug("Querying using " + query.toString()); List<IdentifierUpdateEvent> list = (List<IdentifierUpdateEvent>) query .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY).list(); log.debug("Query returned: " + list.size() + " elements."); return list; }//www .ja va2 s . c o m }); return identifierUpdateEvents; }
From source file:org.openhie.openempi.dao.hibernate.IdentifierDomainDaoHibernate.java
License:Open Source License
public List<IdentifierUpdateEvent> getIdentifierUpdateEvents(final User eventRecipient) { @SuppressWarnings({ "unchecked", "rawtypes" }) List<IdentifierUpdateEvent> identifierUpdateEvents = (List<IdentifierUpdateEvent>) getHibernateTemplate() .execute(new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException, SQLException { Query query = session.createQuery( "from IdentifierUpdateEvent i where i.updateRecipient = :updateRecipient" + " order by i.identifierUpdateEventId"); query.setParameter("updateRecipient", eventRecipient); log.debug("Querying using " + query.toString()); List<IdentifierUpdateEvent> list = (List<IdentifierUpdateEvent>) query .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY).list(); log.debug("Query returned: " + list.size() + " elements."); return list; }/*w ww . j a v a 2s. c om*/ }); return identifierUpdateEvents; }
From source file:org.openhie.openempi.dao.hibernate.IdentifierDomainDaoHibernate.java
License:Open Source License
public List<IdentifierUpdateEvent> getIdentifierUpdateEventsByDate(final Date startDate, final User eventRecipient) { @SuppressWarnings({ "unchecked", "rawtypes" }) List<IdentifierUpdateEvent> identifierUpdateEvents = (List<IdentifierUpdateEvent>) getHibernateTemplate() .execute(new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException, SQLException { Query query = session.createQuery( "from IdentifierUpdateEvent i where i.dateCreated > :startDate and i.updateRecipient = :updateRecipient " + "order by i.dateCreated"); query.setParameter("startDate", startDate); query.setParameter("updateRecipient", eventRecipient); log.debug("Querying using " + query.toString()); List<IdentifierUpdateEvent> list = (List<IdentifierUpdateEvent>) query .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY).list(); log.debug("Query returned: " + list.size() + " elements."); return list; }/* ww w . ja v a 2 s .c o m*/ }); return identifierUpdateEvents; }
From source file:org.openhie.openempi.dao.hibernate.IdentifierDomainDaoHibernate.java
License:Open Source License
public List<IdentifierUpdateEvent> getIdentifierUpdateEventsBeforeDate(final Date startDate, final User eventRecipient) { @SuppressWarnings({ "unchecked", "rawtypes" }) List<IdentifierUpdateEvent> identifierUpdateEvents = (List<IdentifierUpdateEvent>) getHibernateTemplate() .execute(new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException, SQLException { Query query = session.createQuery( "from IdentifierUpdateEvent i where i.dateCreated < :startDate and i.updateRecipient = :updateRecipient " + "order by i.dateCreated"); query.setParameter("startDate", startDate); query.setParameter("updateRecipient", eventRecipient); log.debug("Querying using " + query.toString()); List<IdentifierUpdateEvent> list = (List<IdentifierUpdateEvent>) query .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY).list(); log.debug("Query returned: " + list.size() + " elements."); return list; }/*from w ww. j av a 2s . co m*/ }); return identifierUpdateEvents; }