Example usage for org.hibernate Query setProperties

List of usage examples for org.hibernate Query setProperties

Introduction

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

Prototype

Query<R> setProperties(Map bean);

Source Link

Document

Bind the values of the given Map for each named parameters of the query, matching key names with parameter names and mapping value types to Hibernate types using heuristics.

Usage

From source file:cn.dao.MedicineSalesDao.java

@SuppressWarnings("unchecked")
public List<Object> query(MedicineSales vo, PageResult page) {
    Session session = this.getSessionFactory().getCurrentSession();
    Map<String, Object> properties = new HashMap<>();
    StringBuffer hql = new StringBuffer();
    hql.append("select t.sale_batch_number,t.sale_date,u.name");
    hql.append(" from medicine_sales t");
    hql.append(" left join user_info u");
    hql.append(" on t.user_id = u.id");
    hql.append(" group by t.sale_batch_number,t.sale_date,u.name");
    hql.append(" order by t.sale_date desc");
    Query query = session.createSQLQuery(hql.toString());
    query.setProperties(properties);
    if (page != null) {
        int items = getPageCount(session, hql.toString(), properties);
        page.setItems(items);//from  w  w w .  j  a v a2  s  . c o m
        query.setFirstResult(page.getFirstResult());
        query.setMaxResults(page.getMaxResult());
    }
    return query.list();
}

From source file:cn.dao.MedicineSalesDao.java

public List<Object> queryByBatchNumber(MedicineSales vo, PageResult page) {
    Session session = this.getSessionFactory().getCurrentSession();
    Map<String, Object> properties = new HashMap<>();
    StringBuffer hql = new StringBuffer();
    hql.append("select u.license_number,u.medicine_name,t.sale_price,t.sale_number");
    hql.append(" from medicine_sales t");
    hql.append(" left join medicine_storehouse s");
    hql.append(" on t.medicine_store_house_id = s.id");
    hql.append(" left join medicine_info u");
    hql.append(" on s.medicine_id = u.id");
    hql.append(" where t.sale_batch_number = :batchNumber");
    hql.append(" order by t.sale_date desc");
    Query query = session.createSQLQuery(hql.toString());
    properties.put("batchNumber", vo.getSaleBatchNumber());
    query.setProperties(properties);
    if (page != null) {
        int items = getPageCount(session, hql.toString(), properties);
        page.setItems(items);// ww  w  . ja va2 s. co m
        query.setFirstResult(page.getFirstResult());
        query.setMaxResults(page.getMaxResult());
    }
    return query.list();
}

From source file:cn.dayuanzi.dao.BaseDao.java

License:Apache License

/**
 * ?sql?Query.//w w w  .j ava 2  s .c  o  m
 * find()???.
 * 
 * @param values ????,?.
 */
public Query createSqlQuery(final String queryString, final Map<String, ?> values) {
    Assert.hasText(queryString, "queryString?");
    Query query = getSession().createSQLQuery(queryString);
    if (values != null) {
        query.setProperties(values);
    }
    return query;
}

From source file:cn.dayuanzi.dao.BaseDao.java

License:Apache License

/**
 * ?HQL?Query.//from w ww  . j  av  a 2 s .co m
 * find()???.
 * 
 * @param values ???,??.
 */
public Query createQuery(final String queryString, final Map<String, ?> values) {
    Assert.hasText(queryString, "queryString?");
    Query query = getSession().createQuery(queryString);
    if (values != null) {
        query.setProperties(values);
    }
    return query;
}

From source file:cn.hxh.springside.orm.hibernate.SimpleHibernateDao.java

License:Apache License

/**
 * ?HQL?Query./*ww  w . j  a v a  2  s  .  com*/
 * find()???.
 * 
 * @param values ???,??.
 */
public Query createQuery(final String queryString, final Map<String, ?> values) {
    AssertUtils.hasText(queryString, "queryString?");
    Query query = getSession().createQuery(queryString);
    if (values != null) {
        query.setProperties(values);
    }
    return query;
}

From source file:cn.newtouch.util.hibernate.SimpleHibernateDao.java

License:Open Source License

public Query createQuery(final String queryString, final Map<String, ?> values, final Page<T> page) {
    Assert.hasText(queryString, "queryString?");
    String str = queryString;/*w  w w. j a va  2s .  co  m*/
    if (page.isOrderBySetted()) {
        str += " order by " + page.getOrderBy() + " " + page.getOrder();
    }
    Query query = getSession().createQuery(str);
    if (values != null) {
        query.setProperties(values);
    }
    return query;
}

From source file:com.age.core.orm.hibernate.SimpleHibernateDao.java

License:Apache License

public Query createSQLQuery(final String queryString, final Map<String, ?> values) {
    AssertUtils.hasText(queryString, "queryString?");
    Query query = getSession().createSQLQuery(queryString);
    if (values != null) {
        query.setProperties(values);
    }/*  w  w  w  .  j  av a  2s. c  o  m*/
    return query;
}

From source file:com.asha.tow.dao.impl.UserDaoImpl.java

@Override
public User login(String username, String password) {
    Query query = getSession()
            .createSQLQuery("select * from User where username=:username and password=:password");
    query.setProperties(User.class);
    query.setString("username", username);
    query.setString("password", password);
    List list = query.list();/*from w  ww . ja v a  2  s .c  om*/
    User user = null;
    for (Iterator it = list.iterator(); it.hasNext();) {
        User u = (User) it.next();
        user = new User(u.getUsername(), u.getEmail(), u.getPassword(), u.getLastlog());
    }
    return user;

}

From source file:com.cmweb.orm.hibernate.SimpleHibernateDao.java

License:Apache License

public Query createQuery(final String queryString, final Map<String, Object> values) {
    Query query = getSession().createQuery(queryString);
    if (values != null) {
        query.setProperties(values);
    }//  www. j a  v  a2  s . com
    return query;
}

From source file:com.cndatacom.core.orm.hibernate.SimpleHibernateDao.java

License:Apache License

/**
 * ?HQL?Query./* w  w w .jav a  2s . com*/
 * 
 * @param values ???,??.
 */
public Query createSQLQuery(final String queryString, final Map<String, ?> values) {
    Assert.hasText(queryString, "queryString?");
    Query query = getSession().createSQLQuery(queryString)
            .setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP);

    if (values != null) {
        query.setProperties(values);
    }
    return query;
}