package com.vci.server.bof.service;
|
|
import java.sql.SQLException;
|
import java.sql.Statement;
|
|
import org.hibernate.HibernateException;
|
import org.hibernate.Session;
|
|
import com.vci.server.base.persistence.dao.HibernateSessionFactory;
|
|
public class BatchSqlService {
|
|
private static BatchSqlService instance = null;
|
|
private BatchSqlService() {
|
|
}
|
|
public static synchronized BatchSqlService getInstance() {
|
if (instance == null) {
|
instance = new BatchSqlService();
|
}
|
|
return instance;
|
}
|
|
public boolean executeUpdateSqls(String[] sqls) throws HibernateException, SQLException {
|
boolean rs = false;
|
Session session = HibernateSessionFactory.getSession();
|
Statement st = null;
|
try {
|
st = session.connection().createStatement();
|
for (int i = 0; i < sqls.length; i++) {
|
st.addBatch(sqls[i]);
|
if ((i + 1) % 200 == 0) {
|
st.executeBatch();
|
}
|
}
|
|
if (sqls.length % 200 != 0) {
|
st.executeBatch();
|
}
|
rs = true;
|
} finally {
|
if (st != null) {
|
st.close();
|
st = null;
|
}
|
}
|
|
return rs;
|
}
|
}
|