List of usage examples for org.hibernate SQLQuery setString
@Deprecated @SuppressWarnings("unchecked") default Query<R> setString(int position, String val)
From source file:org.theospi.portfolio.presentation.model.impl.PresentationManagerImpl.java
License:Educational Community License
public Collection getPresentationItems(Id artifactId) { Session session = getSession();/*from w ww .j ava2s . co m*/ SQLQuery query = session.createSQLQuery("SELECT {osp_presentation.*} " + " FROM osp_presentation {osp_presentation}, osp_presentation_item pi " + " WHERE {osp_presentation}.id = pi.presentation_id and pi.artifact_id = :artifactId"); query.addEntity("osp_presentation", Presentation.class); query.setString("artifactId", artifactId.getValue()); try { return query.list(); } catch (HibernateException e) { logger.error("", e); throw new OspException(e); } }
From source file:org.theospi.portfolio.presentation.model.impl.PresentationManagerImpl.java
License:Educational Community License
public Collection getPresentationsBasedOnTemplateFileRef(Id artifactId) { Session session = getSession();// ww w . java2 s . c o m try { SQLQuery query = session.createSQLQuery("SELECT {osp_presentation.*} " + " FROM osp_presentation {osp_presentation}, osp_template_file_ref tfr" + " WHERE {osp_presentation}.template_id = tfr.template_id and tfr.file_id = :artifactId"); query.addEntity("osp_presentation", Presentation.class); query.setString("artifactId", artifactId.getValue()); Collection tfr = query.list(); query = session.createSQLQuery("SELECT {osp_presentation.*} " + " FROM osp_presentation {osp_presentation}, osp_presentation_template templ " + " WHERE {osp_presentation}.template_id = templ.id and (templ.renderer = :artifactId " + " or templ.propertyPage = :artifactId)"); query.addEntity("osp_presentation", Presentation.class); query.setString("artifactId", artifactId.getValue()); tfr.addAll(query.list()); return tfr; } catch (HibernateException e) { logger.error("", e); throw new OspException(e); } }
From source file:org.tsm.concharto.service.EventSearchServiceHib.java
License:Apache License
private SQLQuery createQuery(String prefix, Geometry boundingBox, SearchParams params) { StringBuffer select = new StringBuffer(prefix).append(SQL_SELECT_STUB); select.append(SQL_TIME_JOIN); //always join on time, so we can order by time StringBuffer clause = new StringBuffer(); boolean hasConjuncted = false; if (params.getVisibility() == Visibility.NORMAL) { hasConjuncted = addClause(hasConjuncted, clause, SQL_VISIBLE_CLAUSE); } else if (params.getVisibility() == Visibility.HIDDEN) { hasConjuncted = addClause(hasConjuncted, clause, SQL_HIDDEN_CLAUSE); } else if (params.getVisibility() == Visibility.FLAGGED) { hasConjuncted = addClause(hasConjuncted, clause, SQL_FLAGGED_CLAUSE); }/* w w w . j a v a2s. co m*/ if (!StringUtils.isEmpty(params.getTextFilter())) { select.append(SQL_SEARCH_JOIN); hasConjuncted = addClause(hasConjuncted, clause, SQL_MATCH_CLAUSE); } if (boundingBox != null) { select.append(SQL_GEO_JOIN); hasConjuncted = addClause(hasConjuncted, clause, SQL_MBRWITHIN_CLAUSE); } if (params.getTimeRange() != null) { if (params.isIncludeTimeRangeOverlaps()) { addClause(hasConjuncted, clause, SQL_TIMERANGE_CLAUSE); } else { addClause(hasConjuncted, clause, SQL_TIMERANGE_EXCLUDE_OVERLAPS_CLAUSE); } } if (!StringUtils.isEmpty(params.getUserTag())) { //special case for empty tags if (!UNTAGGED.equals(params.getUserTag())) { select.append(SQL_TAG_JOIN); hasConjuncted = addClause(hasConjuncted, clause, SQL_TAG_CLAUSE); } else { select.append(SQL_TAG_EMPTY_JOIN); hasConjuncted = addClause(hasConjuncted, clause, SQL_TAG_EMPTY_CLAUSE); } } if (!StringUtils.isEmpty(params.getCatalog())) { hasConjuncted = addClause(hasConjuncted, clause, SQL_CATALOG_CLAUSE); } clause.append(SQL_ORDER_CLAUSE); select.append(clause); // Note: Hibernate always uses prepared statements SQLQuery sqlQuery = this.sessionFactory.getCurrentSession().createSQLQuery(select.toString()); if (boundingBox != null) { sqlQuery.setString(PARAM_GEOM_TEXT, boundingBox.toText()); } if (!StringUtils.isEmpty(params.getTextFilter())) { sqlQuery.setString(PARAM_SEARCH_TEXT, params.getTextFilter()); } if (!StringUtils.isEmpty(params.getUserTag())) { //special case for empty tags if (!UNTAGGED.equals(params.getUserTag())) { sqlQuery.setString(PARAM_TAG, StringUtils.trim(params.getUserTag())); } } if (!StringUtils.isEmpty(params.getCatalog())) { sqlQuery.setString(PARAM_CATALOG, StringUtils.trim(params.getCatalog())); } if (params.getTimeRange() != null) { sqlQuery.setBigInteger(PARAM_EARLIEST, BigInteger.valueOf(params.getTimeRange().getBegin().getDate().getTime())); sqlQuery.setBigInteger(PARAM_LATEST, BigInteger.valueOf(params.getTimeRange().getEnd().getDate().getTime())); } return sqlQuery; }
From source file:ru.runa.wfe.commons.dao.ConstantDao.java
License:Open Source License
public Integer getDatabaseVersion() throws Exception { // we won't handle connection error org.hibernate.classic.Session session = sessionFactory.getCurrentSession(); Connection connection = session.connection(); DatabaseMetaData metaData = connection.getMetaData(); log.info("Running with " + metaData.getDatabaseProductName() + " " + metaData.getDatabaseProductVersion()); try {/*from www . j av a 2 s.c o m*/ SQLQuery query = session.createSQLQuery("SELECT VALUE FROM WFE_CONSTANTS WHERE NAME=:name"); query.setString("name", DATABASE_VERSION_VARIABLE_NAME); return TypeConversionUtil.convertTo(Integer.class, query.uniqueResult()); } catch (Exception e) { log.warn("Unable to get database version", e); return null; } }
From source file:simtra.simtraadmin.dao.ReporteDao.java
public List<Reporte> listarReporteIncidencia(String fechaActual) { sesionActual();/*from ww w . ja va 2s .c o m*/ StringBuilder sql = new StringBuilder(); String nombreIncidencia = "Delito, Emergencia y Trafico"; sql.append("SELECT reporte.* "); sql.append("FROM reporte, incidencia "); sql.append("WHERE reporte.incId = incidencia.incId "); sql.append("AND to_char(reporte.repFecha,'dd/MM/yyyy') = :fechaActual "); sql.append("AND incidencia.incNombre = :nombreIncidencia "); sql.append("ORDER BY reporte.repFecha DESC"); SQLQuery query = sesion.createSQLQuery(sql.toString()).addEntity(Reporte.class); query.setString("fechaActual", fechaActual); query.setString("nombreIncidencia", nombreIncidencia); List<Reporte> objeto = (List<Reporte>) query.list(); return objeto; }
From source file:simtra.simtraadmin.dao.ReporteDao.java
public List<String> delitosPorRutaFecha(Integer idRuta, Date fechaInicio, Date fechaFin) { sesionActual();// w w w . ja v a 2s . co m System.out.println(idRuta); StringBuilder sql = new StringBuilder(); sql.append( "SELECT CONCAT(COUNT(incidencia.incTipo),';',incidencia.incTipo,';',TO_CHAR(reporte.repFecha,'yyyy-mm-dd')) "); sql.append("FROM incidencia INNER JOIN reporte ON incidencia.incId = reporte.incId "); sql.append("WHERE incidencia.incNombre = 'Delito, Emergencia y Trafico' "); sql.append("AND incidencia.incTipo IN ('Robo a mano armada', 'Robo con arma blanca', 'Pelea a bordo') "); sql.append("AND incidencia.incObservaciones LIKE CONCAT('%(',:idRuta,')%')"); sql.append("AND reporte.repfecha between :fechaInicio AND :fechaFin "); sql.append("GROUP BY incidencia.incTipo, TO_CHAR(reporte.repFecha,'yyyy-mm-dd') "); sql.append( "ORDER BY incidencia.incTipo,TO_CHAR(reporte.repFecha,'yyyy-mm-dd'), COUNT(incidencia.incTipo) DESC "); SQLQuery query = sesion.createSQLQuery(sql.toString()); query.setString("idRuta", idRuta.toString()); query.setDate("fechaInicio", fechaInicio); query.setDate("fechaFin", fechaFin); List<String> objeto = (List<String>) query.list(); return objeto; }
From source file:simtra.simtraadmin.dao.TelemetriaDao.java
public Telemetria buscarMasProximaPorUnidad(Integer idUnidad, String fechaActual) { try {//ww w . j ava 2 s.c o m sesionActual(); StringBuilder sql = new StringBuilder(); sql.append("SELECT telemetria.* "); sql.append("FROM telemetria, servicio, unidad "); sql.append("WHERE telemetria.serId = servicio.serId "); sql.append("AND servicio.uniId = unidad.uniId "); sql.append("AND unidad.uniId = :idUnidad "); sql.append("AND to_char(telemetria.telFecha,'dd/MM/yyyy') = :fechaActual "); sql.append("ORDER BY telemetria.telDistancia, telemetria.telFecha DESC"); SQLQuery query = sesion.createSQLQuery(sql.toString()).addEntity(Telemetria.class); query.setInteger("idUnidad", idUnidad); query.setString("fechaActual", fechaActual); Telemetria objeto = (Telemetria) query.list().get(0); return objeto; } catch (HibernateException e) { return null; } }
From source file:simtra.simtraadmin.dao.TelemetriaLogDao.java
public List<TelemetriaLog> listar(String fechaActual, Integer idRuta) { sesionActual();/*from w ww .j a v a 2 s . c om*/ StringBuilder sql = new StringBuilder(); sql.append("SELECT log.* "); sql.append("FROM telemetriaLog log "); sql.append("WHERE log.telDistancia <= 30 "); sql.append("AND to_char(log.telFecha,'dd/MM/yyyy') = :fechaActual "); sql.append( "AND traId IN (SELECT trayecto.traId FROM trayecto, ruta WHERE trayecto.ruId = ruta.ruId AND ruta.ruId = :idRuta) "); SQLQuery query = sesion.createSQLQuery(sql.toString()).addEntity(TelemetriaLog.class); query.setString("fechaActual", fechaActual); query.setInteger("idRuta", idRuta); List<TelemetriaLog> objeto = (List<TelemetriaLog>) query.list(); return objeto; }