SHARE
TWEET

Untitled

a guest Dec 11th, 2019 89 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. public class HibernateWorker<T> implements Work {
  3.  
  4.     private final static Logger LOG = Logger.getLogger(HibernateWorker.class);
  5.    
  6.     private static final String ORACLE = "oracle";
  7.     private static final String POSTGRESQL = "postgresql";
  8.    
  9.     boolean withResult;
  10.     private String statement;
  11.     private Object[] params;
  12.     private Class<T> entityClass;
  13.     private List<T> executeResult = null;
  14.     private ProcedureExecutorImpl procedureExecutorImpl;
  15.    
  16.     HibernateWorker(String statement, Object[] params, boolean withResult) {
  17.         this.statement = statement;
  18.         this.params = params;
  19.         this.withResult = withResult;
  20.     }
  21.    
  22.     public void setEntityClass(Class<T> entityClass) {
  23.         this.entityClass = entityClass;
  24.     }
  25.    
  26.     public List<T> getExecuteResult() {
  27.         return executeResult;
  28.     }
  29.    
  30.     @Override
  31.     public void execute(Connection connection) throws SQLException {
  32.         initImpl(connection);
  33.         if (withResult) {
  34.             executeResult = procedureExecutorImpl.executeProcedure(statement, entityClass, params, connection);
  35.         } else {
  36.             procedureExecutorImpl.executeVoidProcedure(statement, params, connection);
  37.         }
  38.     }
  39.  
  40.     private void initImpl(Connection con) throws SQLException {
  41.         DatabaseMetaData metaData = con.getMetaData();
  42.         String driverName = metaData.getDriverName();
  43.         String driverVersion = metaData.getDriverVersion();
  44.         LOG.debug("execute Procedure in : " + driverName + " [" + driverVersion + "]");
  45.         if (procedureExecutorImpl == null) {
  46.             if ((!StringUtil.isBlank(driverName)) && (driverName.toLowerCase().indexOf(ORACLE) != -1)) {
  47.                 procedureExecutorImpl = OracleProcedureExecutorImpl.getInstance();
  48.             } else if ((!StringUtil.isBlank(driverName)) && (driverName.toLowerCase().indexOf(POSTGRESQL) != -1)) {
  49.                 procedureExecutorImpl = PostgresqlProcedureExecutorImpl.getInstance();
  50.             } else {
  51.                 BusinessException exception = new BusinessException("DB_DRIVER_NOT_MATCH", driverName);
  52. //              exception.setModuleName("core");
  53.                 throw exception;
  54.             }
  55.         }
  56.     }
  57. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top