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;
|
}
|
|
}
|