Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class HibernateWorker<T> implements Work {
- private final static Logger LOG = Logger.getLogger(HibernateWorker.class);
- private static final String ORACLE = "oracle";
- private static final String POSTGRESQL = "postgresql";
- boolean withResult;
- private String statement;
- private Object[] params;
- private Class<T> entityClass;
- private List<T> executeResult = null;
- private ProcedureExecutorImpl procedureExecutorImpl;
- HibernateWorker(String statement, Object[] params, boolean withResult) {
- this.statement = statement;
- this.params = params;
- this.withResult = withResult;
- }
- public void setEntityClass(Class<T> entityClass) {
- this.entityClass = entityClass;
- }
- public List<T> getExecuteResult() {
- return executeResult;
- }
- @Override
- public void execute(Connection connection) throws SQLException {
- initImpl(connection);
- if (withResult) {
- executeResult = procedureExecutorImpl.executeProcedure(statement, entityClass, params, connection);
- } else {
- procedureExecutorImpl.executeVoidProcedure(statement, params, connection);
- }
- }
- private void initImpl(Connection con) throws SQLException {
- DatabaseMetaData metaData = con.getMetaData();
- String driverName = metaData.getDriverName();
- String driverVersion = metaData.getDriverVersion();
- LOG.debug("execute Procedure in : " + driverName + " [" + driverVersion + "]");
- if (procedureExecutorImpl == null) {
- if ((!StringUtil.isBlank(driverName)) && (driverName.toLowerCase().indexOf(ORACLE) != -1)) {
- procedureExecutorImpl = OracleProcedureExecutorImpl.getInstance();
- } else if ((!StringUtil.isBlank(driverName)) && (driverName.toLowerCase().indexOf(POSTGRESQL) != -1)) {
- procedureExecutorImpl = PostgresqlProcedureExecutorImpl.getInstance();
- } else {
- BusinessException exception = new BusinessException("DB_DRIVER_NOT_MATCH", driverName);
- // exception.setModuleName("core");
- throw exception;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement