Example usage for org.hibernate Query setString

List of usage examples for org.hibernate Query setString

Introduction

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

Prototype

@Deprecated
@SuppressWarnings("unchecked")
default Query<R> setString(String name, String val) 

Source Link

Document

Bind a named String-valued parameter.

Usage

From source file:cl.vmetrix.operation.persistence.OperationDAOImpl.java

License:Open Source License

@Override
public void deletePricing(Pricing pricing) {
    // sessionFactory.getCurrentSession().delete(pricing);
    Query query = sessionFactory.getCurrentSession()
            .createQuery("delete Pricing where TRANSACTION_PROCESS_DATE = :date");
    query.setString("date", String.valueOf(pricing.getProcessDate()));

    query.executeUpdate();/*from   w  w  w .  j  a  va2 s  .com*/
    pricing = null;
    query = null;

}

From source file:cl.vmetrix.operation.persistence.OperationDAOImpl.java

License:Open Source License

@Override
public void deleteProfit(Profit profit) {
    // sessionFactory.getCurrentSession().delete(profit);
    Query query = sessionFactory.getCurrentSession()
            .createQuery("delete Profit where TRANSACTION_PROCESS_DATE = :date");
    query.setString("date", String.valueOf(profit.getProcessDate()));

    query.executeUpdate();//  ww  w. j a  v a 2s .co  m
    profit = null;
    query = null;

}

From source file:cl.vmetrix.operation.persistence.OperationDAOImpl.java

License:Open Source License

@Override
public void deleteSide(Side side) {
    // sessionFactory.getCurrentSession().delete(side);
    Query query = sessionFactory.getCurrentSession()
            .createQuery("delete Side where TRANSACTION_PROCESS_DATE = :date");
    query.setString("date", String.valueOf(side.getProcessDate()));

    query.executeUpdate();//from   w w w. jav  a  2  s.  c o m
    side = null;
    query = null;

}

From source file:cl.vmetrix.operation.persistence.OperationDAOImpl.java

License:Open Source License

@Override
public void deleteTranInfo(TransactionInfo transactionInfo) {
    // sessionFactory.getCurrentSession().delete(transactionInfo);
    Query query = sessionFactory.getCurrentSession()
            .createQuery("delete TransactionInfo where TRANSACTION_PROCESS_DATE = :date");
    query.setString("date", String.valueOf(transactionInfo.getProcessDate()));

    query.executeUpdate();/*from  ww  w .  j  a v a  2 s  .  co m*/
    transactionInfo = null;
    query = null;

}

From source file:cl.vmetrix.operation.persistence.OperationDAOImpl.java

License:Open Source License

@Override
public void deleteTranSaction(Transaction transaction) {
    // sessionFactory.getCurrentSession().delete(transaction);
    Query query = sessionFactory.getCurrentSession()
            .createQuery("delete Transaction where TRANSACTION_PROCESS_DATE = :date");
    query.setString("date", String.valueOf(transaction.getProcessDate()));

    query.executeUpdate();//from   w  w w.  j a  v  a2s .  c o m
    transaction = null;
    query = null;

}

From source file:classe.MembreUtil.java

public Membre getClientConnexion(String nomUtil, String Mdp) {
    Membre unMembre = null;//from  w ww  .  j a  v a  2 s.c o m
    List<Membre> listeClients = null;

    Transaction tx = null;
    this.session = HibernateUtil.getSessionFactory().openSession();
    try {
        tx = session.beginTransaction();

        // Liste de tous les livres
        Query mem = session.createQuery("from Membre where Nomutil = :nomUtil AND Mpd = :Mdp");
        mem.setString("nomUtil", nomUtil);
        mem.setString("Mdp", Mdp);
        listeClients = mem.list();
    } catch (Exception e) {
        e.printStackTrace();
    }
    this.session.close();
    if (listeClients.size() != 0) {
        return listeClients.get(0);
    } else {
        return null;
    }
}

