|
@@ -30,7 +30,6 @@ import org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory;
|
|
|
import org.mybatis.spring.SqlSessionTemplate;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
-import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
|
|
|
|
|
|
import javax.sql.DataSource;
|
|
|
|
|
@@ -50,7 +49,7 @@ public class ConnectionFactory {
|
|
|
|
|
|
static {
|
|
|
try {
|
|
|
- conf = new PropertiesConfiguration(Constants.DATA_SOURCE_PROPERTIES);
|
|
|
+ conf = new PropertiesConfiguration(Constants.APPLICATION_PROPERTIES);
|
|
|
}catch (ConfigurationException e){
|
|
|
logger.error("load configuration excetpion",e);
|
|
|
System.exit(1);
|
|
@@ -61,19 +60,33 @@ public class ConnectionFactory {
|
|
|
* get the data source
|
|
|
*/
|
|
|
public static DruidDataSource getDataSource() {
|
|
|
+
|
|
|
DruidDataSource druidDataSource = new DruidDataSource();
|
|
|
-
|
|
|
- druidDataSource.setDriverClassName(conf.getString("spring.datasource.driver-class-name"));
|
|
|
- druidDataSource.setUrl(conf.getString("spring.datasource.url"));
|
|
|
- druidDataSource.setUsername(conf.getString("spring.datasource.username"));
|
|
|
- druidDataSource.setPassword(conf.getString("spring.datasource.password"));
|
|
|
- druidDataSource.setInitialSize(5);
|
|
|
- druidDataSource.setMinIdle(5);
|
|
|
- druidDataSource.setMaxActive(20);
|
|
|
- druidDataSource.setMaxWait(60000);
|
|
|
- druidDataSource.setTimeBetweenEvictionRunsMillis(60000);
|
|
|
- druidDataSource.setMinEvictableIdleTimeMillis(300000);
|
|
|
- druidDataSource.setValidationQuery("SELECT 1");
|
|
|
+
|
|
|
+ druidDataSource.setDriverClassName(conf.getString(Constants.SPRING_DATASOURCE_DRIVER_CLASS_NAME));
|
|
|
+ druidDataSource.setUrl(conf.getString(Constants.SPRING_DATASOURCE_URL));
|
|
|
+ druidDataSource.setUsername(conf.getString(Constants.SPRING_DATASOURCE_USERNAME));
|
|
|
+ druidDataSource.setPassword(conf.getString(Constants.SPRING_DATASOURCE_PASSWORD));
|
|
|
+ druidDataSource.setValidationQuery(conf.getString(Constants.SPRING_DATASOURCE_VALIDATION_QUERY));
|
|
|
+
|
|
|
+ druidDataSource.setPoolPreparedStatements(conf.getBoolean(Constants.SPRING_DATASOURCE_POOL_PREPARED_STATEMENTS));
|
|
|
+ druidDataSource.setTestWhileIdle(conf.getBoolean(Constants.SPRING_DATASOURCE_TEST_WHILE_IDLE));
|
|
|
+ druidDataSource.setTestOnBorrow(conf.getBoolean(Constants.SPRING_DATASOURCE_TEST_ON_BORROW));
|
|
|
+ druidDataSource.setTestOnReturn(conf.getBoolean(Constants.SPRING_DATASOURCE_TEST_ON_RETURN));
|
|
|
+ druidDataSource.setKeepAlive(conf.getBoolean(Constants.SPRING_DATASOURCE_KEEP_ALIVE));
|
|
|
+
|
|
|
+ druidDataSource.setMinIdle(conf.getInt(Constants.SPRING_DATASOURCE_MIN_IDLE));
|
|
|
+ druidDataSource.setMaxActive(conf.getInt(Constants.SPRING_DATASOURCE_MAX_ACTIVE));
|
|
|
+ druidDataSource.setMaxWait(conf.getInt(Constants.SPRING_DATASOURCE_MAX_WAIT));
|
|
|
+ druidDataSource.setMaxPoolPreparedStatementPerConnectionSize(conf.getInt(Constants.SPRING_DATASOURCE_MAX_POOL_PREPARED_STATEMENT_PER_CONNECTION_SIZE));
|
|
|
+ druidDataSource.setInitialSize(conf.getInt(Constants.SPRING_DATASOURCE_INITIAL_SIZE));
|
|
|
+ druidDataSource.setTimeBetweenEvictionRunsMillis(conf.getLong(Constants.SPRING_DATASOURCE_TIME_BETWEEN_EVICTION_RUNS_MILLIS));
|
|
|
+ druidDataSource.setTimeBetweenConnectErrorMillis(conf.getLong(Constants.SPRING_DATASOURCE_TIME_BETWEEN_CONNECT_ERROR_MILLIS));
|
|
|
+ druidDataSource.setMinEvictableIdleTimeMillis(conf.getLong(Constants.SPRING_DATASOURCE_MIN_EVICTABLE_IDLE_TIME_MILLIS));
|
|
|
+ druidDataSource.setValidationQueryTimeout(conf.getInt(Constants.SPRING_DATASOURCE_VALIDATION_QUERY_TIMEOUT));
|
|
|
+
|
|
|
+ druidDataSource.setDefaultAutoCommit(conf.getBoolean(Constants.SPRING_DATASOURCE_DEFAULT_AUTO_COMMIT));
|
|
|
+
|
|
|
return druidDataSource;
|
|
|
}
|
|
|
|
|
@@ -95,11 +108,12 @@ public class ConnectionFactory {
|
|
|
configuration.addMappers("org.apache.dolphinscheduler.dao.mapper");
|
|
|
|
|
|
MybatisSqlSessionFactoryBean sqlSessionFactoryBean = new MybatisSqlSessionFactoryBean();
|
|
|
+ sqlSessionFactoryBean.setConfiguration(configuration);
|
|
|
sqlSessionFactoryBean.setDataSource(dataSource);
|
|
|
+
|
|
|
sqlSessionFactoryBean.setTypeEnumsPackage("org.apache.dolphinscheduler.*.enums");
|
|
|
- sqlSessionFactoryBean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath*:org/apache/dolphinscheduler/dao/mapper/*.xml"));
|
|
|
- sqlSessionFactoryBean.setConfiguration(configuration);
|
|
|
- return sqlSessionFactoryBean.getObject();
|
|
|
+ sqlSessionFactory = sqlSessionFactoryBean.getObject();
|
|
|
+ return sqlSessionFactory;
|
|
|
}
|
|
|
}
|
|
|
}
|