Package org.h2.util

Class OsgiDataSourceFactory

  • All Implemented Interfaces:
    org.osgi.service.jdbc.DataSourceFactory

    public class OsgiDataSourceFactory
    extends java.lang.Object
    implements org.osgi.service.jdbc.DataSourceFactory
    This class implements the OSGi DataSourceFactory interface for the H2 JDBC driver. The following standard configuration properties are supported: DataSourceFactory.JDBC_USER, DataSourceFactory.JDBC_PASSWORD, DataSourceFactory.JDBC_DESCRIPTION, DataSourceFactory.JDBC_DATASOURCE_NAME, DataSourceFactory.JDBC_NETWORK_PROTOCOL, DataSourceFactory.JDBC_URL, DataSourceFactory.JDBC_SERVER_NAME, DataSourceFactory.JDBC_PORT_NUMBER. The following standard configuration properties are not supported: DataSourceFactory.JDBC_ROLE_NAME, DataSourceFactory.JDBC_DATABASE_NAME, DataSourceFactory.JDBC_INITIAL_POOL_SIZE, DataSourceFactory.JDBC_MAX_POOL_SIZE, DataSourceFactory.JDBC_MIN_POOL_SIZE, DataSourceFactory.JDBC_MAX_IDLE_TIME, DataSourceFactory.JDBC_MAX_STATEMENTS, DataSourceFactory.JDBC_PROPERTY_CYCLE. Any other property will be treated as a H2 specific option. If the DataSourceFactory.JDBC_URL property is passed to any of the DataSource factories, the following properties will be ignored: DataSourceFactory.JDBC_DATASOURCE_NAME, DataSourceFactory.JDBC_NETWORK_PROTOCOL, DataSourceFactory.JDBC_SERVER_NAME, DataSourceFactory.JDBC_PORT_NUMBER.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private Driver driver  
      • Fields inherited from interface org.osgi.service.jdbc.DataSourceFactory

        JDBC_DATABASE_NAME, JDBC_DATASOURCE_NAME, JDBC_DESCRIPTION, JDBC_INITIAL_POOL_SIZE, JDBC_MAX_IDLE_TIME, JDBC_MAX_POOL_SIZE, JDBC_MAX_STATEMENTS, JDBC_MIN_POOL_SIZE, JDBC_NETWORK_PROTOCOL, JDBC_PASSWORD, JDBC_PORT_NUMBER, JDBC_PROPERTY_CYCLE, JDBC_ROLE_NAME, JDBC_SERVER_NAME, JDBC_URL, JDBC_USER, OSGI_JDBC_DRIVER_CLASS, OSGI_JDBC_DRIVER_NAME, OSGI_JDBC_DRIVER_VERSION
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      javax.sql.ConnectionPoolDataSource createConnectionPoolDataSource​(java.util.Properties properties)
      Creates a pooled data source.
      javax.sql.DataSource createDataSource​(java.util.Properties properties)
      Creates a basic data source.
      java.sql.Driver createDriver​(java.util.Properties properties)
      Returns a driver.
      javax.sql.XADataSource createXADataSource​(java.util.Properties properties)
      Creates a pooled XA data source.
      (package private) static void registerService​(org.osgi.framework.BundleContext bundleContext, Driver driver)
      Register the H2 JDBC driver service.
      private static void rejectPoolingOptions​(java.util.Properties p)
      Checker method that will throw if any pooling related standard OSGi options are present.
      private static void rejectUnsupportedOptions​(java.util.Properties p)
      Checker method that will throw if any unsupported standard OSGi options is present.
      private static void setupH2DataSource​(JdbcDataSource dataSource, java.util.Properties p)
      Applies common OSGi properties to a H2 data source.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • driver

        private final Driver driver
    • Constructor Detail

      • OsgiDataSourceFactory

        public OsgiDataSourceFactory​(Driver driver)
    • Method Detail

      • createDataSource

        public javax.sql.DataSource createDataSource​(java.util.Properties properties)
                                              throws java.sql.SQLException
        Creates a basic data source.
        Specified by:
        createDataSource in interface org.osgi.service.jdbc.DataSourceFactory
        Parameters:
        properties - the properties for the data source.
        Returns:
        a new data source.
        Throws:
        java.sql.SQLException - if unsupported properties are supplied, or if data source can not be created.
      • createConnectionPoolDataSource

        public javax.sql.ConnectionPoolDataSource createConnectionPoolDataSource​(java.util.Properties properties)
                                                                          throws java.sql.SQLException
        Creates a pooled data source.
        Specified by:
        createConnectionPoolDataSource in interface org.osgi.service.jdbc.DataSourceFactory
        Parameters:
        properties - the properties for the data source.
        Returns:
        a new data source.
        Throws:
        java.sql.SQLException - if unsupported properties are supplied, or if data source can not be created.
      • createXADataSource

        public javax.sql.XADataSource createXADataSource​(java.util.Properties properties)
                                                  throws java.sql.SQLException
        Creates a pooled XA data source.
        Specified by:
        createXADataSource in interface org.osgi.service.jdbc.DataSourceFactory
        Parameters:
        properties - the properties for the data source.
        Returns:
        a new data source.
        Throws:
        java.sql.SQLException - if unsupported properties are supplied, or if data source can not be created.
      • createDriver

        public java.sql.Driver createDriver​(java.util.Properties properties)
                                     throws java.sql.SQLException
        Returns a driver. The H2 driver does not support any properties.
        Specified by:
        createDriver in interface org.osgi.service.jdbc.DataSourceFactory
        Parameters:
        properties - must be null or empty list.
        Returns:
        a driver.
        Throws:
        java.sql.SQLException - if any property is supplied.
      • rejectUnsupportedOptions

        private static void rejectUnsupportedOptions​(java.util.Properties p)
                                              throws java.sql.SQLFeatureNotSupportedException
        Checker method that will throw if any unsupported standard OSGi options is present.
        Parameters:
        p - the properties to check
        Throws:
        java.sql.SQLFeatureNotSupportedException - if unsupported properties are present
      • setupH2DataSource

        private static void setupH2DataSource​(JdbcDataSource dataSource,
                                              java.util.Properties p)
        Applies common OSGi properties to a H2 data source. Non standard properties will be applied as H2 options.
        Parameters:
        dataSource - the data source to configure
        p - the properties to apply to the data source
      • rejectPoolingOptions

        private static void rejectPoolingOptions​(java.util.Properties p)
                                          throws java.sql.SQLFeatureNotSupportedException
        Checker method that will throw if any pooling related standard OSGi options are present.
        Parameters:
        p - the properties to check
        Throws:
        java.sql.SQLFeatureNotSupportedException - if unsupported properties are present
      • registerService

        static void registerService​(org.osgi.framework.BundleContext bundleContext,
                                    Driver driver)
        Register the H2 JDBC driver service.
        Parameters:
        bundleContext - the bundle context
        driver - the driver