From source file:cn.com.sinosoft.cimp.recordsummarize.datadeduplication.service.impl.DataDeduplicationService.java

public Integer findTotalPage(String sql, String crCode, String boxT, List<Map<String, Object>> params) {
    StringBuffer finalSql = new StringBuffer();
    StringBuffer sb = new StringBuffer();
    String colTableName = "";
    StringBuffer temp = new StringBuffer();
    colTableName = queryCreditItemTableFieldName(
            "select CODE_COLLECTION_TABLE from dic_credit_record_management where cr_code='" + crCode + "'");
    //      String s1 = colTableName.substring(8);
    //      String s2 = "CIMP_"+s1;
    //      sql = sql.replace(s2, colTableName);
    String ruleMin = "";//??
    String ruleMax = "";//??
    if (boxT != null && boxT.length() > 0) {
        ruleMin = boxT.split(",")[0];
        ruleMax = boxT;// w ww .  j  a  va 2 s. c o m
        sb.append("select t.* from " + colTableName + " t where " + ruleMin);
        sb.append(" in (select c." + ruleMin + " from " + colTableName + " c where c.state_valid = '02' ");
        if (colTableName.equals("CIMP_CO_FOOD_LICENSE")) {
            if (crCode.equals("0103000000")) {
                sb.append(" and c.product_type like '?' ");
            }
            if (crCode.equals("0104000000")) {
                sb.append(" and c.product_type like '???' ");
            }
            if (crCode.equals("0105000000")) {
                sb.append(" and c.product_type like '????' ");
            }
            if (crCode.equals("0106000000")) {
                sb.append(" and c.product_type like '?' ");
            }
        }
        if (colTableName.equals("CIMP_CO_WATER")) {
            if (crCode.equals("0111000000")) {//
                sb.append(" and c.comp_type like '0203%' ");
            }
        }
        if (colTableName.equals("CIMP_CO_DISCIPLINE")) {
            if (crCode.equals("0201010000")) {//???
                sb.append(" and c.specialty_primary like '01%' ");
            }
            if (crCode.equals("0206080000")) {//???
                sb.append(" and c.specialty_primary like '08%' ");
            }
            if (crCode.equals("0207020000")) {//??????
                sb.append(" and c.specialty_primary like '0203%' ");
            }
            if (crCode.equals("0203050000")) {//???
                sb.append(" and c.specialty_primary like '05%' ");
            }
            if (crCode.equals("0204030000")) {//?)???
                sb.append(" and c.specialty_primary like '03%' ");
            }
            if (crCode.equals("0205040000")) {//???
                sb.append(" and c.specialty_primary like '04%' ");
            }
            if (crCode.equals("0208070000")) {//???---??like '07%' 
                sb.append(" and c.specialty_primary like '07%' ");
            }
            if (crCode.equals("0202020000")) {//???
                sb.append(" and c.specialty_primary like '02%' ");
            }
        }
        //         sb.append(" group by "+ruleMax+" having count(1) > 1) and state_valid = '02'  order by "+ruleMin);
        sb.append(" group by " + ruleMax + " having count(1) > 1) and state_valid = '02' ");
        if (colTableName.equals("CIMP_CO_FOOD_LICENSE")) {
            if (crCode.equals("0103000000")) {
                sb.append(" and t.product_type like '?' ");
            }
            if (crCode.equals("0104000000")) {
                sb.append(" and t.product_type like '???' ");
            }
            if (crCode.equals("0105000000")) {
                sb.append(" and t.product_type like '????' ");
            }
            if (crCode.equals("0106000000")) {
                sb.append(" and t.product_type like '?' ");
            }
        }
        if (colTableName.equals("CIMP_CO_WATER")) {
            if (crCode.equals("0111000000")) {//
                sb.append(" and t.comp_type like '0203%' ");
            }
        }
        if (colTableName.equals("CIMP_CO_DISCIPLINE")) {
            if (crCode.equals("0201010000")) {//???
                sb.append(" and t.specialty_primary like '01%' ");
            }
            if (crCode.equals("0206080000")) {//???
                sb.append(" and t.specialty_primary like '08%' ");
            }
            if (crCode.equals("0207020000")) {//??????
                sb.append(" and t.specialty_primary like '0203%' ");
            }
            if (crCode.equals("0203050000")) {//???
                sb.append(" and t.specialty_primary like '05%' ");
            }
            if (crCode.equals("0204030000")) {//?)???
                sb.append(" and t.specialty_primary like '03%' ");
            }
            if (crCode.equals("0205040000")) {//???
                sb.append(" and t.specialty_primary like '04%' ");
            }
            if (crCode.equals("0208070000")) {//???---??like '07%' 
                sb.append(" and t.specialty_primary like '07%' ");
            }
            if (crCode.equals("0202020000")) {//???
                sb.append(" and t.specialty_primary like '02%' ");
            }
        }
        sb.append(" order by " + ruleMin);
    }
    if (!params.isEmpty() || params.size() != 0) {
        int sum = 0;
        temp.append(" select distinct ");
        temp.append(ruleMin);
        temp.append(" from ( ");
        temp.append(sb);
        temp.append(" ) where 1 =1 ");
        temp.append(sql);
        Query query = hibernateTemplate.getSessionFactory().openSession().createSQLQuery(temp.toString());
        if (params.size() != 0) {//----------------------------------->
            for (Map<String, Object> map : params) {
                if (map.get("symbol").equals("R")) {
                    for (Entry<String, Object> entry : map.entrySet()) {
                        if (!(entry.getKey().equals("fuzzy") || entry.getKey().equals("symbol"))) {
                            query.setString(entry.getKey(), (String) entry.getValue());
                        }
                    }
                } else {
                    if (map.get("fuzzy").equals("T")) {
                        for (Entry<String, Object> entry : map.entrySet()) {
                            if (!(entry.getKey().equals("fuzzy") || entry.getKey().equals("symbol"))) {
                                query.setString(entry.getKey(), "%" + (String) entry.getValue() + "%");
                            }
                        }
                    } else {
                        for (Entry<String, Object> entry : map.entrySet()) {
                            if (!(entry.getKey().equals("fuzzy") || entry.getKey().equals("symbol"))) {
                                query.setString(entry.getKey(), (String) entry.getValue());
                            }
                        }
                    }
                }

            }
        }
        List<String> obj = query.list();
        if (obj.size() != 0) {
            String ruleStr = getSqlStrByList(obj, 999, ruleMin);
            //            for(int i=0;i<obj.size();i++){
            temp.delete(0, temp.length());
            temp.append("select count(*)  quantity from ");
            temp.append(colTableName);
            temp.append(" where ");
            //               temp.append(ruleMin);
            //               temp.append(" in (:obj) ");
            temp.append(ruleStr);
            temp.append(" and state_valid = '02' ");
            if (temp != null && temp.length() > 0) {
                Query qry = hibernateTemplate.getSessionFactory().openSession().createSQLQuery(temp.toString());
                //                  qry.setParameterList("obj", obj);
                qry.setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP);
                Map map = (Map) qry.list().get(0);
                BigDecimal b = (BigDecimal) map.get("QUANTITY");
                sum = b.intValue();
            }
            //            }
        }
        return sum;
    } else {
        temp.append("select count(*)  quantity from ( ");
        temp.append(sb);
        temp.append(" ) ");

    }
    //      StringBuffer sbSql = new StringBuffer(getSql(sql,crCode,boxT));
    //      finalSql.append("select count(*)  quantity from ( ");
    //      finalSql.append(sbSql + " )");
    if (temp != null && temp.length() > 0) {
        Query query = hibernateTemplate.getSessionFactory().openSession().createSQLQuery(temp.toString());
        query.setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP);
        Map map = (Map) query.list().get(0);
        BigDecimal b = (BigDecimal) map.get("QUANTITY");
        return b.intValue();
    }
    return 0;
}

