Package org.clazzes.util.jdbc.provider
Class JdbcProvider
- java.lang.Object
-
- org.clazzes.util.jdbc.provider.JdbcProvider
-
- All Implemented Interfaces:
IDataSourceKeeper
,org.osgi.service.cm.ManagedService
public class JdbcProvider extends Object implements org.osgi.service.cm.ManagedService, IDataSourceKeeper
Export
DataSource
instances as OSGi services with the given properties.This bundle reads in configuration properties from the configuration PID
org.clazzes.jdbc.provider
following the conventiondatasource.<name>.<propname>
, wheredesignates the name of the datasource as published under the
datasource.name
OSGi service property.<propname>
designates a property ofBasicDataSource
to be set for the published datasource instance.The following properties are supported:
Property BasicDataSource doc Remarks url
BasicDataSource.setUrl(String)
username
{@link BasicDataSource#setUsername(String) password
{@link BasicDataSource#setPassword(String) driverClassName
{@link BasicDataSource#setDriverClassName(String) The driver class is resolved from the class loader of the jdbc-provider bundle. This allows for putting JDBC driver on the boot classloader of the OSGi container or creating fragment bundles, which supply JDBC drivers to the jdbc-provider bundle. For MySQL, MSSQL, PostgreSql and Oracle JDBC.URLs the driver class name is automatically deduced from url
.validationQuery
BasicDataSource.setValidationQuery(String)
testOnBorrow
BasicDataSource.setTestOnBorrow(boolean)
If unspecified, this property is set to true
, ifvalidationQuery
has been specified.testOnReturn
BasicDataSource.setTestOnReturn(boolean)
testWhileIdle
BasicDataSource.setTestWhileIdle(boolean)
defaultCatalog
BasicDataSource.setDefaultCatalog(String)
Needed, if your driver supports catalogs. defaultAutoCommit
BasicDataSource#setDefaultAutoCommit(boolean)
defaultTransactionIsolation
BasicDataSource.setDefaultTransactionIsolation(int)
defaultReadOnly
BasicDataSource#setDefaultReadOnly(boolean)
initialSize
BasicDataSource.setInitialSize(int)
minIdle
BasicDataSource.setMinIdle(int)
minEvictableIdleTimeMillis
BasicDataSource.setMinEvictableIdleTimeMillis(long)
maxActive
BasicDataSource#setMaxActive(int)
maxIdle
BasicDataSource.setMaxIdle(int)
maxWait
BasicDataSource#setMaxWait(long)
maxOpenPreparedStatement
BasicDataSource.setMaxOpenPreparedStatements(int)
timeBetweenEvictionRunsMillis
BasicDataSource.setTimeBetweenEvictionRunsMillis(long)
connectionInitSqls
BasicDataSource.setConnectionInitSqls(java.util.Collection)
The String property is split at semicolon characters and passed as a list of strings. connectionProperties
BasicDataSource.setConnectionProperties(String)
poolPreparedStatements
BasicDataSource.setPoolPreparedStatements(boolean)
accessToUnderlyingConnectionAllowed
BasicDataSource.setAccessToUnderlyingConnectionAllowed(boolean)
removeAbandoned
BasicDataSource#setRemoveAbandoned(boolean)
removeAbandonedTimeout
BasicDataSource.setRemoveAbandonedTimeout(int)
healthTags
Comma-separated health check tags. If set, the datasource is registered as a felix health check. The tag jdbc
will be added, if not specified in the given list.healthQuery
SQL query to perform as health check. The query mus return one row an one column. healthInterval
See hc.async.intervalInSec
Interval in seconds at which to perform health checks. If not specified, 60 seconds are used. healthKeepNonOkResultsStickyForSec
See hc.keepNonOkResultsStickyForSec
Interval in seconds to keep negtive health check results. If not specified, negative results will not be kept longer then healthInterval
seconds.
-
-
Field Summary
Fields Modifier and Type Field Description static String
CONFIG_PID
-
Constructor Summary
Constructors Constructor Description JdbcProvider()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description DataSourceRecord
getDataSourceRecord(String name)
Get a configured datasource.void
init()
Aninit-method
for blueprint in order to create an empty configuration.Map<String,Boolean>
listDataSources()
boolean
restartDataSource(String name)
Restart and possibly re-export the given datasource as an OSGi service.void
setBundle(org.osgi.framework.Bundle bundle)
void
setConfigurationAdmin(org.osgi.service.cm.ConfigurationAdmin configurationAdmin)
void
setOneTimeScheduler(org.clazzes.util.sched.IOneTimeScheduler oneTimeScheduler)
void
setSecretsService(BiFunction<String,String,String> secretsService)
void
shutdown()
Adestroy-method
for blueprint in order to shut down all datasources.void
updated(Dictionary properties)
-
-
-
Field Detail
-
CONFIG_PID
public static final String CONFIG_PID
- See Also:
- Constant Field Values
-
-
Method Detail
-
updated
public void updated(Dictionary properties) throws org.osgi.service.cm.ConfigurationException
- Specified by:
updated
in interfaceorg.osgi.service.cm.ManagedService
- Throws:
org.osgi.service.cm.ConfigurationException
-
init
public void init() throws IOException
Aninit-method
for blueprint in order to create an empty configuration.- Throws:
IOException
-
shutdown
public void shutdown()
Adestroy-method
for blueprint in order to shut down all datasources.
-
setBundle
public void setBundle(org.osgi.framework.Bundle bundle)
- Parameters:
bundle
- The bundle to set, which is used to export DataSource OSGi services.
-
getDataSourceRecord
public DataSourceRecord getDataSourceRecord(String name)
Description copied from interface:IDataSourceKeeper
Get a configured datasource.- Specified by:
getDataSourceRecord
in interfaceIDataSourceKeeper
- Parameters:
name
- The name of the datasource.- Returns:
- The associated record.
-
listDataSources
public Map<String,Boolean> listDataSources()
- Specified by:
listDataSources
in interfaceIDataSourceKeeper
- Returns:
- A list of datasources along with their activation status.
-
restartDataSource
public boolean restartDataSource(String name) throws org.osgi.service.cm.ConfigurationException
Description copied from interface:IDataSourceKeeper
Restart and possibly re-export the given datasource as an OSGi service.- Specified by:
restartDataSource
in interfaceIDataSourceKeeper
- Parameters:
name
- The name of the datasource to restart.- Throws:
org.osgi.service.cm.ConfigurationException
-
setConfigurationAdmin
public void setConfigurationAdmin(org.osgi.service.cm.ConfigurationAdmin configurationAdmin)
-
setOneTimeScheduler
public void setOneTimeScheduler(org.clazzes.util.sched.IOneTimeScheduler oneTimeScheduler)
-
setSecretsService
public void setSecretsService(BiFunction<String,String,String> secretsService)
-
-