当前位置: 首页>>代码示例>>Java>>正文


Java DataSource类代码示例

本文整理汇总了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());
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:27,代码来源:PoolCleanerTest.java

示例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);
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:26,代码来源:TestSizePreservation.java

示例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();
}
 
开发者ID:nhsconnect,项目名称:careconnect-reference-implementation,代码行数:23,代码来源:DataSourceConfig.java

示例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);
    }
}
 
开发者ID:dionisius1976,项目名称:java-a-to-z,代码行数:19,代码来源:DbManager.java

示例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();
}
 
开发者ID:dionisius1976,项目名称:java-a-to-z,代码行数:21,代码来源:DbManager.java

示例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();
}
 
开发者ID:dionisius1976,项目名称:java-a-to-z,代码行数:21,代码来源:DbManager.java

示例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;
}
 
开发者ID:callakrsos,项目名称:Gargoyle,代码行数:37,代码来源:DbUtil.java

示例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);
}
 
开发者ID:callakrsos,项目名称:Gargoyle,代码行数:22,代码来源:SimpleSQLResultView.java

示例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;
}
 
开发者ID:syukai,项目名称:SpringbootMultiDatasourceSample,代码行数:22,代码来源:AbstractDatasourceProperties.java

示例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));
  }
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:27,代码来源:PooledConnectionTomcat.java

示例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);
}
 
开发者ID:FrancisG-Massey,项目名称:Capstone2016,代码行数:23,代码来源:DBInterfaceTests.java

示例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();
}
 
开发者ID:FrancisG-Massey,项目名称:Capstone2016,代码行数:28,代码来源:NestHttpTests.java

示例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;
}
 
开发者ID:FrancisG-Massey,项目名称:Capstone2016,代码行数:30,代码来源:NestHttpTests.java

示例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;
}
 
开发者ID:psi-probe,项目名称:psi-probe,代码行数:17,代码来源:TomcatJdbcPoolDatasourceAccessor.java


注:本文中的org.apache.tomcat.jdbc.pool.DataSource类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。