优化配置

This commit is contained in:
zhouhao
2016-10-18 09:17:05 +08:00
parent f480ce7319
commit 5c197a683e
2 changed files with 112 additions and 19 deletions

View File

@@ -16,14 +16,17 @@
package org.hsweb.web.datasource.dynamic;
import com.atomikos.datasource.pool.ConnectionPool;
import com.atomikos.jdbc.AtomikosDataSourceBean;
import org.hsweb.web.core.datasource.DatabaseType;
import org.springframework.beans.factory.BeanClassLoaderAware;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.StringUtils;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.LinkedList;
import java.util.List;
@@ -38,25 +41,25 @@ import java.util.Properties;
public class DynamicDataSourceProperties
implements BeanClassLoaderAware, InitializingBean {
private static final List<String> supportDatasourceType;
private String name = "core";
private DatabaseType type = DatabaseType.h2;
private String datasourceName = null;
private String username = "sa";
private String password = "";
private String url = "jdbc:h2:file:./data/h2db;DB_CLOSE_ON_EXIT=FALSE";
private String testQuery = null;
private int loginTimeout = -1;
private int maxLifetime = -1;
private int minPoolSize = 2;
private int maxPoolSize = 20;
private int borrowConnectionTimeout = 30;
private int reapTimeout = 0;
private int maxIdleTime = 60;
private int maintenanceInterval = 60;
private int defaultIsolationLevel = -1;
private int transactionTimeout = 300;
private Properties properties = null;
private ClassLoader classLoader = null;
private String name = "core";
private DatabaseType type = null;
private String datasourceName = null;
private String username = "sa";
private String password = "";
private String url = "jdbc:h2:file:./data/h2db;DB_CLOSE_ON_EXIT=FALSE";
private String testQuery;
private int loginTimeout = 0;
private int maxLifetime = 0;
private int minPoolSize = 2;
private int maxPoolSize = 20;
private int borrowConnectionTimeout = 30;
private int reapTimeout = 0;
private int maxIdleTime = 60;
private int maintenanceInterval = 60;
private int defaultIsolationLevel = -1;
private int transactionTimeout = 300;
private Properties properties = null;
private ClassLoader classLoader = null;
static {
supportDatasourceType = new LinkedList<>();
@@ -218,9 +221,14 @@ public class DynamicDataSourceProperties
@Override
public void afterPropertiesSet() throws Exception {
Assert.notNull(url);
Assert.notNull(username);
if (datasourceName == null) {
datasourceName = lookupSupportDatasourceName();
}
if (type == null) {
type = DatabaseType.fromJdbcUrl(getUrl());
}
if (!StringUtils.hasText(testQuery)) testQuery = getType().getTestQuery();
}

View File

@@ -11,6 +11,91 @@
"name": "hsweb.dynamic-datasource.name",
"type": "java.lang.String",
"sourceType": "org.hsweb.web.datasource.dynamic.DynamicDataSourceProperties"
},
{
"name": "hsweb.dynamic-datasource.type",
"type": "org.hsweb.web.core.datasource.DatabaseType",
"sourceType": "org.hsweb.web.datasource.dynamic.DynamicDataSourceProperties"
},
{
"name": "hsweb.dynamic-datasource.datasource-name",
"type": "java.lang.String",
"sourceType": "org.hsweb.web.datasource.dynamic.DynamicDataSourceProperties"
},
{
"name": "hsweb.dynamic-datasource.username",
"type": "java.lang.String",
"sourceType": "org.hsweb.web.datasource.dynamic.DynamicDataSourceProperties"
},
{
"name": "hsweb.dynamic-datasource.password",
"type": "java.lang.String",
"sourceType": "org.hsweb.web.datasource.dynamic.DynamicDataSourceProperties"
},
{
"name": "hsweb.dynamic-datasource.url",
"type": "java.lang.String",
"sourceType": "org.hsweb.web.datasource.dynamic.DynamicDataSourceProperties"
},
{
"name": "hsweb.dynamic-datasource.testQuery",
"type": "java.lang.String",
"sourceType": "org.hsweb.web.datasource.dynamic.DynamicDataSourceProperties"
},
{
"name": "hsweb.dynamic-datasource.login-timeout",
"type": "java.lang.Integer",
"sourceType": "org.hsweb.web.datasource.dynamic.DynamicDataSourceProperties"
},
{
"name": "hsweb.dynamic-datasource.max-life-time",
"type": "java.lang.Integer",
"sourceType": "org.hsweb.web.datasource.dynamic.DynamicDataSourceProperties"
},
{
"name": "hsweb.dynamic-datasource.min-pool-size",
"type": "java.lang.Integer",
"sourceType": "org.hsweb.web.datasource.dynamic.DynamicDataSourceProperties"
},
{
"name": "hsweb.dynamic-datasource.max-pool-size",
"type": "java.lang.Integer",
"sourceType": "org.hsweb.web.datasource.dynamic.DynamicDataSourceProperties"
},
{
"name": "hsweb.dynamic-datasource.borrow-connection-timeout",
"type": "java.lang.Integer",
"sourceType": "org.hsweb.web.datasource.dynamic.DynamicDataSourceProperties"
},
{
"name": "hsweb.dynamic-datasource.reap-timeout",
"type": "java.lang.Integer",
"sourceType": "org.hsweb.web.datasource.dynamic.DynamicDataSourceProperties"
},
{
"name": "hsweb.dynamic-datasource.max-idle-time",
"type": "java.lang.Integer",
"sourceType": "org.hsweb.web.datasource.dynamic.DynamicDataSourceProperties"
},
{
"name": "hsweb.dynamic-datasource.maintenance-interval",
"type": "java.lang.Integer",
"sourceType": "org.hsweb.web.datasource.dynamic.DynamicDataSourceProperties"
},
{
"name": "hsweb.dynamic-datasource.default-isolation-level",
"type": "java.lang.Integer",
"sourceType": "org.hsweb.web.datasource.dynamic.DynamicDataSourceProperties"
},
{
"name": "hsweb.dynamic-datasource.transaction-timeout",
"type": "java.lang.Integer",
"sourceType": "org.hsweb.web.datasource.dynamic.DynamicDataSourceProperties"
},
{
"name": "hsweb.dynamic-datasource.properties",
"type": "java.util.Properties",
"sourceType": "org.hsweb.web.datasource.dynamic.DynamicDataSourceProperties"
}
],
"hints": [