本文整理汇总了Java中javax.sql.CommonDataSource类的典型用法代码示例。如果您正苦于以下问题:Java CommonDataSource类的具体用法?Java CommonDataSource怎么用?Java CommonDataSource使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CommonDataSource类属于javax.sql包,在下文中一共展示了CommonDataSource类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: resolveDataSourceName
import javax.sql.CommonDataSource; //导入依赖的package包/类
public String resolveDataSourceName(CommonDataSource dataSource) {
if (dataSources == null) {
this.dataSources = applicationContext.getBeansOfType(DataSource.class);
}
return dataSources.entrySet()
.stream()
.filter(entry -> {
DataSource candidate = entry.getValue();
if (candidate instanceof DecoratedDataSource) {
return matchesDataSource((DecoratedDataSource) candidate, dataSource);
}
return candidate == dataSource;
})
.findFirst()
.map(Entry::getKey)
.orElse("dataSource");
}
示例2: isWrapperFor
import javax.sql.CommonDataSource; //导入依赖的package包/类
public boolean isWrapperFor(Class<?> iface) throws SQLException {
if (iface.isInstance(this)) {
return true;
}
CommonDataSource cds = getUnwrappedDataSource();
if (iface.isInstance(cds)) {
return true;
}
if (cds instanceof DataSource) {
DataSource ds = (DataSource) cds;
if (ds.isWrapperFor(iface)) {
return true;
}
}
return false;
}
示例3: unwrap
import javax.sql.CommonDataSource; //导入依赖的package包/类
public <T> T unwrap(Class<T> iface) throws SQLException {
if (iface.isInstance(this)) {
return iface.cast(this);
}
CommonDataSource cds = getUnwrappedDataSource();
if (iface.isInstance(cds)) {
return iface.cast(cds);
}
if (cds instanceof DataSource) {
DataSource ds = (DataSource) cds;
if (ds.isWrapperFor(iface)) {
return ds.unwrap(iface);
}
}
throw new SQLException("Not a wrapper for " + iface.getName());
}
示例4: setup
import javax.sql.CommonDataSource; //导入依赖的package包/类
@Before
public void setup() throws SQLException {
Platform platform = new HSQL();
CommonDataSource dataSource = DatabaseType.getDataSource(platform);
EntityModel model = Models.MODEL2;
Configuration configuration = new ConfigurationBuilder(dataSource, model)
.useDefaultLogging()
.setEntityCache(new EmptyEntityCache())
.setWriteExecutor(Executors.newSingleThreadExecutor())
.build();
SchemaModifier tables = new SchemaModifier(configuration);
tables.createTables(TableCreationMode.DROP_CREATE);
data = new EntityDataStore<>(configuration);
}
示例5: setup
import javax.sql.CommonDataSource; //导入依赖的package包/类
@Before
public void setup() throws SQLException {
CommonDataSource dataSource = DatabaseType.getDataSource(new H2());
EntityModel model = Models.JPA;
CachingProvider provider = Caching.getCachingProvider();
CacheManager cacheManager = provider.getCacheManager();
Configuration configuration = new ConfigurationBuilder(dataSource, model)
.useDefaultLogging()
.setEntityCache(new EntityCacheBuilder(model)
.useReferenceCache(true)
.useSerializableCache(true)
.useCacheManager(cacheManager)
.build())
.build();
data = new EntityDataStore<>(configuration);
SchemaModifier tables = new SchemaModifier(configuration);
tables.dropTables();
TableCreationMode mode = TableCreationMode.CREATE;
System.out.println(tables.createTablesString(mode));
tables.createTables(mode);
}
示例6: setup
import javax.sql.CommonDataSource; //导入依赖的package包/类
@Before
public void setup() throws SQLException {
CommonDataSource dataSource = DatabaseType.getDataSource(platform);
EntityModel model = Models.MODEL3;
Configuration configuration = new ConfigurationBuilder(dataSource, model)
.useDefaultLogging()
.setEntityCache(new EmptyEntityCache())
.setWriteExecutor(Executors.newSingleThreadExecutor())
.build();
SchemaModifier tables = new SchemaModifier(configuration);
tables.createTables(TableCreationMode.DROP_CREATE);
System.out.println(tables.createTablesString(TableCreationMode.DROP_CREATE));
data = new EntityDataStore<>(configuration);
}
示例7: setup
import javax.sql.CommonDataSource; //导入依赖的package包/类
@Before
public void setup() throws SQLException {
Platform platform = new HSQL();
CommonDataSource dataSource = DatabaseType.getDataSource(platform);
EntityModel model = io.requery.test.model.Models.DEFAULT;
CachingProvider provider = Caching.getCachingProvider();
CacheManager cacheManager = provider.getCacheManager();
Configuration configuration = new ConfigurationBuilder(dataSource, model)
.useDefaultLogging()
.setWriteExecutor(Executors.newSingleThreadExecutor())
.setEntityCache(new EntityCacheBuilder(model)
.useReferenceCache(true)
.useSerializableCache(true)
.useCacheManager(cacheManager)
.build())
.build();
SchemaModifier tables = new SchemaModifier(configuration);
tables.createTables(TableCreationMode.DROP_CREATE);
data = new ReactorEntityStore<>(new EntityDataStore<Persistable>(configuration));
}
示例8: setup
import javax.sql.CommonDataSource; //导入依赖的package包/类
@Before
public void setup() throws SQLException {
CommonDataSource dataSource = DatabaseType.getDataSource(platform);
EntityModel model = Models.STATELESS;
Configuration configuration = new ConfigurationBuilder(dataSource, model)
.useDefaultLogging()
.setEntityCache(new EmptyEntityCache())
.setWriteExecutor(Executors.newSingleThreadExecutor())
.build();
SchemaModifier tables = new SchemaModifier(configuration);
tables.createTables(TableCreationMode.DROP_CREATE);
System.out.println(tables.createTablesString(TableCreationMode.DROP_CREATE));
data = new EntityDataStore<>(configuration);
}
示例9: setup
import javax.sql.CommonDataSource; //导入依赖的package包/类
@Before
public void setup() throws SQLException {
CommonDataSource dataSource = DatabaseType.getDataSource(new SQLite());
EntityModel model = Models.AUTOVALUE;
Configuration configuration = new ConfigurationBuilder(dataSource, model)
.useDefaultLogging()
.setEntityCache(new EntityCacheBuilder(model)
.useReferenceCache(true)
.build())
.build();
data = new EntityDataStore<>(configuration);
SchemaModifier tables = new SchemaModifier(configuration);
tables.dropTables();
TableCreationMode mode = TableCreationMode.CREATE_NOT_EXISTS;
System.out.println(tables.createTablesString(mode));
tables.createTables(mode);
}
示例10: setup
import javax.sql.CommonDataSource; //导入依赖的package包/类
@Before
public void setup() throws SQLException {
Platform platform = new HSQL();
CommonDataSource dataSource = DatabaseType.getDataSource(platform);
EntityModel model = io.requery.test.model.Models.DEFAULT;
CachingProvider provider = Caching.getCachingProvider();
CacheManager cacheManager = provider.getCacheManager();
Configuration configuration = new ConfigurationBuilder(dataSource, model)
.useDefaultLogging()
.setWriteExecutor(Executors.newSingleThreadExecutor())
.setEntityCache(new EntityCacheBuilder(model)
.useReferenceCache(true)
.useSerializableCache(true)
.useCacheManager(cacheManager)
.build())
.build();
SchemaModifier tables = new SchemaModifier(configuration);
tables.createTables(TableCreationMode.DROP_CREATE);
data = ReactiveSupport.toReactiveStore(new EntityDataStore<Persistable>(configuration));
}
示例11: setup
import javax.sql.CommonDataSource; //导入依赖的package包/类
@Before
public void setup() throws SQLException {
Platform platform = new HSQL();
CommonDataSource dataSource = DatabaseType.getDataSource(platform);
EntityModel model = io.requery.test.model.Models.DEFAULT;
CachingProvider provider = Caching.getCachingProvider();
CacheManager cacheManager = provider.getCacheManager();
Configuration configuration = new ConfigurationBuilder(dataSource, model)
.useDefaultLogging()
.setWriteExecutor(Executors.newSingleThreadExecutor())
.setEntityCache(new EntityCacheBuilder(model)
.useReferenceCache(true)
.useSerializableCache(true)
.useCacheManager(cacheManager)
.build())
.build();
SchemaModifier tables = new SchemaModifier(configuration);
tables.createTables(TableCreationMode.DROP_CREATE);
data = RxSupport.toReactiveStore(new EntityDataStore<Persistable>(configuration));
}
示例12: setup
import javax.sql.CommonDataSource; //导入依赖的package包/类
@Before
public void setup() throws SQLException {
CommonDataSource dataSource = DatabaseType.getDataSource(platform);
EntityModel model = io.requery.test.model.Models.DEFAULT;
Configuration configuration = new ConfigurationBuilder(dataSource, model)
.useDefaultLogging()
.setStatementCacheSize(10)
.setBatchUpdateSize(50)
.setWriteExecutor(Executors.newSingleThreadExecutor())
.build();
schemaModifier = new SchemaModifier(configuration);
try {
schemaModifier.dropTables();
} catch (Exception e) {
// expected if 'drop if exists' not supported (so ignore in that case)
if (!platform.supportsIfExists()) {
throw e;
}
}
schemaModifier.createTables(TableCreationMode.CREATE);
}
示例13: getJDBCDataSource
import javax.sql.CommonDataSource; //导入依赖的package包/类
public static CommonDataSource getJDBCDataSource(String clazz, String url, String user,
String password) {
if (url == null) {
throw new ConnectionPoolException("url is null");
}
Driver driver;
try {
if (clazz == null) {
clazz = JdbcUtils.getDriverClassName(url);
}
driver = JdbcUtils.createDriver(clazz);
} catch (SQLException e) {
throw new ConnectionPoolException(e);
}
Properties connectProperties = new Properties();
if (user != null) {
connectProperties.put("user", user);
}
if (password != null) {
connectProperties.put("password", password);
}
return new JDBCDataSource(clazz, url, driver, connectProperties);
}
示例14: pool
import javax.sql.CommonDataSource; //导入依赖的package包/类
@Override
public CommonDataSource pool(final String name, final String driver, final Properties properties) {
properties.setProperty("name", name);
final String xa = String.class.cast(properties.remove("XaDataSource"));
if (xa == null && !properties.containsKey("JdbcDriver")) {
properties.setProperty("driverClassName", driver);
}
final BasicDataSource ds = build(BasicDataSource.class, properties);
ds.setDriverClassName(driver);
if (xa != null) {
ds.setDelegate(XADataSourceResource.proxy(Thread.currentThread().getContextClassLoader(), xa));
}
return ds;
}
示例15: pool
import javax.sql.CommonDataSource; //导入依赖的package包/类
@Override
public CommonDataSource pool(final String name, final String driver, final Properties properties) {
return (CustomDataSource) Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(),
new Class<?>[]{CustomDataSource.class},
new InvocationHandler() {
@Override
public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
if (method.getName().equals("name")) {
return properties.getProperty("Name");
}
if ("hashCode".equals(method.getName())) {
return properties.hashCode(); // don't care
}
return null;
}
});
}