本文整理匯總了Java中org.apache.tomcat.jdbc.pool.DataSource類的典型用法代碼示例。如果您正苦於以下問題:Java DataSource類的具體用法?Java DataSource怎麽用?Java DataSource使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
DataSource類屬於org.apache.tomcat.jdbc.pool包,在下文中一共展示了DataSource類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: test2PoolCleaners
import org.apache.tomcat.jdbc.pool.DataSource; //導入依賴的package包/類
@Test
public void test2PoolCleaners() throws Exception {
datasource.getPoolProperties().setTimeBetweenEvictionRunsMillis(2000);
datasource.getPoolProperties().setTestWhileIdle(true);
DataSource ds2 = new DataSource(datasource.getPoolProperties());
Assert.assertEquals("Pool cleaner should not be started yet.",0,ConnectionPool.getPoolCleaners().size() );
Assert.assertNull("Pool timer should be null", ConnectionPool.getPoolTimer());
Assert.assertEquals("Pool cleaner threads should not be present.",0, countPoolCleanerThreads());
datasource.getConnection().close();
ds2.getConnection().close();
Assert.assertEquals("Pool cleaner should have 2 cleaner.",2,ConnectionPool.getPoolCleaners().size() );
Assert.assertNotNull("Pool timer should not be null", ConnectionPool.getPoolTimer());
Assert.assertEquals("Pool cleaner threads should be 1.",1, countPoolCleanerThreads());
datasource.close();
Assert.assertEquals("Pool cleaner should have 1 cleaner.",1,ConnectionPool.getPoolCleaners().size() );
Assert.assertNotNull("Pool timer should not be null", ConnectionPool.getPoolTimer());
ds2.close();
Assert.assertEquals("Pool shutdown, no cleaners should be present.",0,ConnectionPool.getPoolCleaners().size() );
Assert.assertNull("Pool timer should be null after shutdown", ConnectionPool.getPoolTimer());
Assert.assertEquals("Pool cleaner threads should not be present after close.",0, countPoolCleanerThreads());
}
示例2: initSimplePoolProperties
import org.apache.tomcat.jdbc.pool.DataSource; //導入依賴的package包/類
private void initSimplePoolProperties() {
PoolConfiguration p = new DefaultProperties();
ds = new org.apache.tomcat.jdbc.pool.DataSource();
ds.setPoolProperties(p);
ds.getPoolProperties().setDriverClassName(Driver.class.getName());
ds.getPoolProperties().setUrl(Driver.url);
ds.getPoolProperties().setFairQueue(true);
ds.getPoolProperties().setJmxEnabled(false);
ds.getPoolProperties().setTestWhileIdle(true);
ds.getPoolProperties().setTestOnBorrow(false);
ds.getPoolProperties().setTestOnReturn(false);
ds.getPoolProperties().setValidationInterval(30000);
ds.getPoolProperties().setTimeBetweenEvictionRunsMillis(30000);
ds.getPoolProperties().setInitialSize(100);
ds.getPoolProperties().setMaxActive(100);
ds.getPoolProperties().setMinIdle(0);
ds.getPoolProperties().setMaxIdle(0);
ds.getPoolProperties().setMaxWait(10000);
ds.getPoolProperties().setRemoveAbandonedTimeout(10);
ds.getPoolProperties().setMinEvictableIdleTimeMillis(10000);
ds.getPoolProperties().setLogAbandoned(false);
ds.getPoolProperties().setRemoveAbandoned(false);
ds.getPoolProperties().setUseLock(true);
}
示例3: entityManagerFactory
import org.apache.tomcat.jdbc.pool.DataSource; //導入依賴的package包/類
@Bean
public EntityManagerFactory entityManagerFactory(DataSource dataSource) {
final Database database = Database.valueOf(vendor.toUpperCase());
/*
final HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
vendorAdapter.setShowSql(showSql);
vendorAdapter.setGenerateDdl(showDdl);
vendorAdapter.setDatabase(database);
*/
final LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
factory.setPersistenceUnitName("CCRI_PU");
// factory.setJpaVendorAdapter(vendorAdapter);
factory.setPackagesToScan("uk.nhs.careconnect.ri.entity");
factory.setDataSource(dataSource);
factory.setPersistenceProvider(new HibernatePersistenceProvider());
factory.setJpaProperties(jpaProperties());
factory.afterPropertiesSet();
return factory.getObject();
}
示例4: connectToDb
import org.apache.tomcat.jdbc.pool.DataSource; //導入依賴的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);
}
}
示例5: connectToDb
import org.apache.tomcat.jdbc.pool.DataSource; //導入依賴的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();
}
示例6: connectToDb
import org.apache.tomcat.jdbc.pool.DataSource; //導入依賴的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();
}
示例7: selectScala
import org.apache.tomcat.jdbc.pool.DataSource; //導入依賴的package包/類
/**
* 첫번쨰로우의 첫번쨰 컬럼값 리턴. <br/>
* 값이 없는경우 NULL <br/>
*
* @작성자 : KYJ
* @작성일 : 2017. 11. 27.
* @param dataSource
* @param sql
* @param paramMap
* @return
*/
public static String selectScala(DataSource dataSource, final String sql, MapSqlParameterSource paramMap) {
String r = null;
try {
noticeQuery(sql);
NamedParameterJdbcTemplate jdbcTemplate = new NamedParameterJdbcTemplate(dataSource);
ResultSetExtractor<String> extr = new ResultSetExtractor<String>() {
@Override
public String extractData(ResultSet rs) throws SQLException, DataAccessException {
if (rs.next()) {
return rs.getString(1);
}
return null;
}
};
r = jdbcTemplate.query(sql, paramMap, extr);
} catch (Exception e) {
throw e;
} finally {
cleanDataSource();
}
return r;
}
示例8: execute
import org.apache.tomcat.jdbc.pool.DataSource; //導入依賴的package包/類
private List<Map<String, Object>> execute(String sql, MapSqlParameterSource mapSqlParameterSource,
RowMapper<Map<String, Object>> rowMapper) throws Exception {
/* Custom DataSource 정보가 존재한다면 Custom DataSource를 활용한다. */
ResourceLoader instance = ResourceLoader.getInstance();
String url = instance.get(ResourceLoader.CUSTOM_DAOWIZARD_KEY_JDBC_URL, null);
if (ValueUtil.isNotEmpty(url)) {
String driver = instance.get(ResourceLoader.CUSTOM_DAOWIZARD_KEY_JDBC_DRIVER, "");
String id = instance.get(ResourceLoader.CUSTOM_DAOWIZARD_KEY_JDBC_ID, "");
String pass = instance.get(ResourceLoader.CUSTOM_DAOWIZARD_KEY_JDBC_PASS, "");
if (ValueUtil.isNotEmpty(pass))
pass = DbUtil.decryp(pass);
DataSource dataSource = DbUtil.getDataSource(driver, url, id, pass);
return DbUtil.selectLimit(dataSource, sql, mapSqlParameterSource, rowMapper, 100);
}
return DbUtil.selectLimit(sql, mapSqlParameterSource, rowMapper, 100);
}
示例9: createDataSourceBean
import org.apache.tomcat.jdbc.pool.DataSource; //導入依賴的package包/類
@Bean
public DataSource createDataSourceBean(){
DataSource ds = new org.apache.tomcat.jdbc.pool.DataSource();
ds.setDriverClassName(this.dataSourceProperties.getDriverClassName());
ds.setMaxActive(this.dataSourceProperties.getMaxActive());
ds.setMaxIdle(this.dataSourceProperties.getMaxIdle());
ds.setMinIdle(this.dataSourceProperties.getMinIdle());
ds.setInitialSize(this.dataSourceProperties.getInitialSize());
ds.setValidationQuery(this.dataSourceProperties.getValidationQuery());
ds.setTestOnBorrow(this.dataSourceProperties.getTestOnBorrow());
ds.setTestWhileIdle(this.dataSourceProperties.getTestWhileIdle());
ds.setTimeBetweenEvictionRunsMillis(this.dataSourceProperties.getTimeBetweenEvictionRunsMillis());
ds.setMinEvictableIdleTimeMillis(this.dataSourceProperties.getMinEvictableIdleTimeMillis());
ds.setUrl(this.getUrl());
ds.setUsername(this.getUsername());
ds.setPassword(this.getPassword());
return ds;
}
示例10: setupDataSource
import org.apache.tomcat.jdbc.pool.DataSource; //導入依賴的package包/類
private static void setupDataSource(Isolation isolation) {
ds = new DataSource();
try {
ds.setPoolProperties(getPoolProperties()); //set earlier to avoid overriding the isolation setting
ds.setMaxActive(100);
if (isolation == Isolation.NONE) {
ds.setDefaultTransactionIsolation(Connection.TRANSACTION_NONE);
} else if (isolation == Isolation.READ_COMMITTED) {
ds.setDefaultTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
ds.setDefaultAutoCommit(false);
} else {
ds.setDefaultTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ);
ds.setDefaultAutoCommit(false);
}
dsSet = true;
Log.getLogWriter().info("tomcat data source url is set as " + ds.getUrl());
Log.getLogWriter().info("tomcat data source DefaultTransactionIsolation is set to " + ds.getDefaultTransactionIsolation());
Log.getLogWriter().info("tomcat data source DefaultAutoCommit is set to " + ds.getDefaultAutoCommit());
} catch (Exception e) {
throw new TestException("could not set data source" + TestHelper.getStackTrace(e));
}
}
示例11: setUpClass
import org.apache.tomcat.jdbc.pool.DataSource; //導入依賴的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);
}
示例12: NestWipeDB
import org.apache.tomcat.jdbc.pool.DataSource; //導入依賴的package包/類
/**
* For wiping the test database before running tests, so we know they are atomic
* @throws SQLException
* @throws IOException
*/
protected static void NestWipeDB() throws SQLException, IOException {
// Wipe the DB so we know the tests are atomic.
// First read the repeatable SQL DB schema into memory.
String dbSchema = null;
try (Scanner scanner = new Scanner(new File(DBCREATESCRIPT_PATH));) {
dbSchema = scanner.useDelimiter("\\A").next();
}
if (dbSchema == null) {
throw new IOException("Unable to load repeatable database schema");
}
// Next wipe the db
DataSource dsTest = Common.getNestDS(DBCONFIGPATH_TEST);
try (
Connection conn = dsTest.getConnection();
Statement st = conn.createStatement();
) {
boolean hasResults = st.execute(dbSchema);
}
dsTest.close();
}
示例13: dbDeleteEntities
import org.apache.tomcat.jdbc.pool.DataSource; //導入依賴的package包/類
/**
* Remove the created entities directly via the db so we don't worry about bugs in DELETE.
* @param entitiesList These should be names of tables in the database!
* @param ids This should have keys for each value in entitiesList!
* @return
* @throws SQLException
* @throws IOException
*/
protected static boolean dbDeleteEntities(List<String> entitiesList, Map<String,Long> ids) throws SQLException, IOException {
DataSource dsTest = Common.getNestDS(DBCONFIGPATH_TEST);
for(int i = entitiesList.size()-1; i >= 0; i--) {
// Get the entities to delete
final String tablename = entitiesList.get(i);
Long id = ids.get(tablename);
// It's late, okay!?
final String columnname = (!tablename.equals("users"))? tablename+"_id" : "user_id";
try (
Connection conn = dsTest.getConnection();
Statement st = conn.createStatement();
) {
boolean hasResults = st.execute("DELETE FROM "+tablename+" WHERE "+columnname+" = "+id+";");
}
}
dsTest.close();
return true;
}
示例14: serialize
import org.apache.tomcat.jdbc.pool.DataSource; //導入依賴的package包/類
@Override
public void serialize(DataSource value, JsonGenerator jgen,
SerializerProvider provider) throws IOException, JsonProcessingException {
jgen.writeStartObject();
for (PropertyDescriptor property : BeanUtils
.getPropertyDescriptors(DataSource.class)) {
Method reader = property.getReadMethod();
if (reader != null && property.getWriteMethod() != null
&& this.conversionService.canConvert(String.class,
property.getPropertyType())) {
jgen.writeObjectField(property.getName(),
ReflectionUtils.invokeMethod(reader, value));
}
}
jgen.writeEndObject();
}
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:17,代碼來源:DataSourceJsonSerializationTests.java
示例15: getInfo
import org.apache.tomcat.jdbc.pool.DataSource; //導入依賴的package包/類
@Override
public DataSourceInfo getInfo(Object resource) throws Exception {
DataSourceInfo dataSourceInfo = null;
if (canMap(resource)) {
DataSource source = (DataSource) resource;
dataSourceInfo = new DataSourceInfo();
dataSourceInfo.setBusyConnections(source.getNumActive());
dataSourceInfo.setEstablishedConnections(source.getNumIdle() + source.getNumActive());
dataSourceInfo.setMaxConnections(source.getMaxActive());
dataSourceInfo.setJdbcUrl(source.getUrl());
dataSourceInfo.setUsername(source.getUsername());
dataSourceInfo.setResettable(false);
dataSourceInfo.setType("tomcat-jdbc");
}
return dataSourceInfo;
}