Commit 48570d40 by qiuweili123

数据源:

1.fix最大连接数等不能初始化问题
2.增加maxwait等属性
parent aebe0d96
...@@ -42,8 +42,9 @@ public class StringUtil extends StringUtils { ...@@ -42,8 +42,9 @@ public class StringUtil extends StringUtils {
/** /**
* camel转换为snake * camel转换为snake
* * 转换为下划线
* @param str * @param str
* @param ch 原字符串中的连接符号
* @return * @return
*/ */
public static String toSnakeCase(String str, char ch) { public static String toSnakeCase(String str, char ch) {
...@@ -58,14 +59,35 @@ public class StringUtil extends StringUtils { ...@@ -58,14 +59,35 @@ public class StringUtil extends StringUtils {
} }
} }
/**
* 连接字符串连接,如order-pay
* @return
*/
public static String toHyphen(String str){
return toSnakeCase(str, CharConstant.UNDERLINE);
}
public static String toHyphen(String str,char ch) {
switch (ch) {
case CharConstant.UNDERLINE:
return CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_HYPHEN, str);
default:
return CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_HYPHEN, str);
}
}
public static void main(String[] args) { public static void main(String[] args) {
String str = "test_jata"; String str = "testJdate_order";
System.out.println(toCamelCase(str)); System.out.println(toCamelCase(str));
System.out.println(toCamelCase("test-jdate", '-')); System.out.println(toCamelCase("test-jdate", '-'));
String str2 = "testJdate"; String str2 = "testJdate_order";
System.out.println(toSnakeCase(str)); System.out.println(toSnakeCase(str2,'-'));
String str3 = "testJdateOrderj";
System.out.println("toHyphen=="+toHyphen(str3,'-'));
System.out.println(toSnakeCase("test-jdate", '-')); System.out.println(toSnakeCase("test-jdate", '-'));
} }
......
...@@ -20,16 +20,16 @@ public interface DataSourceConfig { ...@@ -20,16 +20,16 @@ public interface DataSourceConfig {
* *
* @return the connection timeout in milliseconds * @return the connection timeout in milliseconds
*/ */
long getConnectionTimeout(); Long getConnectionTimeout();
/** /**
* Set the maximum number of milliseconds that a client will wait for a connection from the pool. If this * Set the maximum number of milliseconds that a client will wait for a connection from the pool. If this
* time is exceeded without a connection becoming available, a SQLException will be thrown from * time is exceeded without a connection becoming available, a SQLException will be thrown from
* {@link javax.sql.DataSource#getConnection()}. * {@link javax.sql.DataSource#getConnection()}.
* *
* @param connectionTimeoutMs the connection timeout in milliseconds * @param connectionTimeout the connection timeout in milliseconds
*/ */
void setConnectionTimeout(long connectionTimeoutMs); void setConnectionTimeout(Long connectionTimeout);
/** /**
* This property controls the maximum amount of time (in milliseconds) that a connection is allowed to sit * This property controls the maximum amount of time (in milliseconds) that a connection is allowed to sit
...@@ -39,7 +39,7 @@ public interface DataSourceConfig { ...@@ -39,7 +39,7 @@ public interface DataSourceConfig {
* *
* @return the idle timeout in milliseconds * @return the idle timeout in milliseconds
*/ */
long getIdleTimeout(); Long getIdleTimeout();
/** /**
* This property controls the maximum amount of time (in milliseconds) that a connection is allowed to sit * This property controls the maximum amount of time (in milliseconds) that a connection is allowed to sit
...@@ -49,7 +49,7 @@ public interface DataSourceConfig { ...@@ -49,7 +49,7 @@ public interface DataSourceConfig {
* *
* @param idleTimeoutMs the idle timeout in milliseconds * @param idleTimeoutMs the idle timeout in milliseconds
*/ */
void setIdleTimeout(long idleTimeoutMs); void setIdleTimeout(Long idleTimeoutMs);
/** /**
* This property controls the maximum lifetime of a connection in the pool. When a connection reaches this * This property controls the maximum lifetime of a connection in the pool. When a connection reaches this
...@@ -58,7 +58,7 @@ public interface DataSourceConfig { ...@@ -58,7 +58,7 @@ public interface DataSourceConfig {
* *
* @return the maximum connection lifetime in milliseconds * @return the maximum connection lifetime in milliseconds
*/ */
long getMaxLifetime(); Long getMaxLifetime();
/** /**
* This property controls the maximum lifetime of a connection in the pool. When a connection reaches this * This property controls the maximum lifetime of a connection in the pool. When a connection reaches this
...@@ -67,7 +67,7 @@ public interface DataSourceConfig { ...@@ -67,7 +67,7 @@ public interface DataSourceConfig {
* *
* @param maxLifetimeMs the maximum connection lifetime in milliseconds * @param maxLifetimeMs the maximum connection lifetime in milliseconds
*/ */
void setMaxLifetime(long maxLifetimeMs); void setMaxLifetime(Long maxLifetimeMs);
/** /**
* The property controls the minimum number of idle connections that HikariCP tries to maintain in the pool, * The property controls the minimum number of idle connections that HikariCP tries to maintain in the pool,
...@@ -76,7 +76,7 @@ public interface DataSourceConfig { ...@@ -76,7 +76,7 @@ public interface DataSourceConfig {
* *
* @return the minimum number of connections in the pool * @return the minimum number of connections in the pool
*/ */
int getMinimumIdle(); Integer getMinimumIdle();
/** /**
* The property controls the minimum number of idle connections that HikariCP tries to maintain in the pool, * The property controls the minimum number of idle connections that HikariCP tries to maintain in the pool,
...@@ -85,7 +85,7 @@ public interface DataSourceConfig { ...@@ -85,7 +85,7 @@ public interface DataSourceConfig {
* *
* @param minIdle the minimum number of idle connections in the pool to maintain * @param minIdle the minimum number of idle connections in the pool to maintain
*/ */
void setMinimumIdle(int minIdle); void setMinimumIdle(Integer minIdle);
/** /**
* The property controls the maximum number of connections that HikariCP will keep in the pool, * The property controls the maximum number of connections that HikariCP will keep in the pool,
...@@ -93,7 +93,7 @@ public interface DataSourceConfig { ...@@ -93,7 +93,7 @@ public interface DataSourceConfig {
* *
* @return the maximum number of connections in the pool * @return the maximum number of connections in the pool
*/ */
int getMaximumPoolSize(); Integer getMaximumPoolSize();
/** /**
* The property controls the maximum size that the pool is allowed to reach, including both idle and in-use * The property controls the maximum size that the pool is allowed to reach, including both idle and in-use
...@@ -105,7 +105,7 @@ public interface DataSourceConfig { ...@@ -105,7 +105,7 @@ public interface DataSourceConfig {
* *
* @param maxPoolSize the maximum number of connections in the pool * @param maxPoolSize the maximum number of connections in the pool
*/ */
void setMaximumPoolSize(int maxPoolSize); void setMaximumPoolSize(Integer maxPoolSize);
/** /**
* Set the password used for authentication. Changing this at runtime will apply to new connections only. * Set the password used for authentication. Changing this at runtime will apply to new connections only.
......
...@@ -13,14 +13,15 @@ public class MatrixDataSourceConfig implements DataSourceConfig { ...@@ -13,14 +13,15 @@ public class MatrixDataSourceConfig implements DataSourceConfig {
*/ */
private String url; private String url;
private int minimumIdle = DEFAULT_MIN_IDLE; private Integer minimumIdle = DEFAULT_MIN_IDLE;
private int maxPoolSize = DEFAULT_POOL_SIZE;
private Integer maxPoolSize = DEFAULT_POOL_SIZE;
/** /**
* Unit:Millis * Unit:Millis
*/ */
private long connectionTimeout = CONNECTION_TIMEOUT; private Long connectionTimeout = CONNECTION_TIMEOUT;
private long idleTimeout = IDLE_TIMEOUT; private Long idleTimeout = IDLE_TIMEOUT;
private long maxLifetime = MAX_LIFETIME; private Long maxLifetime = MAX_LIFETIME;
public void setName(String name) { public void setName(String name) {
...@@ -28,52 +29,22 @@ public class MatrixDataSourceConfig implements DataSourceConfig { ...@@ -28,52 +29,22 @@ public class MatrixDataSourceConfig implements DataSourceConfig {
} }
@Override @Override
public long getConnectionTimeout() { public Integer getMinimumIdle() {
return connectionTimeout;
}
@Override
public void setConnectionTimeout(long connectionTimeoutMs) {
this.connectionTimeout = connectionTimeoutMs;
}
@Override
public long getIdleTimeout() {
return idleTimeout;
}
@Override
public void setIdleTimeout(long idleTimeoutMs) {
this.idleTimeout = idleTimeoutMs;
}
@Override
public long getMaxLifetime() {
return maxLifetime;
}
@Override
public void setMaxLifetime(long maxLifetimeMs) {
this.maxLifetime = maxLifetimeMs;
}
@Override
public int getMinimumIdle() {
return this.minimumIdle; return this.minimumIdle;
} }
@Override @Override
public void setMinimumIdle(int minIdle) { public void setMinimumIdle(Integer minIdle) {
this.minimumIdle = minIdle; this.minimumIdle = minIdle;
} }
@Override @Override
public int getMaximumPoolSize() { public Integer getMaximumPoolSize() {
return maxPoolSize; return maxPoolSize;
} }
@Override @Override
public void setMaximumPoolSize(int maxPoolSize) { public void setMaximumPoolSize(Integer maxPoolSize) {
this.maxPoolSize = maxPoolSize; this.maxPoolSize = maxPoolSize;
} }
......
...@@ -21,9 +21,10 @@ public class DruidDataSourceFactory extends AbsDataSourceFactory<DruidDataSource ...@@ -21,9 +21,10 @@ public class DruidDataSourceFactory extends AbsDataSourceFactory<DruidDataSource
dataSource.setPassword(config.getPassword()); dataSource.setPassword(config.getPassword());
dataSource.setMinIdle(config.getMinimumIdle()); dataSource.setMinIdle(config.getMinimumIdle());
dataSource.setMaxActive(config.getMaximumPoolSize()); dataSource.setMaxActive(config.getMaximumPoolSize());
/*屏蔽时间属性,使用druid个性化属性
dataSource.setPhyTimeoutMillis(config.getConnectionTimeout()); dataSource.setPhyTimeoutMillis(config.getConnectionTimeout());
dataSource.setTimeBetweenEvictionRunsMillis(config.getIdleTimeout()); dataSource.setTimeBetweenEvictionRunsMillis(config.getIdleTimeout());
dataSource.setMaxEvictableIdleTimeMillis(config.getMaxLifetime()); dataSource.setMaxEvictableIdleTimeMillis(config.getMaxLifetime());*/
try { try {
dataSource.init(); dataSource.init();
} catch (SQLException e) { } catch (SQLException e) {
......
...@@ -12,6 +12,9 @@ public class MatrixDruidDataSourceProperties extends MatrixDataSourceProperties ...@@ -12,6 +12,9 @@ public class MatrixDruidDataSourceProperties extends MatrixDataSourceProperties
private Integer initialSize; private Integer initialSize;
private Long timeBetweenEvictionRunsMillis= DruidAbstractDataSource.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS; private Long timeBetweenEvictionRunsMillis= DruidAbstractDataSource.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS;
private Long timeBetweenLogStatsMillis; private Long timeBetweenLogStatsMillis;
private Integer minIdle;
private Integer maxIdle;
private Long maxWait;
private Integer statSqlMaxSize; private Integer statSqlMaxSize;
private Long minEvictableIdleTimeMillis; private Long minEvictableIdleTimeMillis;
private Long maxEvictableIdleTimeMillis; private Long maxEvictableIdleTimeMillis;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment