|
@@ -14,23 +14,22 @@
|
|
|
* See the License for the specific language governing permissions and
|
|
|
* limitations under the License.
|
|
|
*/
|
|
|
+
|
|
|
package org.apache.dolphinscheduler.dao.datasource;
|
|
|
|
|
|
-import com.alibaba.druid.pool.DruidDataSource;
|
|
|
-import com.baomidou.mybatisplus.annotation.IdType;
|
|
|
-import com.baomidou.mybatisplus.core.MybatisConfiguration;
|
|
|
-import com.baomidou.mybatisplus.core.config.GlobalConfig;
|
|
|
-import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
|
|
|
-import com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean;
|
|
|
-import org.apache.commons.configuration.ConfigurationException;
|
|
|
-import org.apache.commons.configuration.PropertiesConfiguration;
|
|
|
+import static org.apache.dolphinscheduler.common.Constants.DATASOURCE_PROPERTIES;
|
|
|
+
|
|
|
import org.apache.dolphinscheduler.common.Constants;
|
|
|
-import org.apache.dolphinscheduler.dao.utils.PropertyUtils;
|
|
|
+import org.apache.dolphinscheduler.common.utils.PropertyUtils;
|
|
|
+
|
|
|
import org.apache.ibatis.mapping.DatabaseIdProvider;
|
|
|
import org.apache.ibatis.mapping.VendorDatabaseIdProvider;
|
|
|
import org.apache.ibatis.session.SqlSession;
|
|
|
import org.apache.ibatis.session.SqlSessionFactory;
|
|
|
import org.apache.ibatis.type.JdbcType;
|
|
|
+
|
|
|
+import java.util.Properties;
|
|
|
+
|
|
|
import org.mybatis.spring.SqlSessionTemplate;
|
|
|
import org.mybatis.spring.annotation.MapperScan;
|
|
|
import org.slf4j.Logger;
|
|
@@ -41,7 +40,12 @@ import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
|
|
|
import org.springframework.core.io.support.ResourcePatternResolver;
|
|
|
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
|
|
|
|
|
|
-import java.util.Properties;
|
|
|
+import com.alibaba.druid.pool.DruidDataSource;
|
|
|
+import com.baomidou.mybatisplus.annotation.IdType;
|
|
|
+import com.baomidou.mybatisplus.core.MybatisConfiguration;
|
|
|
+import com.baomidou.mybatisplus.core.config.GlobalConfig;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
|
|
|
+import com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean;
|
|
|
|
|
|
|
|
|
/**
|
|
@@ -53,9 +57,13 @@ public class SpringConnectionFactory {
|
|
|
|
|
|
private static final Logger logger = LoggerFactory.getLogger(SpringConnectionFactory.class);
|
|
|
|
|
|
+ static {
|
|
|
+ PropertyUtils.loadPropertyFile(DATASOURCE_PROPERTIES);
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
- * pagination interceptor
|
|
|
+ * pagination interceptor
|
|
|
+ *
|
|
|
* @return pagination interceptor
|
|
|
*/
|
|
|
@Bean
|
|
@@ -65,9 +73,10 @@ public class SpringConnectionFactory {
|
|
|
|
|
|
/**
|
|
|
* get the data source
|
|
|
+ *
|
|
|
* @return druid dataSource
|
|
|
*/
|
|
|
- @Bean(destroyMethod="")
|
|
|
+ @Bean(destroyMethod = "")
|
|
|
public DruidDataSource dataSource() {
|
|
|
|
|
|
DruidDataSource druidDataSource = new DruidDataSource();
|
|
@@ -76,30 +85,31 @@ public class SpringConnectionFactory {
|
|
|
druidDataSource.setUrl(PropertyUtils.getString(Constants.SPRING_DATASOURCE_URL));
|
|
|
druidDataSource.setUsername(PropertyUtils.getString(Constants.SPRING_DATASOURCE_USERNAME));
|
|
|
druidDataSource.setPassword(PropertyUtils.getString(Constants.SPRING_DATASOURCE_PASSWORD));
|
|
|
- druidDataSource.setValidationQuery(PropertyUtils.getString(Constants.SPRING_DATASOURCE_VALIDATION_QUERY,"SELECT 1"));
|
|
|
-
|
|
|
- druidDataSource.setPoolPreparedStatements(PropertyUtils.getBoolean(Constants.SPRING_DATASOURCE_POOL_PREPARED_STATEMENTS,true));
|
|
|
- druidDataSource.setTestWhileIdle(PropertyUtils.getBoolean(Constants.SPRING_DATASOURCE_TEST_WHILE_IDLE,true));
|
|
|
- druidDataSource.setTestOnBorrow(PropertyUtils.getBoolean(Constants.SPRING_DATASOURCE_TEST_ON_BORROW,true));
|
|
|
- druidDataSource.setTestOnReturn(PropertyUtils.getBoolean(Constants.SPRING_DATASOURCE_TEST_ON_RETURN,true));
|
|
|
- druidDataSource.setKeepAlive(PropertyUtils.getBoolean(Constants.SPRING_DATASOURCE_KEEP_ALIVE,true));
|
|
|
-
|
|
|
- druidDataSource.setMinIdle(PropertyUtils.getInt(Constants.SPRING_DATASOURCE_MIN_IDLE,5));
|
|
|
- druidDataSource.setMaxActive(PropertyUtils.getInt(Constants.SPRING_DATASOURCE_MAX_ACTIVE,50));
|
|
|
- druidDataSource.setMaxWait(PropertyUtils.getInt(Constants.SPRING_DATASOURCE_MAX_WAIT,60000));
|
|
|
- druidDataSource.setMaxPoolPreparedStatementPerConnectionSize(PropertyUtils.getInt(Constants.SPRING_DATASOURCE_MAX_POOL_PREPARED_STATEMENT_PER_CONNECTION_SIZE,20));
|
|
|
- druidDataSource.setInitialSize(PropertyUtils.getInt(Constants.SPRING_DATASOURCE_INITIAL_SIZE,5));
|
|
|
- druidDataSource.setTimeBetweenEvictionRunsMillis(PropertyUtils.getLong(Constants.SPRING_DATASOURCE_TIME_BETWEEN_EVICTION_RUNS_MILLIS,60000));
|
|
|
- druidDataSource.setTimeBetweenConnectErrorMillis(PropertyUtils.getLong(Constants.SPRING_DATASOURCE_TIME_BETWEEN_CONNECT_ERROR_MILLIS,60000));
|
|
|
- druidDataSource.setMinEvictableIdleTimeMillis(PropertyUtils.getLong(Constants.SPRING_DATASOURCE_MIN_EVICTABLE_IDLE_TIME_MILLIS,300000));
|
|
|
- druidDataSource.setValidationQueryTimeout(PropertyUtils.getInt(Constants.SPRING_DATASOURCE_VALIDATION_QUERY_TIMEOUT,3));
|
|
|
+ druidDataSource.setValidationQuery(PropertyUtils.getString(Constants.SPRING_DATASOURCE_VALIDATION_QUERY, "SELECT 1"));
|
|
|
+
|
|
|
+ druidDataSource.setPoolPreparedStatements(PropertyUtils.getBoolean(Constants.SPRING_DATASOURCE_POOL_PREPARED_STATEMENTS, true));
|
|
|
+ druidDataSource.setTestWhileIdle(PropertyUtils.getBoolean(Constants.SPRING_DATASOURCE_TEST_WHILE_IDLE, true));
|
|
|
+ druidDataSource.setTestOnBorrow(PropertyUtils.getBoolean(Constants.SPRING_DATASOURCE_TEST_ON_BORROW, true));
|
|
|
+ druidDataSource.setTestOnReturn(PropertyUtils.getBoolean(Constants.SPRING_DATASOURCE_TEST_ON_RETURN, true));
|
|
|
+ druidDataSource.setKeepAlive(PropertyUtils.getBoolean(Constants.SPRING_DATASOURCE_KEEP_ALIVE, true));
|
|
|
+
|
|
|
+ druidDataSource.setMinIdle(PropertyUtils.getInt(Constants.SPRING_DATASOURCE_MIN_IDLE, 5));
|
|
|
+ druidDataSource.setMaxActive(PropertyUtils.getInt(Constants.SPRING_DATASOURCE_MAX_ACTIVE, 50));
|
|
|
+ druidDataSource.setMaxWait(PropertyUtils.getInt(Constants.SPRING_DATASOURCE_MAX_WAIT, 60000));
|
|
|
+ druidDataSource.setMaxPoolPreparedStatementPerConnectionSize(PropertyUtils.getInt(Constants.SPRING_DATASOURCE_MAX_POOL_PREPARED_STATEMENT_PER_CONNECTION_SIZE, 20));
|
|
|
+ druidDataSource.setInitialSize(PropertyUtils.getInt(Constants.SPRING_DATASOURCE_INITIAL_SIZE, 5));
|
|
|
+ druidDataSource.setTimeBetweenEvictionRunsMillis(PropertyUtils.getLong(Constants.SPRING_DATASOURCE_TIME_BETWEEN_EVICTION_RUNS_MILLIS, 60000));
|
|
|
+ druidDataSource.setTimeBetweenConnectErrorMillis(PropertyUtils.getLong(Constants.SPRING_DATASOURCE_TIME_BETWEEN_CONNECT_ERROR_MILLIS, 60000));
|
|
|
+ druidDataSource.setMinEvictableIdleTimeMillis(PropertyUtils.getLong(Constants.SPRING_DATASOURCE_MIN_EVICTABLE_IDLE_TIME_MILLIS, 300000));
|
|
|
+ druidDataSource.setValidationQueryTimeout(PropertyUtils.getInt(Constants.SPRING_DATASOURCE_VALIDATION_QUERY_TIMEOUT, 3));
|
|
|
//auto commit
|
|
|
- druidDataSource.setDefaultAutoCommit(PropertyUtils.getBoolean(Constants.SPRING_DATASOURCE_DEFAULT_AUTO_COMMIT,true));
|
|
|
+ druidDataSource.setDefaultAutoCommit(PropertyUtils.getBoolean(Constants.SPRING_DATASOURCE_DEFAULT_AUTO_COMMIT, true));
|
|
|
return druidDataSource;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* * get transaction manager
|
|
|
+ *
|
|
|
* @return DataSourceTransactionManager
|
|
|
*/
|
|
|
@Bean
|
|
@@ -109,6 +119,7 @@ public class SpringConnectionFactory {
|
|
|
|
|
|
/**
|
|
|
* * get sql session factory
|
|
|
+ *
|
|
|
* @return sqlSessionFactory
|
|
|
* @throws Exception sqlSessionFactory exception
|
|
|
*/
|
|
@@ -139,16 +150,16 @@ public class SpringConnectionFactory {
|
|
|
|
|
|
/**
|
|
|
* get sql session
|
|
|
+ *
|
|
|
* @return SqlSession
|
|
|
- * @throws Exception
|
|
|
*/
|
|
|
@Bean
|
|
|
- public SqlSession sqlSession() throws Exception{
|
|
|
+ public SqlSession sqlSession() throws Exception {
|
|
|
return new SqlSessionTemplate(sqlSessionFactory());
|
|
|
}
|
|
|
|
|
|
@Bean
|
|
|
- public DatabaseIdProvider databaseIdProvider(){
|
|
|
+ public DatabaseIdProvider databaseIdProvider() {
|
|
|
DatabaseIdProvider databaseIdProvider = new VendorDatabaseIdProvider();
|
|
|
Properties properties = new Properties();
|
|
|
properties.setProperty("MySQL", "mysql");
|