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
DataSourceinstances as OSGi services with the given properties.This bundle reads in configuration properties from the configuration PID
org.clazzes.jdbc.providerfollowing the conventiondatasource.<name>.<propname>, wheredesignates the name of the datasource as published under thedatasource.nameOSGi service property.<propname>designates a property ofBasicDataSourceto be set for the published datasource instance.The following properties are supported:
Property BasicDataSource doc Remarks urlBasicDataSource.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.validationQueryBasicDataSource.setValidationQuery(String)testOnBorrowBasicDataSource.setTestOnBorrow(boolean)If unspecified, this property is set to true, ifvalidationQueryhas been specified.testOnReturnBasicDataSource.setTestOnReturn(boolean)testWhileIdleBasicDataSource.setTestWhileIdle(boolean)defaultCatalogBasicDataSource.setDefaultCatalog(String)Needed, if your driver supports catalogs. defaultAutoCommitBasicDataSource#setDefaultAutoCommit(boolean)defaultTransactionIsolationBasicDataSource.setDefaultTransactionIsolation(int)defaultReadOnlyBasicDataSource#setDefaultReadOnly(boolean)initialSizeBasicDataSource.setInitialSize(int)minIdleBasicDataSource.setMinIdle(int)minEvictableIdleTimeMillisBasicDataSource.setMinEvictableIdleTimeMillis(long)maxActiveBasicDataSource#setMaxActive(int)maxIdleBasicDataSource.setMaxIdle(int)maxWaitBasicDataSource#setMaxWait(long)maxOpenPreparedStatementBasicDataSource.setMaxOpenPreparedStatements(int)timeBetweenEvictionRunsMillisBasicDataSource.setTimeBetweenEvictionRunsMillis(long)connectionInitSqlsBasicDataSource.setConnectionInitSqls(java.util.Collection)The String property is split at semicolon characters and passed as a list of strings. connectionPropertiesBasicDataSource.setConnectionProperties(String)poolPreparedStatementsBasicDataSource.setPoolPreparedStatements(boolean)accessToUnderlyingConnectionAllowedBasicDataSource.setAccessToUnderlyingConnectionAllowed(boolean)removeAbandonedBasicDataSource#setRemoveAbandoned(boolean)removeAbandonedTimeoutBasicDataSource.setRemoveAbandonedTimeout(int)healthTagsComma-separated health check tags. If set, the datasource is registered as a felix health check. The tag jdbcwill be added, if not specified in the given list.healthQuerySQL query to perform as health check. The query mus return one row an one column. healthIntervalSee hc.async.intervalInSecInterval in seconds at which to perform health checks. If not specified, 60 seconds are used. healthKeepNonOkResultsStickyForSecSee hc.keepNonOkResultsStickyForSecInterval in seconds to keep negtive health check results. If not specified, negative results will not be kept longer then healthIntervalseconds.
-
-
Field Summary
Fields Modifier and Type Field Description static StringCONFIG_PID
-
Constructor Summary
Constructors Constructor Description JdbcProvider()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description DataSourceRecordgetDataSourceRecord(String name)Get a configured datasource.voidinit()Aninit-methodfor blueprint in order to create an empty configuration.Map<String,Boolean>listDataSources()booleanrestartDataSource(String name)Restart and possibly re-export the given datasource as an OSGi service.voidsetBundle(org.osgi.framework.Bundle bundle)voidsetConfigurationAdmin(org.osgi.service.cm.ConfigurationAdmin configurationAdmin)voidsetOneTimeScheduler(org.clazzes.util.sched.IOneTimeScheduler oneTimeScheduler)voidsetSecretsService(BiFunction<String,String,String> secretsService)voidshutdown()Adestroy-methodfor blueprint in order to shut down all datasources.voidupdated(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:
updatedin interfaceorg.osgi.service.cm.ManagedService- Throws:
org.osgi.service.cm.ConfigurationException
-
init
public void init() throws IOExceptionAninit-methodfor blueprint in order to create an empty configuration.- Throws:
IOException
-
shutdown
public void shutdown()
Adestroy-methodfor 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:IDataSourceKeeperGet a configured datasource.- Specified by:
getDataSourceRecordin interfaceIDataSourceKeeper- Parameters:
name- The name of the datasource.- Returns:
- The associated record.
-
listDataSources
public Map<String,Boolean> listDataSources()
- Specified by:
listDataSourcesin 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:IDataSourceKeeperRestart and possibly re-export the given datasource as an OSGi service.- Specified by:
restartDataSourcein 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)
-
-