From source file:cn.com.sinosoft.cimp.recordsummarize.datadeduplication.service.impl.DataDeduplicationService.java

public List<Map<String, Object>> findByPage(String sql, String crCode, String boxT,
        List<Map<String, Object>> params, String page, String rows) {
    //      StringBuffer orignalSql = new StringBuffer(getSql(sql,crCode,boxT));
    StringBuffer orignalSql = new StringBuffer();
    StringBuffer finalSql = new StringBuffer();
    StringBuffer sb = new StringBuffer();
    StringBuffer temp = new StringBuffer();
    String colTableName = queryCreditItemTableFieldName(
            "select CODE_COLLECTION_TABLE from dic_credit_record_management where cr_code='" + crCode + "'");
    //      String s1 = colTableName.substring(8);
    //      String s2 = "CIMP_"+s1;
    //      sql = sql.replace(s2, colTableName);
    String ruleMin = "";//??
    String ruleMax = "";//??
    String coltable = dao/*ww  w  .j a v  a  2s .  com*/
            .executeSql("SELECT T.QUERY_COL_RELEASE_SQL FROM DIC_CREDIT_RECORD_MANAGEMENT T WHERE T.CR_CODE='"
                    + crCode + "'");
    if (boxT != null && boxT.length() > 0) {
        ruleMin = boxT.split(",")[0];
        ruleMax = boxT;
        //         sb.append("select t.* from "+colTableName+" t where "+ruleMin);
        sb.append(coltable + " and " + ruleMin);
        sb.append(" in (select c." + ruleMin + " from " + colTableName + " c where c.state_valid = '02' ");
        if (colTableName.equals("CIMP_CO_FOOD_LICENSE")) {
            if (crCode.equals("0103000000")) {
                sb.append(" and c.product_type like '?' ");
            }
            if (crCode.equals("0104000000")) {
                sb.append(" and c.product_type like '???' ");
            }
            if (crCode.equals("0105000000")) {
                sb.append(" and c.product_type like '????' ");
            }
            if (crCode.equals("0106000000")) {
                sb.append(" and c.product_type like '?' ");
            }
        }
        if (colTableName.equals("CIMP_CO_WATER")) {
            if (crCode.equals("0111000000")) {//
                sb.append(" and c.comp_type like '0203%' ");
            }
        }
        if (colTableName.equals("CIMP_CO_DISCIPLINE")) {
            if (crCode.equals("0201010000")) {//???
                sb.append(" and c.specialty_primary like '01%' ");
            }
            if (crCode.equals("0206080000")) {//???
                sb.append(" and c.specialty_primary like '08%' ");
            }
            if (crCode.equals("0207020000")) {//??????
                sb.append(" and c.specialty_primary like '0203%' ");
            }
            if (crCode.equals("0203050000")) {//???
                sb.append(" and c.specialty_primary like '05%' ");
            }
            if (crCode.equals("0204030000")) {//?)???
                sb.append(" and c.specialty_primary like '03%' ");
            }
            if (crCode.equals("0205040000")) {//???
                sb.append(" and c.specialty_primary like '04%' ");
            }
            if (crCode.equals("0208070000")) {//???---??like '07%' 
                sb.append(" and c.specialty_primary like '07%' ");
            }
            if (crCode.equals("0202020000")) {//???
                sb.append(" and c.specialty_primary like '02%' ");
            }
        }
        //         sb.append(" group by "+ruleMax+" having count(1) > 1) and state_valid = '02'  order by "+ruleMin);
        sb.append(" group by " + ruleMax + " having count(1) > 1) and state_valid = '02' ");
        if (colTableName.equals("CIMP_CO_FOOD_LICENSE")) {
            if (crCode.equals("0103000000")) {
                sb.append(" and product_type like '?' ");
            }
            if (crCode.equals("0104000000")) {
                sb.append(" and product_type like '???' ");
            }
            if (crCode.equals("0105000000")) {
                sb.append(" and product_type like '????' ");
            }
            if (crCode.equals("0106000000")) {
                sb.append(" and product_type like '?' ");
            }
        }
        if (colTableName.equals("CIMP_CO_WATER")) {
            if (crCode.equals("0111000000")) {//
                sb.append(" and comp_type like '0203%' ");
            }
        }
        if (colTableName.equals("CIMP_CO_DISCIPLINE")) {
            if (crCode.equals("0201010000")) {//???
                sb.append(" and specialty_primary like '01%' ");
            }
            if (crCode.equals("0206080000")) {//???
                sb.append(" and specialty_primary like '08%' ");
            }
            if (crCode.equals("0207020000")) {//??????
                sb.append(" and specialty_primary like '0203%' ");
            }
            if (crCode.equals("0203050000")) {//???
                sb.append(" and specialty_primary like '05%' ");
            }
            if (crCode.equals("0204030000")) {//?)???
                sb.append(" and specialty_primary like '03%' ");
            }
            if (crCode.equals("0205040000")) {//???
                sb.append(" and specialty_primary like '04%' ");
            }
            if (crCode.equals("0208070000")) {//???---??like '07%' 
                sb.append(" and specialty_primary like '07%' ");
            }
            if (crCode.equals("0202020000")) {//???
                sb.append(" and specialty_primary like '02%' ");
            }
        }
        sb.append(" order by " + ruleMin);
    }
    if (!params.isEmpty() || params.size() != 0) {
        temp.append(" select ");
        temp.append(ruleMin);
        temp.append(" from ( ");
        temp.append(sb);
        temp.append(" ) where 1 = 1 ");
        temp.append(sql);
        Query query = hibernateTemplate.getSessionFactory().openSession().createSQLQuery(temp.toString());
        if (params.size() != 0) {//----------------------------------->
            for (Map<String, Object> map : params) {
                if (map.get("symbol").equals("R")) {
                    for (Entry<String, Object> entry : map.entrySet()) {
                        if (!(entry.getKey().equals("fuzzy") || entry.getKey().equals("symbol"))) {
                            query.setString(entry.getKey(), (String) entry.getValue());
                        }
                    }
                } else {
                    if (map.get("fuzzy").equals("T")) {
                        for (Entry<String, Object> entry : map.entrySet()) {
                            if (!(entry.getKey().equals("fuzzy") || entry.getKey().equals("symbol"))) {
                                query.setString(entry.getKey(), "%" + (String) entry.getValue() + "%");
                            }
                        }
                    } else {
                        for (Entry<String, Object> entry : map.entrySet()) {
                            if (!(entry.getKey().equals("fuzzy") || entry.getKey().equals("symbol"))) {
                                query.setString(entry.getKey(), (String) entry.getValue());
                            }
                        }
                    }
                }

            }
        }
        List<String> obj = query.list();
        if (obj.size() != 0) {
            String ruleStr = getSqlStrByList(obj, 999, ruleMin);
            finalSql.append("SELECT * ");
            //            finalSql.append(" * ");
            finalSql.append(" FROM ( ");
            finalSql.append(" SELECT ORINGAL.*, ROWNUM rnum ");
            //            finalSql.append(" ORINGAL.*, ROWNUM rnum ");
            finalSql.append(" FROM ( ");
            //            finalSql.append(" select * from "+colTableName+" where "+ruleMin+" in (:obj) and state_valid='02' order by "+ruleMax+"");//----------
            finalSql.append(" select * from ( " + sb + " ) where " + ruleStr + " and state_valid='02' order by "
                    + ruleMax);
            finalSql.append(" ) ORINGAL");
            finalSql.append(" WHERE ROWNUM <=  " + Integer.parseInt(page) * (Integer.parseInt(rows)));
            finalSql.append(" ) ");
            finalSql.append(" WHERE ");
            finalSql.append(" rnum > " + (Integer.parseInt(page) - 1) * (Integer.parseInt(rows)));
            Query qry = hibernateTemplate.getSessionFactory().openSession().createSQLQuery(finalSql.toString());
            //            qry.setParameterList("obj", obj);
            qry.setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP);
            DataHandleUtil u = new DataHandleUtil();
            List<Map<String, Object>> newItems = u.idCardHandlerItem(qry.list(), "ID_CARD");
            return newItems;
        }
        return new ArrayList<Map<String, Object>>();
    } else {
        finalSql.append("SELECT");
        finalSql.append(" * ");
        finalSql.append(" FROM ( ");
        finalSql.append(" SELECT ");
        finalSql.append(" ORINGAL.*, ROWNUM rnum ");
        finalSql.append(" FROM ( ");
        finalSql.append(sb);
        finalSql.append(" ) ORINGAL");
        finalSql.append(" ) ");
        finalSql.append(" WHERE ");
        finalSql.append(" rnum > " + (Integer.parseInt(page) - 1) * (Integer.parseInt(rows)));
        finalSql.append(" AND rnum <=  " + Integer.parseInt(page) * (Integer.parseInt(rows)));
        Query query = hibernateTemplate.getSessionFactory().openSession().createSQLQuery(finalSql.toString());
        if (params.size() != 0) {
            for (int i = 0; i < params.size(); i++) {
                Map<String, Object> map = params.get(i);
                if (map.get("symbol").equals("R")) {
                    for (Entry<String, Object> entry : map.entrySet()) {
                        if (!(entry.getKey().equals("fuzzy") || entry.getKey().equals("symbol"))) {
                            query.setString(entry.getKey(), (String) entry.getValue());
                        }
                    }
                } else {
                    if (map.get("fuzzy").equals("T")) {

                        for (Entry<String, Object> entry : map.entrySet()) {
                            if (!(entry.getKey().equals("fuzzy") || entry.getKey().equals("symbol"))) {
                                query.setString(entry.getKey(), "%" + (String) entry.getValue() + "%");
                            }
                        }

                    } else {
                        for (Entry<String, Object> entry : map.entrySet()) {
                            if (!(entry.getKey().equals("fuzzy") || entry.getKey().equals("symbol"))) {
                                query.setString(entry.getKey(), (String) entry.getValue());

                            }
                        }
                    }
                }

            }
        }
        query.setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP);
        DataHandleUtil u = new DataHandleUtil();
        List<Map<String, Object>> newItems = u.idCardHandlerItem(query.list(), "ID_CARD");
        return newItems;
    }
}

From source file:cn.dao.MedicineInfoDao.java

public List<MedicineInfo> queryFuzzy(String search) {
    Session session = this.getSessionFactory().getCurrentSession();
    StringBuffer hql = new StringBuffer();
    hql.append("from MedicineInfo");
    hql.append(" where licenseNumber like :search");
    hql.append(" or medicineName like :search");
    hql.append(" or medicineENName like :search");
    Query query = session.createQuery(hql.toString());
    query.setString("search", "%" + search + "%");
    query.setMaxResults(10);//  ww w. j  av a  2s  .  c om
    return query.list();
}

From source file:cn.dao.MedicineInfoDao.java

public List<MedicineInfo> queryByDrugStandardCode(String drugStandardCode) {
    Session session = this.getSessionFactory().getCurrentSession();
    StringBuffer hql = new StringBuffer();
    hql.append("from MedicineInfo");
    hql.append(" where drugStandardCode like :search");
    Query query = session.createQuery(hql.toString());
    query.setString("search", "%" + drugStandardCode + "%");
    return query.list();
}