Example usage for org.hibernate.type StringType INSTANCE

List of usage examples for org.hibernate.type StringType INSTANCE

Introduction

In this page you can find the example usage for org.hibernate.type StringType INSTANCE.

Prototype

StringType INSTANCE

To view the source code for org.hibernate.type StringType INSTANCE.

Click Source Link

Usage

From source file:org.glite.security.voms.admin.persistence.dao.hibernate.AuditSearchDAOHibernate.java

License:Apache License

protected Criteria buildCriteriaFromParams(AuditLogSearchParams sp) {

    Criteria crit = createCriteria();//from   w  w w  .  j av a  2s  .  c  o  m

    crit.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);

    if (sp.getFromTime() != null) {
        crit.add(Restrictions.ge("timestamp", sp.getFromTime()));
    }

    if (sp.getToTime() != null) {
        crit.add(Restrictions.le("timestamp", sp.getToTime()));
    }

    if (sp.getFilterString() != null && !sp.getFilterString().trim().equals("")) {

        if (sp.getFilterType().equals(AuditLogSearchParams.FULL_SEARCH_KEY)) {

            // Full search is basically search over principal
            // and audit event data point values
            String filterString = String.format("%%%s%%", sp.getFilterString());

            // This is due to another ugly limitation of Hibernate 3.3
            // which does not support criteria queries on embedded
            // collections
            // See https://hibernate.atlassian.net/browse/HHH-869

            crit.add(Restrictions.disjunction().add(Restrictions.sqlRestriction(
                    "{alias}.event_id in (select ae.event_id from audit_event ae, audit_event_data aed where ae.event_id = aed.event_id and aed.value like ?)",
                    filterString, StringType.INSTANCE))
                    .add(Restrictions.like("principal", sp.getFilterString().trim(), MatchMode.ANYWHERE)));

        } else {
            crit.add(Restrictions.like(sp.getFilterType(), sp.getFilterString().trim(), MatchMode.ANYWHERE));
        }

    }

    if (sp.getFirstResult() != null) {
        crit.setFirstResult(sp.getFirstResult());
    }

    if (sp.getMaxResults() != null) {
        crit.setMaxResults(sp.getMaxResults());
    }

    crit.addOrder(Order.desc("timestamp"));
    return crit;
}

From source file:org.hoteia.qalingo.core.dao.RetailerDao.java

License:Apache License

public List<GeolocatedStore> findStoresByGeoloc(final String latitude, final String longitude,
        final String distance, int maxResults, Object... params) {
    Float latitudeFloat = new Float(latitude);
    Float longitudeFloat = new Float(longitude);
    String queryString = "SELECT store.id, store.code, ((ACOS(SIN(:latitude * PI() / 180) * SIN(latitude * PI() / 180) + COS(:latitude * PI() / 180) * COS(latitude * PI() / 180) * COS((:longitude - longitude) * PI() / 180)) * 180 / PI()) * 60 * 1.1515) AS distance FROM teco_store store HAVING distance <= :distanceValue ORDER BY distance ASC";
    Query query = createNativeQuery(queryString);
    query.setParameter("latitude", latitudeFloat.floatValue());
    query.setParameter("longitude", longitudeFloat.floatValue());
    query.setParameter("distanceValue", distance);
    query.setMaxResults(maxResults);//  w  ww.  ja v a  2  s .  c o m
    query.unwrap(SQLQuery.class).addScalar("id", LongType.INSTANCE).addScalar("code", StringType.INSTANCE)
            .addScalar("distance", DoubleType.INSTANCE);

    @SuppressWarnings("unchecked")
    List<Object[]> objects = query.getResultList();
    List<GeolocatedStore> stores = new ArrayList<GeolocatedStore>();
    for (Iterator<Object[]> iterator = objects.iterator(); iterator.hasNext();) {
        Object[] object = iterator.next();
        GeolocatedStore geolocatedStore = new GeolocatedStore();
        geolocatedStore.setId((Long) object[0]);
        geolocatedStore.setCode((String) object[1]);
        geolocatedStore.setDistance((Double) object[2]);
        stores.add(geolocatedStore);
    }
    return stores;
}

From source file:org.hoteia.qalingo.core.dao.RetailerDao.java

License:Apache License

