ludc
2025-01-16 986aa62ed00bee39363bab41b4eeb8259d446efd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package com.vci.server.bof.service;
 
import java.util.Iterator;
import java.util.Map;
 
import org.hibernate.HibernateException;
import org.hibernate.SQLQuery;
import org.hibernate.Session;
 
import com.vci.server.base.persistence.dao.HibernateSessionFactory;
 
public class CustomSqlService {
 
    private static CustomSqlService instance = null;
 
    private CustomSqlService() {
 
    }
 
    public static synchronized CustomSqlService getInstance() {
        if (instance == null) {
            instance = new CustomSqlService();
        }
 
        return instance;
    }
    
    public boolean executeUpdateSql(String sql) throws HibernateException {
        boolean rs = false;
        Session session = HibernateSessionFactory.getSession();
        SQLQuery query = session.createSQLQuery(sql);
        int result = query.executeUpdate();
        if (result > 0) {
            rs = true;
        }
        return rs;
    }
    
    public boolean executeUpdateSql(String sql,Map<String,String> params) throws HibernateException{
        boolean rs = false;
        Session session = HibernateSessionFactory.getSession();
        SQLQuery query = session.createSQLQuery(sql);
        if(params != null && params.size() > 0){
            Iterator<String> it = params.keySet().iterator();
            while(it.hasNext()){
                String key = it.next();
                query.setParameter(Integer.valueOf(key), params.get(key));
            }
        }
        int result = query.executeUpdate();
        if (result > 0) {
            rs = true;
        }
        return rs;
    }
    
}