本文整理匯總了Java中com.holonplatform.jdbc.DataSourceConfigProperties類的典型用法代碼示例。如果您正苦於以下問題:Java DataSourceConfigProperties類的具體用法?Java DataSourceConfigProperties怎麽用?Java DataSourceConfigProperties使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
DataSourceConfigProperties類屬於com.holonplatform.jdbc包,在下文中一共展示了DataSourceConfigProperties類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testHikariType
import com.holonplatform.jdbc.DataSourceConfigProperties; //導入依賴的package包/類
@Test
public void testHikariType() throws SQLException {
DataSource ds = DataSourceBuilder.create().build(
DataSourceConfigProperties.builder("pooling2").withPropertySource("test_build.properties").build());
assertNotNull(ds);
assertEquals(HikariDataSource.class, ds.getClass());
assertEquals("jdbc:h2:mem:testdb", ((HikariDataSource) ds).getJdbcUrl());
assertEquals("sa", ((HikariDataSource) ds).getUsername());
assertEquals(2, ((HikariDataSource) ds).getMinimumIdle());
assertEquals(7, ((HikariDataSource) ds).getMaximumPoolSize());
assertEquals(1234L, ((HikariDataSource) ds).getConnectionTimeout());
assertEquals(DatabasePlatform.H2.getDriverClassName(), ((HikariDataSource) ds).getDriverClassName());
assertEquals(DatabasePlatform.H2.getValidationQuery(), ((HikariDataSource) ds).getConnectionTestQuery());
try (Connection c = ds.getConnection()) {
assertNotNull(c);
}
}
示例2: setup
import com.holonplatform.jdbc.DataSourceConfigProperties; //導入依賴的package包/類
public void setup() {
// tag::setup[]
JdbcDatastore datastore = JdbcDatastore.builder() // obtain the builder
.dataSource(getDataSource()) // <1>
.database(DatabasePlatform.ORACLE) // <2>
.build();
datastore = JdbcDatastore.builder() // obtain the builder
.dataSource(DataSourceConfigProperties.builder().withPropertySource("jdbc.properties").build()) // <3>
.dialect(new MyDialect()) // <4>
.build();
datastore = JdbcDatastore.builder() // obtain the builder
.dataContextId("db1") // <5>
.dataSource(DataSourceConfigProperties.builder("db1").withPropertySource("jdbc.properties").build()) // <6>
.configuration(
DatastoreConfigProperties.builder("db1").withPropertySource("datastore.properties").build()) // <7>
.build();
// end::setup[]
}
示例3: build
import com.holonplatform.jdbc.DataSourceConfigProperties; //導入依賴的package包/類
@Override
public DataSource build(DataSourceConfigProperties configurationProperties) throws ConfigurationException {
final String dataContextId = configurationProperties.getDataContextId().orElse(null);
final String jndiName = configurationProperties.getConfigPropertyValue(DataSourceConfigProperties.JNDI_NAME,
null);
if (jndiName == null || jndiName.trim().equals("")) {
throw new ConfigurationException(
DefaultDataSourceBuilderConfiguration.buildMissingJNDINameMessage(dataContextId));
}
try {
DataSource dataSource = lookupJNDIDataSource(jndiName);
LOGGER.debug(() -> "(Data context id: " + dataContextId + "): " + "DataSource initialized using JNDI name "
+ jndiName);
return dataSource;
} catch (Exception e) {
throw new ConfigurationException("Failed to load DataSource using JNDI name: " + jndiName, e);
}
}
示例4: getScripts
import com.holonplatform.jdbc.DataSourceConfigProperties; //導入依賴的package包/類
private List<Resource> getScripts(String locations, String fallback) {
String scriptLocations = locations;
if (scriptLocations == null) {
StringBuilder sb = new StringBuilder();
DatabasePlatform db = configuration.getConfigPropertyValue(DataSourceConfigProperties.PLATFORM, null);
String platform = (db != null) ? db.name() : null;
if (getDataContextId().isPresent()) {
if (platform != null) {
sb.append("classpath*:" + getDataContextId().get() + "-" + fallback + "-" + platform + ".sql,");
}
sb.append("classpath*:" + getDataContextId().get() + "-" + fallback + ".sql");
} else {
if (platform != null) {
sb.append("classpath*:" + fallback + "-" + platform + ".sql,");
}
sb.append("classpath*:" + fallback + ".sql");
}
scriptLocations = sb.toString();
}
return getResources(scriptLocations);
}
示例5: customProvider
import com.holonplatform.jdbc.DataSourceConfigProperties; //導入依賴的package包/類
@Bean("test_tenant_dsprovider")
public TenantDataSourceProvider customProvider() {
return new TenantDataSourceProvider() {
@Override
public DataSource getDataSource(String tenantId) {
Properties properties = new Properties();
properties.put("holon.datasource.username", "sa");
properties.put("holon.datasource.url",
"jdbc:h2:mem:testdbt1;INIT=RUNSCRIPT FROM 'classpath:test-scripts/db1.sql'");
return DataSourceBuilder.create()
.build(DataSourceConfigProperties.builder().withPropertySource(properties).build());
}
};
}
開發者ID:holon-platform,項目名稱:holon-jdbc,代碼行數:17,代碼來源:TestEnableMultiTenantDataSourceConfigResolver.java
示例6: dsProvider
import com.holonplatform.jdbc.DataSourceConfigProperties; //導入依賴的package包/類
@Bean("test_tenant_dsprovider")
public TenantDataSourceProvider dsProvider() {
return new TenantDataSourceProvider() {
@Override
public DataSource getDataSource(String tenantId) {
Properties properties = new Properties();
properties.put("holon.datasource.username", "sa");
properties.put("holon.datasource.url",
"jdbc:h2:mem:testdbt1;INIT=RUNSCRIPT FROM 'classpath:test-scripts/db1.sql'");
return DataSourceBuilder.create()
.build(DataSourceConfigProperties.builder().withPropertySource(properties).build());
}
};
}
開發者ID:holon-platform,項目名稱:holon-jdbc,代碼行數:17,代碼來源:TestEnableMultiTenantDataSourceConfigProvider.java
示例7: configuration
import com.holonplatform.jdbc.DataSourceConfigProperties; //導入依賴的package包/類
public void configuration() throws IOException {
// tag::configuration[]
DataSourceConfigProperties config = DataSourceConfigProperties.builder().withDefaultPropertySources().build(); // <1>
config = DataSourceConfigProperties.builder().withSystemPropertySource().build(); // <2>
Properties props = new Properties();
props.put("holon.datasource.url", "jdbc:h2:mem:testdb");
config = DataSourceConfigProperties.builder().withPropertySource(props).build(); // <3>
config = DataSourceConfigProperties.builder().withPropertySource("datasource.properties").build(); // <4>
config = DataSourceConfigProperties.builder()
.withPropertySource(
Thread.currentThread().getContextClassLoader().getResourceAsStream("datasource.properties"))
.build(); // <5>
// end::configuration[]
}
示例8: buildMissingJdbcUrlMessage
import com.holonplatform.jdbc.DataSourceConfigProperties; //導入依賴的package包/類
/**
* Build the missing JDBC url error message.
* @param type DataSource type
* @param dataContextId Optional data context id
* @return the error message
*/
public static String buildMissingJdbcUrlMessage(String type, String dataContextId) {
StringBuilder sb = new StringBuilder();
if (dataContextId != null) {
sb.append("(Data context id: ");
sb.append(dataContextId);
sb.append(") ");
}
sb.append("Failed to initialize DataSource of type [");
sb.append(type);
sb.append("]: Missing JDBC connection URL. Check the DataSource configuration property [");
sb.append(DataSourceConfigProperties.DEFAULT_NAME);
sb.append(".");
if (dataContextId != null) {
sb.append(dataContextId);
sb.append(".");
}
sb.append(DataSourceConfigProperties.URL.getKey());
sb.append("]");
return sb.toString();
}
示例9: buildMissingDriverClassMessage
import com.holonplatform.jdbc.DataSourceConfigProperties; //導入依賴的package包/類
/**
* Build the missing JDBC driver class name error message.
* @param type DataSource type
* @param dataContextId Optional data context id
* @return the error message
*/
public static String buildMissingDriverClassMessage(String type, String dataContextId) {
StringBuilder sb = new StringBuilder();
if (dataContextId != null) {
sb.append("(Data context id: ");
sb.append(dataContextId);
sb.append(") ");
}
sb.append("Failed to initialize DataSource of type [");
sb.append(type);
sb.append(
"]: Cannot auto-detect JDBC driver class to use. The driver class name must be specified using configuration property [");
sb.append(DataSourceConfigProperties.DEFAULT_NAME);
sb.append(".");
if (dataContextId != null) {
sb.append(dataContextId);
sb.append(".");
}
sb.append(DataSourceConfigProperties.DRIVER_CLASS_NAME.getKey());
sb.append("]");
return sb.toString();
}
示例10: buildMissingJNDINameMessage
import com.holonplatform.jdbc.DataSourceConfigProperties; //導入依賴的package包/類
/**
* Build the missing JNDI name error message.
* @param dataContextId Optional data context id
* @return the error message
*/
public static String buildMissingJNDINameMessage(String dataContextId) {
StringBuilder sb = new StringBuilder();
if (dataContextId != null) {
sb.append("(Data context id: ");
sb.append(dataContextId);
sb.append(") ");
}
sb.append(
"Failed to initialize JNDI DataSource: Missing JNDI name. Check the DataSource configuration property [");
sb.append(DataSourceConfigProperties.DEFAULT_NAME);
sb.append(".");
if (dataContextId != null) {
sb.append(dataContextId);
sb.append(".");
}
sb.append(DataSourceConfigProperties.JNDI_NAME.getKey());
sb.append("]");
return sb.toString();
}
示例11: getDataSource
import com.holonplatform.jdbc.DataSourceConfigProperties; //導入依賴的package包/類
@Override
public DataSource getDataSource(String tenantId) {
Properties properties = new Properties();
properties.put("holon.datasource.username", "sa");
if ("T1".equals(tenantId)) {
properties.put("holon.datasource.url",
"jdbc:h2:mem:testdbt1;INIT=RUNSCRIPT FROM 'classpath:scripts/db1.sql'");
} else if ("T2".equals(tenantId)) {
properties.put("holon.datasource.url",
"jdbc:h2:mem:testdbt1;INIT=RUNSCRIPT FROM 'classpath:scripts/db2.sql'");
} else {
properties.put("holon.datasource.url",
"jdbc:h2:mem:testdbt1;INIT=RUNSCRIPT FROM 'classpath:scripts/db3.sql'");
}
return DataSourceBuilder.create()
.build(DataSourceConfigProperties.builder().withPropertySource(properties).build());
}
示例12: testTomcatType
import com.holonplatform.jdbc.DataSourceConfigProperties; //導入依賴的package包/類
@Test
public void testTomcatType() throws SQLException {
DataSource ds = DataSourceBuilder.create().build(
DataSourceConfigProperties.builder("pooling1").withPropertySource("test_build.properties").build());
assertNotNull(ds);
assertEquals(org.apache.tomcat.jdbc.pool.DataSource.class, ds.getClass());
assertEquals("jdbc:h2:mem:testdb", ((org.apache.tomcat.jdbc.pool.DataSource) ds).getUrl());
assertEquals("sa", ((org.apache.tomcat.jdbc.pool.DataSource) ds).getUsername());
assertEquals(3, ((org.apache.tomcat.jdbc.pool.DataSource) ds).getInitialSize());
assertEquals(5, ((org.apache.tomcat.jdbc.pool.DataSource) ds).getMaxActive());
assertEquals(33120L, ((org.apache.tomcat.jdbc.pool.DataSource) ds).getMaxAge());
assertEquals(DatabasePlatform.H2.getDriverClassName(),
((org.apache.tomcat.jdbc.pool.DataSource) ds).getDriverClassName());
assertEquals(DatabasePlatform.H2.getValidationQuery(),
((org.apache.tomcat.jdbc.pool.DataSource) ds).getValidationQuery());
try (Connection c = ds.getConnection()) {
assertNotNull(c);
}
}
示例13: testDBCPType
import com.holonplatform.jdbc.DataSourceConfigProperties; //導入依賴的package包/類
@Test
public void testDBCPType() throws SQLException {
DataSource ds = DataSourceBuilder.create().build(
DataSourceConfigProperties.builder("pooling3").withPropertySource("test_build.properties").build());
assertNotNull(ds);
assertEquals(org.apache.commons.dbcp2.BasicDataSource.class, ds.getClass());
assertEquals("jdbc:h2:mem:testdb", ((org.apache.commons.dbcp2.BasicDataSource) ds).getUrl());
assertEquals("sa", ((org.apache.commons.dbcp2.BasicDataSource) ds).getUsername());
assertEquals(8, ((org.apache.commons.dbcp2.BasicDataSource) ds).getInitialSize());
assertEquals(12, ((org.apache.commons.dbcp2.BasicDataSource) ds).getMaxTotal());
assertEquals(1000L, ((org.apache.commons.dbcp2.BasicDataSource) ds).getMaxWaitMillis());
assertEquals(DatabasePlatform.H2.getDriverClassName(),
((org.apache.commons.dbcp2.BasicDataSource) ds).getDriverClassName());
assertEquals(DatabasePlatform.H2.getValidationQuery(),
((org.apache.commons.dbcp2.BasicDataSource) ds).getValidationQuery());
try (Connection c = ds.getConnection()) {
assertNotNull(c);
}
}
示例14: setConfiguration
import com.holonplatform.jdbc.DataSourceConfigProperties; //導入依賴的package包/類
/**
* Set the data source configuration properties.
* @param configuration the data source configuration properties to set (not null)
* @param buildDataSource Whether to build and set a {@link DataSource} using given configuration properties.
*/
public void setConfiguration(DataSourceConfigProperties configuration, boolean buildDataSource) {
ObjectUtils.argumentNotNull(configuration, "DataSource configuration must be not null");
this.configuration = configuration;
if (!getDatabase().isPresent()) {
setDatabase(configuration.getDatabasePlatform());
}
if (buildDataSource) {
setDataSource(DataSourceBuilder.create().build(configuration));
}
}
示例15: dataSource
import com.holonplatform.jdbc.DataSourceConfigProperties; //導入依賴的package包/類
@Bean
public DataSource dataSource() {
DataSource ds = DataSourceBuilder.create().build(
DataSourceConfigProperties.builder().withPropertySource("sqlite/datasource.properties").build());
// init
initSQL(ds, "sqlite/schema.sql", "sqlite/data.sql");
return ds;
}