public List<GeolocatedStore> findStoresByGeolocAndCountry(final String countryCode, final String latitude,
        final String longitude, final String distance, int maxResults, Object... params) {
    if (StringUtils.isNotEmpty(latitude) && StringUtils.isNotEmpty(longitude)) {
        Float latitudeFloat = new Float(latitude);
        Float longitudeFloat = new Float(longitude);
        String queryString = "SELECT store.id, store.code, ((ACOS(SIN(:latitude * PI() / 180) * SIN(latitude * PI() / 180) + COS(:latitude * PI() / 180) * COS(latitude * PI() / 180) * COS((:longitude - longitude) * PI() / 180)) * 180 / PI()) * 60 * 1.1515) AS distance FROM teco_store store WHERE country_code = :countryCode HAVING distance <= :distanceValue ORDER BY distance ASC";
        Query query = createNativeQuery(queryString);
        query.setParameter("latitude", latitudeFloat.floatValue());
        query.setParameter("longitude", longitudeFloat.floatValue());
        query.setParameter("countryCode", countryCode);
        query.setParameter("distanceValue", distance);
        query.setMaxResults(maxResults);
        query.unwrap(SQLQuery.class).addScalar("id", LongType.INSTANCE).addScalar("code", StringType.INSTANCE)
                .addScalar("distance", DoubleType.INSTANCE);

        @SuppressWarnings("unchecked")
        List<Object[]> objects = query.getResultList();
        List<GeolocatedStore> stores = new ArrayList<GeolocatedStore>();
        for (Iterator<Object[]> iterator = objects.iterator(); iterator.hasNext();) {
            Object[] object = iterator.next();
            GeolocatedStore geolocatedStore = new GeolocatedStore();
            geolocatedStore.setId((Long) object[0]);
            geolocatedStore.setCode((String) object[1]);
            geolocatedStore.setDistance((Double) object[2]);
            stores.add(geolocatedStore);
        }// www.jav a  2  s.  c o  m
        return stores;
    }
    return null;
}

From source file:org.jadira.usertype.spi.shared.DstSafeDateType.java

License:Apache License

public String objectToSQLString(Date value, Dialect dialect) throws Exception {
    final java.sql.Date jdbcDate = java.sql.Date.class.isInstance(value) ? (java.sql.Date) value
            : new java.sql.Date(value.getTime());
    // TODO : use JDBC date literal escape syntax? -> {d 'date-string'} in yyyy-mm-dd format
    return StringType.INSTANCE.objectToSQLString(jdbcDate.toString(), dialect);
}

From source file:org.jadira.usertype.spi.shared.DstSafeTimestampType.java

License:Apache License

public String objectToSQLString(Date value, Dialect dialect) throws Exception {
    final Timestamp ts = Timestamp.class.isInstance(value) ? (Timestamp) value : new Timestamp(value.getTime());
    // TODO : use JDBC date literal escape syntax? -> {d 'date-string'} in
    // yyyy-mm-dd hh:mm:ss[.f...] format
    return StringType.INSTANCE.objectToSQLString(ts.toString(), dialect);
}

From source file:org.jadira.usertype.spi.shared.DstSafeTimeType.java

License:Apache License

public String objectToSQLString(Date value, Dialect dialect) throws Exception {
    final Time ts = Time.class.isInstance(value) ? (Time) value : new Time(value.getTime());
    // TODO : use JDBC date literal escape syntax? -> {d 'date-string'} in
    // yyyy-mm-dd hh:mm:ss[.f...] format
    return StringType.INSTANCE.objectToSQLString(ts.toString(), dialect);
}

From source file:org.jasig.ssp.util.hibernate.MultipleCountProjection.java

License:Apache License

/**
 * Coerce a proerty to a string-ish type using the current
 * <code>Dialect</code>'s "str" function.
 *
 * @param propertyName/*from ww  w.  j a  v  a  2s . c o m*/
 * @param criteria
 * @param criteriaQuery
 * @return
 */
private String asSqlStr(String propertyName, Criteria criteria, CriteriaQuery criteriaQuery) {
    String castCall = super.getFunction("cast", criteriaQuery).render(
            criteriaQuery.getType(criteria, propertyName),
            Lists.newArrayList(
                    (String) buildFunctionParameterList(criteriaQuery.getColumn(criteria, propertyName)).get(0),
                    "string"),
            criteriaQuery.getFactory());
    return super.getFunction("coalesce", criteriaQuery).render(StringType.INSTANCE,
            Lists.newArrayList(castCall, "''"), criteriaQuery.getFactory());
}

