Example usage for org.hibernate SQLQuery setProperties

List of usage examples for org.hibernate SQLQuery setProperties

Introduction

In this page you can find the example usage for org.hibernate SQLQuery setProperties.

Prototype

@Override
    NativeQuery<T> setProperties(Map bean);

Source Link

Usage

From source file:com.abssh.util.GenericDao.java

License:Apache License

/**
 * SQL (=:property)// ww  w  . ja  v a 2 s. c o  m
 * 
 * @param sql
 *            SQL
 * @param values
 *            ?
 * @return ??object
 */
@SuppressWarnings("unchecked")
public List findListByProperty(String sql, final Map<String, Object> values) {
    SQLQuery query = getSession().createSQLQuery(sql);
    if (values != null && values.size() > 0) {
        query.setProperties(values);
    }
    return query.list();
}

From source file:com.eryansky.common.orm.core.hibernate.support.BasicHibernateDao.java

License:Apache License

/**
 * ?HQL?Query//  w  w  w .j  a va  2  s  . com
 *
 * @param queryOrSqlQuery query  NamedSQLQuery
 * @param values
 *            ???,??.
 *
 * @return {@link org.hibernate.Query}
 *
 */
protected SQLQuery createSQLQuery(String queryOrSqlQuery, Map<String, ?> values) {
    SQLQuery query = createSQLQuery(queryOrSqlQuery);
    if (values != null) {
        query.setProperties(values);
    }
    return query.addEntity(entityClass);
}

From source file:com.formkiq.core.dao.ReportDaoImpl.java

License:Apache License

@SuppressWarnings({ "unchecked", "resource" })
@Override/*from w  w  w  .  ja  v a  2  s . c o m*/
public List<Map<String, Object>> runReport(final ReportInput input) {

    StringBuilder sb = new StringBuilder();

    appendSelectSQL(sb, input);

    appendFromSQL(sb, input);

    appendWhereSQL(sb, input);

    appendWhereDateSQL(sb, input);

    appendGroupBySQL(sb, input);

    Session session = getEntityManager().unwrap(Session.class);

    SQLQuery q = session.createSQLQuery(sb.toString());
    addScalars(q, input);

    Map<Object, Object> map = createParameterMap(input);
    q.setProperties(map);

    List<Object[]> list = q.list();

    return translateToMap(input.getColumns(), list);
}

From source file:com.ghy.common.orm.hibernate.HibernateDao.java

License:Apache License

/**
 * ?sql??map?list/*w w  w. j a va2s .  c o  m*/
 * @param sql
 * @param params
 * @return
 */
public List<Object[]> findBySql(String sql, Map<String, ?> params) {
    SQLQuery queryObject = getSession().createSQLQuery(sql);
    if (params != null && params.size() > 0)
        queryObject.setProperties(params);
    return queryObject.list();
}

From source file:com.ghy.common.orm.hibernate.HibernateDao.java

License:Apache License

/**
 * ?sql???map??//from w w  w .  j  a v a  2 s . c om
 * @param sql
 * @param params
 * @return
 */
public Integer findBySqlCount(String sql, Map<String, ?> params) {
    SQLQuery queryObject = getSession().createSQLQuery(sql);
    if (params != null && params.size() > 0)
        queryObject.setProperties(params);
    List<BigDecimal> qlist = queryObject.list();
    if (qlist != null && qlist.size() > 0) {
        BigDecimal obj = qlist.get(0);
        return obj.intValue();
    }
    return 0;
}

From source file:com.ghy.common.orm.hibernate.HibernateDao.java

License:Apache License

/**
 * /*from  w  w  w. j ava2 s  . c o m*/
 * @param sql
 * @param params
 * @return
 */
public Float findBySqlFloat(String sql, Map<String, ?> params) {
    SQLQuery queryObject = getSession().createSQLQuery(sql);
    if (params != null && params.size() > 0)
        queryObject.setProperties(params);
    List<BigDecimal> qlist = queryObject.list();
    if (qlist != null && qlist.size() > 0) {
        BigDecimal obj = qlist.get(0);
        return obj.floatValue();
    }
    return Float.valueOf(0);
}

From source file:com.ghy.common.orm.hibernate.HibernateDao.java

License:Apache License

/**
 * ?sql???map?map??/*from w  ww .j a  v a 2  s .c o  m*/
 * @param sql
 * @param params
 * @return
 */
public Integer findBySqlCount(String sql, Map<String, ?> params, Map<String, ?> params2) {
    SQLQuery queryObject = getSession().createSQLQuery(sql);
    if (params != null && params.size() > 0) {
        queryObject.setProperties(params);
    }
    if (params2 != null && params2.size() > 0) {
        queryObject.setProperties(params2);
    }
    List<BigDecimal> qlist = queryObject.list();
    if (qlist != null && qlist.size() > 0) {
        BigDecimal obj = qlist.get(0);
        return obj.intValue();
    }
    return 0;
}

From source file:com.ghy.common.orm.hibernate.SimpleHibernateDao.java

License:Apache License

/**
 * ?SQL?SQLQuery. find()???./*  ww w. j av a 2 s.  com*/
 * 
 * @param values
 *            ???,??.
 */
public SQLQuery createSqlQuery(final String queryString, final Map<String, ?> values) {
    Assert.hasText(queryString, "queryString?");
    SQLQuery query = getSession().createSQLQuery(queryString);
    if ((values != null) && (values.size() > 0)) {
        query.setProperties(values);
    }
    return query;
}

From source file:com.ghy.common.orm.hibernate.SimpleHibernateDao.java

License:Apache License

/**
 * ?SQL?SQLQuery. find()???./* w  ww .j  a  v  a 2s .  c o m*/
 * 
 * @param values
 *            ???,??.
 */
public SQLQuery createSqlQuery(final String queryString, final Map<String, ?> values,
        final Map<String, ?> values2) {
    Assert.hasText(queryString, "queryString?");
    SQLQuery query = getSession().createSQLQuery(queryString);
    if ((values != null) && (values.size() > 0)) {
        query.setProperties(values);
    }
    if ((values2 != null) && (values2.size() > 0)) {
        query.setProperties(values2);
    }
    return query;
}

From source file:com.project.framework.dao.GenericDao.java

License:Apache License

/**
 * ?SQL??SQLQuery/*from  w w  w  . j  a va2 s.  co  m*/
 * 
 * @param values ???,??.
 */
public SQLQuery createNativeQuery(final String nativeQueryString, final Map<String, ?> values) {

    Assert.hasText(nativeQueryString, "nativeQueryString Can not NULL");

    SQLQuery query = getSession().createSQLQuery(nativeQueryString);
    if (values != null) {
        query.setProperties(values);
    }
    return query;
}