本文整理匯總了Java中com.holonplatform.jdbc.DataSourceConfigProperties.getConfigPropertyValue方法的典型用法代碼示例。如果您正苦於以下問題:Java DataSourceConfigProperties.getConfigPropertyValue方法的具體用法?Java DataSourceConfigProperties.getConfigPropertyValue怎麽用?Java DataSourceConfigProperties.getConfigPropertyValue使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.holonplatform.jdbc.DataSourceConfigProperties
的用法示例。
在下文中一共展示了DataSourceConfigProperties.getConfigPropertyValue方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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);
}
}
示例2: build
import com.holonplatform.jdbc.DataSourceConfigProperties; //導入方法依賴的package包/類
@Override
public DataSource build(DataSourceConfigProperties configurationProperties) throws ConfigurationException {
final String dataContextId = configurationProperties.getDataContextId().orElse(null);
final String url = configurationProperties.getConfigPropertyValue(DataSourceConfigProperties.URL, null);
if (url == null) {
throw new ConfigurationException(DefaultDataSourceBuilderConfiguration
.buildMissingJdbcUrlMessage(getDataSourceType(), dataContextId));
}
final String driverClassName = configurationProperties.getConfigPropertyValue(
DataSourceConfigProperties.DRIVER_CLASS_NAME,
configurationProperties.getDriverClassName()
.orElseThrow(() -> new ConfigurationException("Cannot auto detect JDBC driver class to use, "
+ "please specify driver class name using config property "
+ DataSourceConfigProperties.DRIVER_CLASS_NAME.getKey() + " (Data context: "
+ dataContextId + ")")));
BasicDataSource ds = BasicDataSource.builder().url(url).driverClassName(driverClassName)
.username(configurationProperties.getConfigPropertyValue(DataSourceConfigProperties.USERNAME, null))
.password(configurationProperties.getConfigPropertyValue(DataSourceConfigProperties.PASSWORD, null))
.build();
LOGGER.debug(
() -> "(Data context id: " + dataContextId + "): " + "BasicDataSource setted up for jdbc url: " + url);
return ds;
}
示例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 url = configurationProperties.getConfigPropertyValue(DataSourceConfigProperties.URL, null);
if (url == null) {
throw new ConfigurationException(DefaultDataSourceBuilderConfiguration
.buildMissingJdbcUrlMessage(getDataSourceType(), dataContextId));
}
final String driverClass = configurationProperties.getConfigPropertyValue(
DataSourceConfigProperties.DRIVER_CLASS_NAME,
configurationProperties.getDriverClassName()
.orElseThrow(() -> new ConfigurationException(DefaultDataSourceBuilderConfiguration
.buildMissingDriverClassMessage(getDataSourceType(), dataContextId))));
try {
// Hikari specific configuration properties
Map<String, String> hikariProperties = configurationProperties.getSubPropertiesUsingPrefix("hikari");
Properties properties = new Properties();
properties.putAll(hikariProperties);
final HikariConfig config = new HikariConfig(properties);
config.setDriverClassName(driverClass);
config.setJdbcUrl(url);
// name
String name = configurationProperties.getConfigPropertyValue(DataSourceConfigProperties.NAME, null);
if (name != null) {
config.setPoolName(name);
}
// validation query
configurationProperties.getConnectionValidationQuery().ifPresent(vq -> config.setConnectionTestQuery(vq));
// credentials
config.setUsername(
configurationProperties.getConfigPropertyValue(DataSourceConfigProperties.USERNAME, null));
config.setPassword(
configurationProperties.getConfigPropertyValue(DataSourceConfigProperties.PASSWORD, null));
// pool size
Integer minPoolSize = configurationProperties
.getConfigPropertyValue(DataSourceConfigProperties.MIN_POOL_SIZE, null);
if (minPoolSize != null && minPoolSize > 0) {
config.setMinimumIdle(minPoolSize);
}
Integer maxPoolSize = configurationProperties.getConfigPropertyValue(
DataSourceConfigProperties.MAX_POOL_SIZE, DataSourceConfigProperties.DEFAULT_MAX_POOL_SIZE);
if (maxPoolSize != null && maxPoolSize > 0) {
config.setMaximumPoolSize(maxPoolSize);
}
// autocommit
if (configurationProperties.isDisableAutoCommit()) {
config.setAutoCommit(false);
}
HikariDataSource ds = new HikariDataSource(config);
LOGGER.debug(() -> "(Data context id: " + dataContextId + "): "
+ "HikariCP DataSource setted up for jdbc url: " + url + " [Max pool size: " + maxPoolSize + "]");
return ds;
} catch (Exception e) {
throw new ConfigurationException("Failed to configure [" + getDataSourceType() + "] DataSource", e);
}
}
示例4: build
import com.holonplatform.jdbc.DataSourceConfigProperties; //導入方法依賴的package包/類
@Override
public DataSource build(DataSourceConfigProperties configurationProperties) throws ConfigurationException {
final String dataContextId = configurationProperties.getDataContextId().orElse(null);
final String url = configurationProperties.getConfigPropertyValue(DataSourceConfigProperties.URL, null);
if (url == null) {
throw new ConfigurationException(DefaultDataSourceBuilderConfiguration
.buildMissingJdbcUrlMessage(getDataSourceType(), dataContextId));
}
final String driverClass = configurationProperties.getConfigPropertyValue(
DataSourceConfigProperties.DRIVER_CLASS_NAME,
configurationProperties.getDriverClassName()
.orElseThrow(() -> new ConfigurationException(DefaultDataSourceBuilderConfiguration
.buildMissingDriverClassMessage(getDataSourceType(), dataContextId))));
try {
// specific properties
Map<String, String> tomcatProperties = configurationProperties.getSubPropertiesUsingPrefix("tomcat");
Properties poolProperties = new Properties();
poolProperties.putAll(tomcatProperties);
PoolConfiguration config = org.apache.tomcat.jdbc.pool.DataSourceFactory
.parsePoolProperties(poolProperties);
config.setDriverClassName(driverClass);
config.setUrl(url);
// name
String name = configurationProperties.getConfigPropertyValue(DataSourceConfigProperties.NAME, null);
if (name != null) {
config.setName(name);
}
// validation query
configurationProperties.getConnectionValidationQuery().ifPresent(vq -> {
config.setTestOnBorrow(true);
config.setValidationQuery(vq);
});
// credentials
config.setUsername(
configurationProperties.getConfigPropertyValue(DataSourceConfigProperties.USERNAME, null));
config.setPassword(
configurationProperties.getConfigPropertyValue(DataSourceConfigProperties.PASSWORD, null));
// pool size
Integer minPoolSize = configurationProperties
.getConfigPropertyValue(DataSourceConfigProperties.MIN_POOL_SIZE, null);
if (minPoolSize != null && minPoolSize > 0) {
config.setInitialSize(minPoolSize);
config.setMinIdle(minPoolSize);
}
Integer maxPoolSize = configurationProperties.getConfigPropertyValue(
DataSourceConfigProperties.MAX_POOL_SIZE, DataSourceConfigProperties.DEFAULT_MAX_POOL_SIZE);
if (maxPoolSize != null && maxPoolSize > 0) {
config.setMaxActive(maxPoolSize);
if (config.getMaxIdle() > maxPoolSize) {
config.setMaxIdle(maxPoolSize);
}
}
// autocommit
if (configurationProperties.isDisableAutoCommit()) {
config.setDefaultAutoCommit(Boolean.FALSE);
}
final org.apache.tomcat.jdbc.pool.DataSource ds = new org.apache.tomcat.jdbc.pool.DataSource(config);
LOGGER.debug(() -> "(Data context id: " + dataContextId + "): "
+ "Tomcat DataSource setted up for jdbc url: " + url + " [Max pool size: " + maxPoolSize + "]");
return ds;
} catch (Exception e) {
throw new ConfigurationException("Failed to configure [" + getDataSourceType() + "] DataSource", e);
}
}
示例5: build
import com.holonplatform.jdbc.DataSourceConfigProperties; //導入方法依賴的package包/類
@Override
public DataSource build(DataSourceConfigProperties configurationProperties) throws ConfigurationException {
final String dataContextId = configurationProperties.getDataContextId().orElse(null);
final String url = configurationProperties.getConfigPropertyValue(DataSourceConfigProperties.URL, null);
if (url == null) {
throw new ConfigurationException(DefaultDataSourceBuilderConfiguration
.buildMissingJdbcUrlMessage(getDataSourceType(), dataContextId));
}
final String driverClass = configurationProperties.getConfigPropertyValue(
DataSourceConfigProperties.DRIVER_CLASS_NAME,
configurationProperties.getDriverClassName()
.orElseThrow(() -> new ConfigurationException(DefaultDataSourceBuilderConfiguration
.buildMissingDriverClassMessage(getDataSourceType(), dataContextId))));
try {
// specific properties
Map<String, String> dbcpProperties = configurationProperties.getSubPropertiesUsingPrefix("dbcp");
Properties poolProperties = new Properties();
poolProperties.putAll(dbcpProperties);
BasicDataSource ds = BasicDataSourceFactory.createDataSource(poolProperties);
ds.setDriverClassName(driverClass);
ds.setUrl(url);
// validation query
configurationProperties.getConnectionValidationQuery().ifPresent(vq -> {
ds.setTestOnBorrow(true);
ds.setValidationQuery(vq);
});
// credentials
ds.setUsername(configurationProperties.getConfigPropertyValue(DataSourceConfigProperties.USERNAME, null));
ds.setPassword(configurationProperties.getConfigPropertyValue(DataSourceConfigProperties.PASSWORD, null));
// pool size
Integer minPoolSize = configurationProperties
.getConfigPropertyValue(DataSourceConfigProperties.MIN_POOL_SIZE, null);
if (minPoolSize != null && minPoolSize > 0) {
ds.setInitialSize(minPoolSize);
ds.setMinIdle(minPoolSize);
}
Integer maxPoolSize = configurationProperties.getConfigPropertyValue(
DataSourceConfigProperties.MAX_POOL_SIZE, DataSourceConfigProperties.DEFAULT_MAX_POOL_SIZE);
if (maxPoolSize != null && maxPoolSize > 0) {
ds.setMaxTotal(maxPoolSize);
if (ds.getMaxIdle() > maxPoolSize) {
ds.setMaxIdle(maxPoolSize);
}
}
// autocommit
if (configurationProperties.isDisableAutoCommit()) {
ds.setDefaultAutoCommit(Boolean.FALSE);
}
LOGGER.debug(() -> "(Data context id: " + dataContextId + "): "
+ "DBCP2 DataSource setted up for jdbc url: " + url + " [Max pool size: " + maxPoolSize + "]");
return ds;
} catch (Exception e) {
throw new ConfigurationException("Failed to configure [" + getDataSourceType() + "] DataSource", e);
}
}
示例6: build
import com.holonplatform.jdbc.DataSourceConfigProperties; //導入方法依賴的package包/類
@Override
public DataSource build(final DataSourceConfigProperties configurationProperties) throws ConfigurationException {
ObjectUtils.argumentNotNull(configurationProperties, "DataSource configuration properties must be not null");
final ClassLoader cl = classLoader.get();
// type
String type = configurationProperties.getConfigPropertyValue(DataSourceConfigProperties.TYPE, null);
// check JNDI
final String jndiName = configurationProperties.getConfigPropertyValue(DataSourceConfigProperties.JNDI_NAME,
null);
if (jndiName != null && !jndiName.trim().equals("")) {
// check type
if (type != null && !type.trim().equals("") && !DataSourceBuilder.TYPE_JNDI.equals(jndiName)) {
throw new ConfigurationException("Invalid DataSource type property: when ["
+ DataSourceConfigProperties.JNDI_NAME.getKey() + "] property is specified only the type ["
+ DataSourceBuilder.TYPE_JNDI + "] is admitted, or it must be omitted");
}
type = DataSourceBuilder.TYPE_JNDI;
}
// type
if (type == null && cl != null) {
// get default
type = DefaultDataSourceBuilderConfiguration.getDefaultType(cl).orElse(null);
}
if (type == null) {
throw new ConfigurationException(
"Missing DataSource type property value and no default DataSource type available"
+ configurationProperties.getDataContextId().map(d -> " [Data context id: " + d + "]")
.orElse(""));
}
final String dataSourceType = type;
LOGGER.debug(() -> "Building DataSource using type [" + dataSourceType + "]");
// get a suitable factory
DataSourceFactory factory = factories.get(type);
if (factory == null && cl != null) {
factory = DefaultDataSourceBuilderConfiguration.getDataSourceFactory(cl, dataSourceType).orElse(null);
}
if (factory == null) {
throw new ConfigurationException("No DataSourceFactory bound to DataSource type [" + dataSourceType
+ "] is available"
+ configurationProperties.getDataContextId().map(d -> " [Data context id: " + d + "]").orElse(""));
}
// build DataSource
final DataSource dataSource = factory.build(configurationProperties);
// post processors
getPostProcessors(cl)
.forEach(p -> p.postProcessDataSource(dataSource, dataSourceType, configurationProperties));
// done
return dataSource;
}