From source file:org.jasig.ssp.util.hibernate.MultipleCountProjection.java

License:Apache License

/**
 * Concats literals as opposed to field references. Useful for concating
 * the SQL output by/*from ww  w  .j  a  v  a2s.c o m*/
 * {@link #asSqlStr(String, org.hibernate.Criteria, org.hibernate.criterion.CriteriaQuery)}
 *
 * @param str1
 * @param str2
 * @param criteria
 * @param criteriaQuery
 * @return
 */
private String sqlConcatLiterals(String str1, String str2, Criteria criteria, CriteriaQuery criteriaQuery) {
    return super.getFunction("concat", criteriaQuery).render(StringType.INSTANCE,
            Lists.newArrayList(str1, str2), criteriaQuery.getFactory());
}

From source file:org.kimios.kernel.dms.hibernate.HEnumerationValueFactory.java

License:Open Source License

public Vector<String> getValues(long uid) throws ConfigException, DataSourceException {
    try {/*from   w  ww  . jav  a 2s.com*/
        Vector<String> vValues = new Vector<String>();
        List<String> lValues = getSession().createSQLQuery(
                "SELECT v.enumeration_value as val FROM enumeration_value v WHERE enumeration_id=:uid ORDER by lower(v.enumeration_value)")
                .addScalar("val", StringType.INSTANCE).setParameter("uid", uid).list();
        for (String st : lValues) {
            vValues.add(st);
        }

        return vValues;
    } catch (HibernateException e) {
        throw new DataSourceException(e);
    }
}

From source file:org.kimios.kernel.reporting.impl.DocumentHitsReport.java

License:Open Source License

public String getData() throws ConfigException, DataSourceException {
    if (order != null && order.length() == 0) {
        order = null;/*from  w ww . ja va  2 s.co  m*/
    }
    try {
        Calendar dtFrom = Calendar.getInstance();
        dtFrom.setTime(dateFrom);
        Calendar dtTo = Calendar.getInstance();
        dtTo.setTime(dateTo);

        dtFrom.set(Calendar.SECOND, 0);
        dtFrom.set(Calendar.MINUTE, 0);
        dtFrom.set(Calendar.HOUR, 0);

        dtTo.set(Calendar.SECOND, 59);
        dtTo.set(Calendar.MINUTE, 59);
        dtTo.set(Calendar.HOUR, 23);

        String rq = "SELECT e.dm_entity_name as DocumentName, count(*) as HitsCount, e.dm_entity_path as Position "
                + "FROM document d, entity_log dl, dm_entity e " + "WHERE d.id=dl.dm_entity_id  "
                + "AND d.id=e.dm_entity_id " + "AND dl.dm_entity_type=3  " + "AND dl.action IN ( "
                + ActionType.READ + "," + ActionType.UPDATE + "," + ActionType.CREATE + ") "
                + "AND dl.log_time >= :dateFrom " + "AND dl.log_time <= :dateTo "
                + "GROUP BY e.dm_entity_name,e.dm_entity_path,e.dm_entity_id  " + "ORDER BY "
                + (order == null ? "HitsCount" : order) + " " + (asc ? "ASC" : "DESC");

        SQLQuery sql = FactoryInstantiator.getInstance().getDtrFactory().getSession().createSQLQuery(rq);
        sql.addScalar("DocumentName", StringType.INSTANCE);
        sql.addScalar("HitsCount", IntegerType.INSTANCE);
        sql.addScalar("Position", StringType.INSTANCE);
        sql.setDate("dateFrom", dtFrom.getTime());
        sql.setDate("dateTo", dtTo.getTime());

        List<Object[]> lReports = sql.list();
        Report report = new Report("DocumentHits");
        report.addColumn("Position");
        report.addColumn("DocumentName");
        report.addColumn("HitsCount");

        for (Object[] r : lReports) {
            Vector<Cell> cells = new Vector<Cell>();
            cells.add(new Cell("Position",
                    (String) ((String) r[2]).substring(0, ((String) r[2]).lastIndexOf('/'))));
            cells.add(new Cell("DocumentName", (String) r[0]));
            cells.add(new Cell("HitsCount", (Integer) r[1]));

            report.addRow(new Row(cells));
        }

        return report.toXML();
    } catch (HibernateException he) {
        he.printStackTrace();
        throw he;
    }
}