List of usage examples for org.hibernate.type CustomType CustomType
public CustomType(UserType userType, String[] registrationKeys) throws MappingException
From source file:es.emergya.bbdd.dao.RoutingHome.java
License:Open Source License
/** * Devuelve el id del vrtice ms cercano, calculado segn la tabla de * routing./*from ww w .j av a 2s .c o m*/ * * @param p * @param end * @return */ @Transactional(readOnly = true, rollbackFor = Throwable.class) private Long getVertex(Point p, boolean end) { log.trace("getVertex(" + p + ", " + end + ")"); Long res = -1l; try { Session currentSession = getSession(); String point = "Start"; if (end) { point = "End"; } Type geometryType = new CustomType(GeometryUserType.class, null); Query q = currentSession.createQuery( "select " + id + " from " + table + " order by ST_Distance(ST_SETSRID(ST_POINT(ST_X(ST_" + point + "Point(" + the_geom + ")),ST_Y(ST_" + point + "Point(" + the_geom + "))), " + SRID + ")" + ",ST_SETSRID(?, " + SRID + ")) asc"); q.setParameter(0, p, geometryType); log.trace("SRID " + p.getSRID()); q.setMaxResults(1); log.trace(q); res = (Long) q.uniqueResult(); } catch (Throwable t) { log.error("Error al calcular el vertice mas cercano" + t, t); } log.trace(res); return res; }
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;/*from w ww . j a v a 2 s.c om*/ 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)); } 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; }