本文整理汇总了Java中org.apache.tomcat.jdbc.pool.PoolProperties类的典型用法代码示例。如果您正苦于以下问题:Java PoolProperties类的具体用法?Java PoolProperties怎么用?Java PoolProperties使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PoolProperties类属于org.apache.tomcat.jdbc.pool包,在下文中一共展示了PoolProperties类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: connectToDb
import org.apache.tomcat.jdbc.pool.PoolProperties; //导入依赖的package包/类
/**
* Connects to specified database.
*/
private void connectToDb() {
this.loadProperties();
PoolProperties p = new PoolProperties();
p.setUrl(this.prs.getProperty("url"));
p.setDriverClassName(SQL_DRIVER);
p.setUsername(this.prs.getProperty("user"));
p.setPassword(this.prs.getProperty("password"));
DataSource datasource = new DataSource();
datasource.setPoolProperties(p);
try {
this.conn = datasource.getConnection();
} catch (SQLException e) {
LOG.error(e.getMessage(), e);
}
}
示例2: connectToDb
import org.apache.tomcat.jdbc.pool.PoolProperties; //导入依赖的package包/类
/**
* Connects to specified database.
*/
private void connectToDb() {
this.loadProperties();
PoolProperties p = new PoolProperties();
DataSource datasource = new DataSource();
p.setUrl(this.prs.getProperty("url"));
p.setDriverClassName(SQL_DRIVER);
p.setUsername(this.prs.getProperty("user"));
p.setPassword(this.prs.getProperty("password"));
datasource.setPoolProperties(p);
try {
this.conn = datasource.getConnection();
} catch (SQLException e) {
LOG.error(e.getMessage(), e);
}
this.createTable();
}
示例3: connectToDb
import org.apache.tomcat.jdbc.pool.PoolProperties; //导入依赖的package包/类
/**
* Connects to specified database.
*/
private void connectToDb() {
this.loadProperties();
PoolProperties p = new PoolProperties();
p.setUrl(this.prs.getProperty("url"));
p.setDriverClassName(SQL_DRIVER);
p.setUsername(this.prs.getProperty("user"));
p.setPassword(this.prs.getProperty("password"));
DataSource datasource = new DataSource();
datasource.setPoolProperties(p);
try {
this.conn = datasource.getConnection();
System.out.println(this.conn);
} catch (SQLException e) {
LOG.error(e.getMessage(), e);
}
this.createTable();
}
示例4: ping
import org.apache.tomcat.jdbc.pool.PoolProperties; //导入依赖的package包/类
/**
* 데이터베이스 접속 여부 확인
*
* @param conSupplier
* 커넥션정보를 제공
* @param onSuccess
* 접속성공시 처리
* @param exHandler
* 에러발생시 처리
* @param timeoutSec
* 핑테스트 대기시간 (Secound)
* @return 접속 성공여부
*/
public static void ping(Supplier<PoolProperties> conSupplier, Consumer<Boolean> onSuccess, Consumer<Throwable> exHandler,
int timeoutSec, boolean async) {
// boolean result = false;
PoolProperties prop = conSupplier.get();
String driverClassName = prop.getDriverClassName();
String url = prop.getUrl();
String userName = prop.getUsername();
String password = prop.getPassword();
if (async) {
ExecutorDemons.getGargoyleSystemExecutorSerivce().execute(() -> {
ping(onSuccess, exHandler, timeoutSec, driverClassName, url, userName, password);
});
} else {
ping(onSuccess, exHandler, timeoutSec, driverClassName, url, userName, password);
}
}
示例5: getPoolProperties
import org.apache.tomcat.jdbc.pool.PoolProperties; //导入依赖的package包/类
private PoolProperties getPoolProperties() {
Map<String, Object> bufMap = new HashMap<>();
tbDatabase.getItems().forEach(item -> {
Object key = item.get("key");
Object value = item.get("value");
if (key == null)
return;
bufMap.put(key.toString(), value.toString());
});
String driver = bufMap.get(ResourceLoader.BASE_KEY_JDBC_DRIVER).toString();
String url = bufMap.get(ResourceLoader.BASE_KEY_JDBC_URL).toString();
String username = bufMap.get(ResourceLoader.BASE_KEY_JDBC_ID).toString();
String password = bufMap.get(ResourceLoader.BASE_KEY_JDBC_PASS).toString();
password = decryp(password);
PoolProperties poolProperties = new PoolProperties();
poolProperties.setDriverClassName(driver);
poolProperties.setUrl(url);
poolProperties.setUsername(username);
poolProperties.setPassword(password);
return poolProperties;
}
示例6: getPoolProperties
import org.apache.tomcat.jdbc.pool.PoolProperties; //导入依赖的package包/类
private PoolProperties getPoolProperties() {
Map<String, Object> bufMap = new HashMap<>();
tbDatabase.getItems().forEach(item -> {
Object key = item.get("key");
Object value = item.get("value");
if (key == null)
return;
bufMap.put(key.toString(), value.toString());
});
String driver = bufMap.get(ResourceLoader.CUSTOM_DAOWIZARD_KEY_JDBC_DRIVER).toString();
String url = bufMap.get(ResourceLoader.CUSTOM_DAOWIZARD_KEY_JDBC_URL).toString();
String username = bufMap.get(ResourceLoader.CUSTOM_DAOWIZARD_KEY_JDBC_ID).toString();
String password = bufMap.get(ResourceLoader.CUSTOM_DAOWIZARD_KEY_JDBC_PASS).toString();
password = decryp(password);
PoolProperties poolProperties = new PoolProperties();
poolProperties.setDriverClassName(driver);
poolProperties.setUrl(url);
poolProperties.setUsername(username);
poolProperties.setPassword(password);
return poolProperties;
}
示例7: init
import org.apache.tomcat.jdbc.pool.PoolProperties; //导入依赖的package包/类
public void init(ServerConfiguration config) throws IOException {
databaseURL = Objects.requireNonNull(config.getDatabaseURL());
LOG.info("Initializing database {}", databaseURL);
PoolProperties props = new PoolProperties();
props.setUrl(config.getDatabaseURL());
props.setDriverClassName(config.getDatabaseDriver());
if (config.getDatabaseUser().isPresent()) {
props.setUsername(config.getDatabaseUser().get());
if (config.getDatabasePass().isPresent()) {
props.setPassword(config.getDatabasePass().get());
}
}
init(props, true);
if (getUser(config.getAccessKey()).isPresent()) {
LOG.info("admin user is {}", config.getAccessKey());
} else {
LOG.info("No user found: creating admin user {}", config.getAccessKey());
addUser(config.getUser());
}
}
示例8: setUpClass
import org.apache.tomcat.jdbc.pool.PoolProperties; //导入依赖的package包/类
@BeforeClass
public static void setUpClass() throws IOException {
// Get the relative path context
final String servletContextPath = AllTests.getServletContextPath();
final String sep = File.separator;
dbConfigPath = servletContextPath + "/web/WEB-INF/dbconfig.properties.dev".replace("/", sep);
// Load the db config properties
Properties prop = new Properties();
try (InputStream input = new FileInputStream(dbConfigPath)) {
prop.load(input);
}
PoolProperties p = new PoolProperties();
p.setDriverClassName( prop.getProperty("driver") );
p.setUsername( prop.getProperty("user") );
p.setPassword( prop.getProperty("password"));
p.setUrl( prop.getProperty("url") );
p.setValidationQuery( "SELECT 1;" );
ds = new DataSource(p);
}
示例9: SingleDataSource
import org.apache.tomcat.jdbc.pool.PoolProperties; //导入依赖的package包/类
public SingleDataSource(String name, DataSourceConfigure dataSourceConfigure) throws SQLException {
if (dataSourceConfigure == null)
throw new SQLException("Can not find any connection configure for " + name);
try {
this.name = name;
this.dataSourceConfigure = dataSourceConfigure;
PoolProperties p = poolPropertiesHelper.convert(dataSourceConfigure);
PoolPropertiesHolder.getInstance().setPoolProperties(p);
org.apache.tomcat.jdbc.pool.DataSource dataSource = new org.apache.tomcat.jdbc.pool.DataSource(p);
this.dataSource = dataSource;
dataSource.createPool();
logger.info("Datasource[name=" + name + ", Driver=" + p.getDriverClassName() + "] created.");
} catch (Throwable e) {
logger.error(String.format("Error creating pool for data source %s", name), e);
// throw e;
}
}
示例10: setUpDB
import org.apache.tomcat.jdbc.pool.PoolProperties; //导入依赖的package包/类
@BeforeClass
@Parameters("dbType")
public void setUpDB(String dbTypeStr) throws Exception {
DBTypes dbType = DBTypes.valueOf(dbTypeStr);
TestDBConfiguration dbConfig = getTestDBConfiguration(dbType);
switch (dbType) {
case H2:
PoolProperties properties = new PoolProperties();
properties.setUrl(dbConfig.getConnectionUrl());
properties.setDriverClassName(dbConfig.getDriverClass());
properties.setUsername(dbConfig.getUserName());
properties.setPassword(dbConfig.getPwd());
dataSource = new org.apache.tomcat.jdbc.pool.DataSource(properties);
this.initSQLScript();
DeviceManagementDAOFactory.init(dataSource);
default:
}
}
示例11: setupDatabase
import org.apache.tomcat.jdbc.pool.PoolProperties; //导入依赖的package包/类
@BeforeClass(alwaysRun = true)
@Parameters("dbType")
public void setupDatabase(String dbTypeName) throws Exception {
DBTypes type = DBTypes.valueOf(dbTypeName);
TestDBConfiguration config = getTestDBConfiguration(type);
switch (type) {
case H2:
PoolProperties properties = new PoolProperties();
properties.setUrl(config.getConnectionUrl());
properties.setDriverClassName(config.getDriverClass());
properties.setUsername(config.getUserName());
properties.setPassword(config.getPwd());
dataSource = new org.apache.tomcat.jdbc.pool.DataSource(properties);
this.initSQLScript();
default:
}
}
示例12: TomcatSchema
import org.apache.tomcat.jdbc.pool.PoolProperties; //导入依赖的package包/类
public TomcatSchema(@Nonnull Config config) {
checkNotNull(config);
log.debug("{} sql.url: {}", config.getName(), config.getString("sql.url"));
PoolProperties poolProps = new PoolProperties();
poolProps.setUrl(config.getString("sql.url"));
poolProps.setUsername(config.getString("sql.login"));
poolProps.setPassword(config.getString("sql.password"));
poolProps.setDriverClassName(config.getString("sql.driver"));
poolProps.setMinIdle(config.getInt("sql.pool.minIdle", 1));
poolProps.setMaxIdle(config.getInt("sql.pool.maxIdle", 3));
poolProps.setMaxActive(config.getInt("sql.pool.maxActive", 5));
poolProps.setInitialSize(poolProps.getMinIdle());
poolProps.setValidationQuery("SELECT 1");
poolProps.setValidationQueryTimeout((int) config.getTime("sql.pool.validationQueryTimeout", "5s"));
poolProps.setTestOnBorrow(config.getBoolean("sql.pool.testOnBorrow", true));
poolProps.setDefaultReadOnly(config.getBoolean("sql.pool.defaultReadOnly", true));
dataSource = new DataSource(poolProps);
streaming = config.getBoolean("sql.streaming", false);
}
示例13: initDataSource
import org.apache.tomcat.jdbc.pool.PoolProperties; //导入依赖的package包/类
private void initDataSource(String dataSourceFile) {
Properties dataSourceProps = getPropertiesFromClasspath(dataSourceFile);
PoolProperties p = new PoolProperties();
p.setUrl(dataSourceProps.getProperty("url"));
p.setDriverClassName(dataSourceProps.getProperty("driverClassName"));
p.setUsername(dataSourceProps.getProperty("username"));
p.setPassword(dataSourceProps.getProperty("password"));
p.setMaxIdle(Integer.valueOf(dataSourceProps.getProperty("maxIdle")));
p.setMinIdle(Integer.valueOf(dataSourceProps.getProperty("minIdle")));
p.setInitialSize(Integer.valueOf(dataSourceProps.getProperty("initialSize")));
p.setMaxWait(Integer.valueOf(dataSourceProps.getProperty("maxWait")));
p.setMaxActive(Integer.valueOf(dataSourceProps.getProperty("maxActive")));
p.setTestOnBorrow(Boolean.valueOf(dataSourceProps.getProperty("testOnBorrow")));
p.setTestOnReturn(Boolean.valueOf(dataSourceProps.getProperty("testOnReturn")));
p.setTestWhileIdle(Boolean.valueOf(dataSourceProps.getProperty("testWhileIdle")));
p.setValidationQuery(dataSourceProps.getProperty("validationQuery"));
p.setValidationQueryTimeout(Integer.valueOf(dataSourceProps.getProperty("validationQueryTimeout")));
p.setTimeBetweenEvictionRunsMillis(Integer.valueOf(dataSourceProps.getProperty("timeBetweenEvictionRunsMillis")));
p.setMinEvictableIdleTimeMillis(Integer.valueOf(dataSourceProps.getProperty("minEvictableIdleTimeMillis")));
p.setRemoveAbandoned(Boolean.valueOf(dataSourceProps.getProperty("removeAbandoned")));
p.setRemoveAbandonedTimeout(Integer.valueOf(dataSourceProps.getProperty("removeAbandonedTimeout")));
p.setValidationInterval(Integer.valueOf(dataSourceProps.getProperty("validationInterval")));
p.setLogAbandoned(Boolean.valueOf(dataSourceProps.getProperty("logAbandoned")));
p.setFairQueue(Boolean.valueOf(dataSourceProps.getProperty("fairQueue")));
dataSource.setPoolProperties(p);
}
示例14: dataSource
import org.apache.tomcat.jdbc.pool.PoolProperties; //导入依赖的package包/类
@Primary
@Bean
public DataSource dataSource() {
DbConfiguration dbConfiguration = configurationService.getDbConfiguration();
PoolProperties poolProperties = new PoolProperties();
poolProperties.setDriverClassName(dbConfiguration.getDriverClassName());
poolProperties.setUrl(dbConfiguration.getUrl());
poolProperties.setUsername(dbConfiguration.getUser());
poolProperties.setPassword(dbConfiguration.getPassword());
poolProperties.setMaxActive(dbConfiguration.getMaxActive());
poolProperties.setMaxIdle(dbConfiguration.getMaxIdle());
poolProperties.setMinIdle(dbConfiguration.getMinIdle());
poolProperties.setMaxWait(dbConfiguration.getMaxWait());
poolProperties.setValidationQuery(dbConfiguration.getValidationQuery());
poolProperties.setTestOnBorrow(dbConfiguration.getTestOnBorrow());
poolProperties.setTestWhileIdle(dbConfiguration.getTestWhileIdle());
return new org.apache.tomcat.jdbc.pool.DataSource(poolProperties);
}
示例15: dataSource
import org.apache.tomcat.jdbc.pool.PoolProperties; //导入依赖的package包/类
@Bean
public DataSource dataSource() {
logger.info("Create DataSource bean. JDBC URL " + env.getProperty("database.url") + ", for username: " + env.getProperty("database.user"));
try {
PoolProperties poolProperties = new PoolProperties();
poolProperties.setUsername(env.getProperty("database.user"));
poolProperties.setPassword(env.getProperty("database.password"));
poolProperties.setUrl(env.getProperty("database.url"));
poolProperties.setDriverClassName("com.mysql.jdbc.Driver");
poolProperties.setMaxActive(50);
poolProperties.setMaxIdle(50);
poolProperties.setInitialSize(1);
return new DataSource(poolProperties);
} catch (Exception ex) {
logger.error(ex.getMessage(), ex);
throw new RuntimeException(ex);
}
}