Commit 140131a7 by qiuweili123

数据源开发

parent 58a5d968
package com.secoo.mall.datasource.util;
import lombok.extern.slf4j.Slf4j;
import java.util.Properties;
@Slf4j
public class SysUtil {
private static Properties properties = new Properties();
public static void setProperty(String key, String value) {
/* try {
PropertyUtils.setProperty(HashMap.class, key, value);
} catch (Exception e) {
log.error("set property", e);
}*/
properties.setProperty(key, value);
}
public static String getProperty(String key) {
/* try {
Object property = PropertyUtils.getProperty(HashMap.class, key);
return (T) PropertyUtils.getProperty(HashMap.class, key);
} catch (Exception e) {
log.error("set property", e);
}*/
return properties.getProperty(key);
}
}
package com.secoo.mall.mybatis.config;
public interface DataSourceConfig {
/**
* Get 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
* {@link javax.sql.DataSource#getConnection()}.
*
* @return the connection timeout in milliseconds
*/
long getConnectionTimeout();
/**
* 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
* {@link javax.sql.DataSource#getConnection()}.
*
* @param connectionTimeoutMs the connection timeout in milliseconds
*/
void setConnectionTimeout(long connectionTimeoutMs);
/**
* This property controls the maximum amount of time (in milliseconds) that a connection is allowed to sit
* idle in the pool. Whether a connection is retired as idle or not is subject to a maximum variation of +30
* seconds, and average variation of +15 seconds. A connection will never be retired as idle before this timeout.
* A value of 0 means that idle connections are never removed from the pool.
*
* @return the idle timeout in milliseconds
*/
long getIdleTimeout();
/**
* This property controls the maximum amount of time (in milliseconds) that a connection is allowed to sit
* idle in the pool. Whether a connection is retired as idle or not is subject to a maximum variation of +30
* seconds, and average variation of +15 seconds. A connection will never be retired as idle before this timeout.
* A value of 0 means that idle connections are never removed from the pool.
*
* @param idleTimeoutMs the idle timeout in milliseconds
*/
void setIdleTimeout(long idleTimeoutMs);
/**
* This property controls the maximum lifetime of a connection in the pool. When a connection reaches this
* timeout, even if recently used, it will be retired from the pool. An in-use connection will never be
* retired, only when it is idle will it be removed.
*
* @return the maximum connection lifetime in milliseconds
*/
long getMaxLifetime();
/**
* This property controls the maximum lifetime of a connection in the pool. When a connection reaches this
* timeout, even if recently used, it will be retired from the pool. An in-use connection will never be
* retired, only when it is idle will it be removed.
*
* @param maxLifetimeMs the maximum connection lifetime in milliseconds
*/
void setMaxLifetime(long maxLifetimeMs);
/**
* The property controls the minimum number of idle connections that HikariCP tries to maintain in the pool,
* including both idle and in-use connections. If the idle connections dip below this value, HikariCP will
* make a best effort to restore them quickly and efficiently.
*
* @return the minimum number of connections in the pool
*/
int getMinimumIdle();
/**
* The property controls the minimum number of idle connections that HikariCP tries to maintain in the pool,
* including both idle and in-use connections. If the idle connections dip below this value, HikariCP will
* make a best effort to restore them quickly and efficiently.
*
* @param minIdle the minimum number of idle connections in the pool to maintain
*/
void setMinimumIdle(int minIdle);
/**
* The property controls the maximum number of connections that HikariCP will keep in the pool,
* including both idle and in-use connections.
*
* @return the maximum number of connections in the pool
*/
int getMaximumPoolSize();
/**
* The property controls the maximum size that the pool is allowed to reach, including both idle and in-use
* connections. Basically this value will determine the maximum number of actual connections to the database
* backend.
* <p>
* When the pool reaches this size, and no idle connections are available, calls to getConnection() will
* block for up to connectionTimeout milliseconds before timing out.
*
* @param maxPoolSize the maximum number of connections in the pool
*/
void setMaximumPoolSize(int maxPoolSize);
/**
* Set the password used for authentication. Changing this at runtime will apply to new connections only.
* Altering this at runtime only works for DataSource-based connections, not Driver-class or JDBC URL-based
* connections.
*
* @param password the database password
*/
void setPassword(String password);
/**
* Set the username used for authentication. Changing this at runtime will apply to new connections only.
* Altering this at runtime only works for DataSource-based connections, not Driver-class or JDBC URL-based
* connections.
*
* @param username the database username
*/
void setUsername(String username);
/**
* The name of the data source.
*
* @return the name of the connection pool
*/
String getName();
}
package com.secoo.mall.mybatis.config;
import com.secoo.mall.mybatis.constants.DataSourceType;
import lombok.Data;
@Data
public class MatrixDataSourceConfig implements DataSourceConfig {
public static final String PREFIX = "spring.datasource.matrix";
/**
* SourceType DRUID or HIKARI.
* Default value HIKARI.
*/
private DataSourceType type;
private String name;
private String username;
private String password;
/**
* Connection url
*/
private String url;
private int minimumIdle;
private int maxPoolSize;
private long connectionTimeout;
private long idleTimeout;
private long maxLifetime;
@Override
public long getConnectionTimeout() {
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;
}
@Override
public void setMinimumIdle(int minIdle) {
this.minimumIdle = minIdle;
}
@Override
public int getMaximumPoolSize() {
return maxPoolSize;
}
@Override
public void setMaximumPoolSize(int maxPoolSize) {
this.maxPoolSize = maxPoolSize;
}
}
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