Java Code Examples for org.osgi.service.jdbc.DataSourceFactory

The following examples show how to use org.osgi.service.jdbc.DataSourceFactory. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: incubator-iotdb   Source File: IoTDbDataSourceFactory.java    License: Apache License 2.0 6 votes vote down vote up
public void setProperties(IoTDBDataSource ds, Properties prop){
    Properties properties = (Properties)prop.clone();
    String url = (String)properties.remove(DataSourceFactory.JDBC_URL);
    if(url!=null){
        ds.setUrl(url);
        logger.info("URL set {}",url);
    }

    String user = (String) properties.remove(DataSourceFactory.JDBC_USER);
    ds.setUser(user);
    logger.info("User set {}",user);


    String password = (String) properties.remove(DataSourceFactory.JDBC_PASSWORD);
    ds.setPassword(password);
    logger.info("Password set {}",password);


    logger.info("Remaining properties {}", properties.size());

    if (!properties.isEmpty()) {
        BeanConfig.configure(ds, properties);
    }
}
 
Example 2
Source Project: neoscada   Source File: Activator.java    License: Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void start ( final BundleContext context ) throws Exception
{
    this.scheduler = Executors.newSingleThreadScheduledExecutor ( new NamedThreadFactory ( context.getBundle ().getSymbolicName () ) );
    final String driver = DataSourceHelper.getDriver ( DS_PREFIX, DataSourceHelper.DEFAULT_PREFIX );

    if ( driver == null )
    {
        logger.error ( "JDBC driver is not set" );
        throw new IllegalStateException ( "JDBC driver name is not set" );
    }

    this.dataSourceFactoryTracker = new DataSourceFactoryTracker ( context, driver, new SingleServiceListener<DataSourceFactory> () {

        @Override
        public void serviceChange ( final ServiceReference<DataSourceFactory> reference, final DataSourceFactory service )
        {
            unregister ();
            if ( service != null )
            {
                register ( service, context );
            }
        }
    } );
    this.dataSourceFactoryTracker.open ( true );
}
 
Example 3
Source Project: neoscada   Source File: EventInjector.java    License: Eclipse Public License 1.0 6 votes vote down vote up
public EventInjector ( final DataSourceFactory factory, final Properties properties, final int delay, final Long loginTimeout ) throws SQLException
{
    logger.info ( "Starting event injector" ); //$NON-NLS-1$
    this.storage = new JdbcStorageDao ( factory, properties, false, loginTimeout, null );

    if ( !System.getProperty ( Activator.SPECIFIC_PREFIX + ".schema", "" ).trim ().isEmpty () )
    {
        this.storage.setSchema ( System.getProperty ( Activator.SPECIFIC_PREFIX + ".schema" ) + "." );
    }

    this.scheduler = new ScheduledExportedExecutorService ( "org.eclipse.scada.ae.slave.inject", 1 ); //$NON-NLS-1$

    this.scheduler.scheduleWithFixedDelay ( new Runnable () {

        @Override
        public void run ()
        {
            process ();
        }
    }, 0, delay, TimeUnit.MILLISECONDS );
}
 
Example 4
Source Project: neoscada   Source File: Activator.java    License: Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void start ( final BundleContext bundleContext ) throws Exception
{
    Activator.context = bundleContext;

    final String driver = DataSourceHelper.getDriver ( SPECIFIC_PREFIX, DataSourceHelper.DEFAULT_PREFIX );

    if ( driver == null )
    {
        logger.error ( "JDBC driver is not set" );
        throw new IllegalStateException ( "JDBC driver name is not set" );
    }

    this.tracker = new DataSourceFactoryTracker ( bundleContext, driver, new SingleServiceListener<DataSourceFactory> () {

        @Override
        public void serviceChange ( final ServiceReference<DataSourceFactory> reference, final DataSourceFactory service )
        {
            setService ( service );
        }
    } );
    this.tracker.open ();
}
 
Example 5
Source Project: neoscada   Source File: Activator.java    License: Eclipse Public License 1.0 6 votes vote down vote up
protected void setService ( final DataSourceFactory service )
{
    if ( this.injector != null )
    {
        this.injector.dispose ();
        this.injector = null;
    }

    if ( service != null )
    {
        try
        {
            final Long loginTimeout = DataSourceHelper.getLoginTimeout ( System.getProperties (), SPECIFIC_PREFIX, DataSourceHelper.DEFAULT_PREFIX );
            this.injector = new EventInjector ( service, DataSourceHelper.getDataSourceProperties ( SPECIFIC_PREFIX, DataSourceHelper.DEFAULT_PREFIX ), Integer.getInteger ( SPECIFIC_PREFIX + ".loopDelay", 10 * 1000 ), loginTimeout );
        }
        catch ( final SQLException e )
        {
            logger.warn ( "Failed to start event injector", e ); //$NON-NLS-1$
        }
    }
}
 
Example 6
Source Project: neoscada   Source File: Activator.java    License: Eclipse Public License 1.0 6 votes vote down vote up
private void activate ( final DataSourceFactory dataSourceFactory ) throws Exception
{
    logger.info ( "Activating: {}", dataSourceFactory );

    final Properties dbProperties = DataSourceHelper.getDataSourceProperties ( SPECIFIC_PREFIX, DataSourceHelper.DEFAULT_PREFIX );

    final Long loginTimeout = DataSourceHelper.getLoginTimeout ( System.getProperties (), SPECIFIC_PREFIX, DataSourceHelper.DEFAULT_PREFIX );
    this.jdbcStorage = createJdbcStorage ( dataSourceFactory, dbProperties, DataSourceHelper.isConnectionPool ( SPECIFIC_PREFIX, DataSourceHelper.DEFAULT_PREFIX, false ), loginTimeout );
    this.jdbcStorage.start ();

    final Dictionary<String, Object> properties = new Hashtable<String, Object> ( 2 );
    properties.put ( Constants.SERVICE_DESCRIPTION, "JDBC implementation for org.eclipse.scada.ae.server.storage.Storage" );
    properties.put ( Constants.SERVICE_VENDOR, "Eclipse SCADA Project" );
    properties.put ( "osgi.command.scope", "ae" );
    properties.put ( "osgi.command.function", new String[] { "cleanupArchive", "showQueueSize" } );
    this.jdbcStorageHandle = context.registerService ( new String[] { JdbcStorage.class.getName (), Storage.class.getName () }, this.jdbcStorage, properties );
}
 
Example 7
Source Project: neoscada   Source File: EventInjector.java    License: Eclipse Public License 1.0 6 votes vote down vote up
public EventInjector ( final DataSourceFactory dataSourceFactory, final Properties dataSourceProperties, final Integer delay, final boolean usePool, final Long loginTimeout, final String schema, final String replicationSchema, final String instance ) throws SQLException
{
    logger.info ( "Starting event injector" ); //$NON-NLS-1$
    this.schema = schema;
    this.replicationSchema = replicationSchema;
    this.accessor = usePool ? new PoolConnectionAccessor ( dataSourceFactory, dataSourceProperties ) : new DataSourceConnectionAccessor ( dataSourceFactory, dataSourceProperties, loginTimeout );
    this.jdbcDao = new JdbcDao ( this.accessor, schema, instance, new NodeIdProvider () {
        @Override
        public String getNodeId ()
        {
            return EventInjector.this.getNodeId ();
        }
    } );
    this.scheduler = new ScheduledExportedExecutorService ( "org.eclipse.scada.ae.slave.inject.postgres", 1 ); //$NON-NLS-1$

    this.scheduler.scheduleWithFixedDelay ( new Runnable () {

        @Override
        public void run ()
        {
            process ();
        }
    }, 0, delay, TimeUnit.MILLISECONDS );
}
 
Example 8
Source Project: neoscada   Source File: Activator.java    License: Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void start ( final BundleContext bundleContext ) throws Exception
{
    Activator.context = bundleContext;

    final String driver = DataSourceHelper.getDriver ( SPECIFIC_PREFIX, DataSourceHelper.DEFAULT_PREFIX );

    if ( driver == null )
    {
        logger.error ( "JDBC driver is not set" );
        throw new IllegalStateException ( "JDBC driver name is not set" );
    }

    this.tracker = new DataSourceFactoryTracker ( bundleContext, driver, new SingleServiceListener<DataSourceFactory> () {

        @Override
        public void serviceChange ( final ServiceReference<DataSourceFactory> reference, final DataSourceFactory service )
        {
            setService ( service );
        }
    } );
    this.tracker.open ();
}
 
Example 9
Source Project: neoscada   Source File: Activator.java    License: Eclipse Public License 1.0 6 votes vote down vote up
protected void setService ( final DataSourceFactory service )
{
    if ( this.injector != null )
    {
        this.injector.dispose ();
        this.injector = null;
    }

    if ( service != null )
    {
        try
        {
            final String schema = getSchema ();
            final String replicationSchema = getReplicationSchema ();
            final String instance = getInstance ();
            final Long loginTimeout = DataSourceHelper.getLoginTimeout ( System.getProperties (), SPECIFIC_PREFIX, DataSourceHelper.DEFAULT_PREFIX );
            final boolean usePool = DataSourceHelper.isConnectionPool ( SPECIFIC_PREFIX, DataSourceHelper.DEFAULT_PREFIX, false );
            this.injector = new EventInjector ( service, DataSourceHelper.getDataSourceProperties ( SPECIFIC_PREFIX, DataSourceHelper.DEFAULT_PREFIX ), Integer.getInteger ( SPECIFIC_PREFIX + ".loopDelay", 10 * 1000 ), usePool, loginTimeout, schema, replicationSchema, instance );
        }
        catch ( final SQLException e )
        {
            logger.warn ( "Failed to start event injector", e ); //$NON-NLS-1$
        }
    }
}
 
Example 10
Source Project: neoscada   Source File: Activator.java    License: Eclipse Public License 1.0 6 votes vote down vote up
private void activate ( final DataSourceFactory dataSourceFactory ) throws Exception
{
    logger.debug ( "Activate storage" );
    this.scheduler = ScheduledExportedExecutorService.newSingleThreadExportedScheduledExecutor ( "org.eclipse.scada.ae.server.storage.postgresql/ScheduledExecutor" );

    final Properties dbProperties = DataSourceHelper.getDataSourceProperties ( SPECIFIC_PREFIX, DataSourceHelper.DEFAULT_PREFIX );

    final String schema = getSchema ();
    final String instance = getInstance ();
    this.jdbcStorage = new JdbcStorage ( dataSourceFactory, this.scheduler, dbProperties, DataSourceHelper.isConnectionPool ( SPECIFIC_PREFIX, DataSourceHelper.DEFAULT_PREFIX, false ), schema, instance );
    this.jdbcStorage.start ();

    final Dictionary<String, Object> properties = new Hashtable<String, Object> ( 2 );
    properties.put ( Constants.SERVICE_DESCRIPTION, "PostgreSQL specific JDBC implementation for org.eclipse.scada.ae.server.storage.Storage" );
    properties.put ( Constants.SERVICE_VENDOR, "Eclipse SCADA Project" );
    this.jdbcStorageHandle = context.registerService ( new String[] { JdbcStorage.class.getName (), Storage.class.getName () }, this.jdbcStorage, properties );
    logger.debug ( "Storage activated - {}", this.jdbcStorageHandle );
}
 
Example 11
Source Project: incubator-iotdb   Source File: Activator.java    License: Apache License 2.0 5 votes vote down vote up
public void start(BundleContext context) {
    IoTDbDataSourceFactory dsf = new IoTDbDataSourceFactory();
    Dictionary<String, String> props = new Hashtable<String, String>();
    props.put(DataSourceFactory.OSGI_JDBC_DRIVER_CLASS, IoTDBDriver.class.getName());
    props.put(DataSourceFactory.OSGI_JDBC_DRIVER_NAME, "iotdb");
    context.registerService(DataSourceFactory.class.getName(), dsf, props);
}
 
Example 12
Source Project: neoscada   Source File: JdbcStorageDaoBase64Impl.java    License: Eclipse Public License 1.0 5 votes vote down vote up
public JdbcStorageDaoBase64Impl ( final DataSourceFactory dataSourceFactory, final Properties paramProperties, final boolean usePool ) throws SQLException
{
    this.accessor = usePool ? new PoolConnectionAccessor ( dataSourceFactory, paramProperties ) : new DataSourceConnectionAccessor ( dataSourceFactory, paramProperties );
    if ( this.chunkSize <= 0 )
    {
        this.chunkSize = Integer.MAX_VALUE;
    }
}
 
Example 13
Source Project: neoscada   Source File: Activator.java    License: Eclipse Public License 1.0 5 votes vote down vote up
protected void register ( final DataSourceFactory service, final BundleContext context )
{
    JdbcStorageDao storage = null;

    try
    {
        switch ( getType () )
        {
            case BLOB:
                logger.info ( "Registering BLOB implemenation" );
                storage = configure ( new JdbcStorageDaoBlobImpl ( service, getDataSourceProperties (), isConnectionPool () ) );
                break;
            case BASE64:
                logger.info ( "Registering BASE64 implemenation" );
                storage = configure ( new JdbcStorageDaoBase64Impl ( service, getDataSourceProperties (), isConnectionPool () ) );
                break;
        }
    }
    catch ( final Exception e )
    {
        logger.error ( "Failed to create service", e );
    }

    if ( storage != null )
    {
        this.storageImpl = new StorageImpl ( storage );

        final Dictionary<String, Object> properties = new Hashtable<String, Object> ( 1 );
        properties.put ( Constants.SERVICE_VENDOR, "Eclipse SCADA Project" );
        this.serviceHandle = context.registerService ( org.eclipse.scada.ds.DataStore.class, this.storageImpl, properties );
    }
}
 
Example 14
/**
 * @since 0.2.0
 */
public DataSourceConnectionAccessor ( final DataSourceFactory dataSourceFactory, final Properties paramProperties, final Long loginTimeout ) throws SQLException
{
    logger.debug ( "Creating default data source accessor" );
    this.dataSource = dataSourceFactory.createDataSource ( paramProperties );

    if ( loginTimeout != null && loginTimeout > 0 )
    {
        this.dataSource.setLoginTimeout ( (int) ( loginTimeout / 1000 ) );
    }
}
 
Example 15
Source Project: neoscada   Source File: PullManager.java    License: Eclipse Public License 1.0 5 votes vote down vote up
public void runOnce () throws SQLException
{
    final DataSourceFactory localFactory = this.tracker.getService ();
    if ( localFactory == null )
    {
        throw new IllegalStateException ( String.format ( "Failed to get local data source factory - %s", this.tracker.getDriver () ) );
    }

    final Properties properties = DataSourceHelper.getDataSourceProperties ( SPECIFIC_PREFIX, DataSourceHelper.DEFAULT_PREFIX );

    logger.debug ( "Opening database connection for local: {}", properties );

    final DataSourceConnectionAccessor accessor = new DataSourceConnectionAccessor ( localFactory, properties );
    try
    {
        accessor.doWithConnection ( new CommonConnectionTask<Void> () {
            @Override
            protected Void performTask ( final ConnectionContext connectionContext ) throws Exception
            {
                processSites ( connectionContext );
                return null;
            }
        } );

    }
    finally
    {
        accessor.dispose ();
    }
}
 
Example 16
Source Project: neoscada   Source File: PullManager.java    License: Eclipse Public License 1.0 5 votes vote down vote up
private void processSite ( final Site site, final ConnectionContext localContext ) throws Exception
{
    logger.info ( "Processing site: {}", site.getId () );

    final DataSourceFactoryTracker tracker = this.dataSourceFactoryTrackers.get ( site.getDriverName () );
    if ( tracker == null )
    {
        throw new IllegalStateException ( "Site is configured but has not data source factory tracker" );
    }

    final DataSourceFactory factory = tracker.getService ();
    if ( factory == null )
    {
        throw new IllegalStateException ( String.format ( "Site's driver could not be found - %s", site.getDriverName () ) );
    }

    final DataSourceConnectionAccessor accessor = new DataSourceConnectionAccessor ( factory, site.getProperties () );
    try
    {
        accessor.doWithConnection ( new CommonConnectionTask<Void> () {

            @Override
            protected Void performTask ( final ConnectionContext context ) throws Exception
            {
                transferSite ( site, localContext, context );
                return null;
            }
        } );
    }
    finally
    {
        accessor.dispose ();
    }
}
 
Example 17
Source Project: neoscada   Source File: Activator.java    License: Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void start ( final BundleContext context ) throws Exception
{
    final String driver = DataSourceHelper.getDriver ( CA_PREFIX, DataSourceHelper.DEFAULT_PREFIX );

    if ( driver == null )
    {
        logger.error ( "JDBC driver is not set" );
        throw new IllegalStateException ( "JDBC driver name is not set" );
    }

    this.dataSourceFactoryTracker = new DataSourceFactoryTracker ( context, driver, new SingleServiceListener<DataSourceFactory> () {

        @Override
        public void serviceChange ( final ServiceReference<DataSourceFactory> reference, final DataSourceFactory service )
        {
            unregister ();
            if ( service != null )
            {
                try
                {
                    register ( service, context );
                }
                catch ( final Exception e )
                {
                    logger.error ( "Failed to start configuration administrator", e );
                }
            }
        }
    } );
    this.dataSourceFactoryTracker.open ( true );
}
 
Example 18
Source Project: neoscada   Source File: Activator.java    License: Eclipse Public License 1.0 5 votes vote down vote up
protected void register ( final DataSourceFactory service, final BundleContext context ) throws Exception
{
    logger.info ( "Registering services - service: {}, context: {}", service, context );

    this.storage = new JdbcStorageDAOImpl ( service, getDataSourceProperties (), isConnectionPool () );

    final ConfigurationAdministratorImpl configAdmin = new ConfigurationAdministratorImpl ( context, this.storage );
    try
    {
        configAdmin.start ();
    }
    catch ( final Exception e )
    {
        logger.warn ( "Failed to start CA", e );

        try
        {
            configAdmin.dispose ();
        }
        catch ( final Exception e2 )
        {
            logger.warn ( "Failed to early dispose CA after error", e2 );
        }

        throw new InvocationTargetException ( e );
    }

    // started ... now announce
    this.configAdmin = configAdmin;

    final Dictionary<String, Object> properties = new Hashtable<String, Object> ( 2 );
    properties.put ( Constants.SERVICE_VENDOR, "Eclipse SCADA Project" );
    properties.put ( Constants.SERVICE_DESCRIPTION, "A JDBC based configuration administrator" );

    this.serviceHandle = context.registerService ( new String[] { ConfigurationAdministrator.class.getName (), FreezableConfigurationAdministrator.class.getName () }, this.configAdmin, properties );
}
 
Example 19
Source Project: neoscada   Source File: JdbcStorageDao.java    License: Eclipse Public License 1.0 5 votes vote down vote up
public JdbcStorageDao ( final DataSourceFactory dataSourceFactory, final Properties properties, final boolean usePool, final Long loginTimeout, final Interner<String> stringInterner ) throws SQLException
{
    super ( dataSourceFactory, properties, usePool, loginTimeout, stringInterner );

    this.executor = Executors.newSingleThreadScheduledExecutor ( new NamedThreadFactory ( "org.eclipse.scada.ae.server.storage.jdbc/CleanupThread" ) );
    this.executor.scheduleWithFixedDelay ( new Runnable () {

        @Override
        public void run ()
        {
            cleanupArchive ();
        }
    }, getCleanupPeriod (), getCleanupPeriod (), TimeUnit.SECONDS );
}
 
Example 20
Source Project: neoscada   Source File: Activator.java    License: Eclipse Public License 1.0 5 votes vote down vote up
private JdbcStorage createJdbcStorage ( final DataSourceFactory dataSourceFactory, final Properties dbParameters, final boolean usePool, final Long loginTimeout ) throws SQLException
{
    final AbstractJdbcStorageDao jdbcStorageDao = new JdbcStorageDao ( dataSourceFactory, dbParameters, usePool, loginTimeout, this.stringInterner );
    jdbcStorageDao.setInstance ( System.getProperty ( "org.eclipse.scada.ae.server.storage.jdbc.instance", "default" ) );
    jdbcStorageDao.setMaxLength ( Integer.getInteger ( "org.eclipse.scada.ae.server.storage.jdbc.maxlength", this.maxLength ) );
    if ( !System.getProperty ( "org.eclipse.scada.ae.server.storage.jdbc.schema", "" ).trim ().isEmpty () )
    {
        jdbcStorageDao.setSchema ( System.getProperty ( "org.eclipse.scada.ae.server.storage.jdbc.schema" ) + "." );
    }
    return new JdbcStorage ( jdbcStorageDao );
}
 
Example 21
Source Project: neoscada   Source File: JdbcValueMapper.java    License: Eclipse Public License 1.0 5 votes vote down vote up
protected void performReload () throws Exception
{
    final Configuration configuration = this.configuration;

    final Map<String, String> newData;

    final DataSourceFactoryTracker tracker = new DataSourceFactoryTracker ( this.context, configuration.jdbcDriver, null );

    try
    {
        tracker.open ();
        final DataSourceFactory factory = tracker.waitForService ( configuration.serviceTimeout );

        final DataSourceConnectionAccessor accessor = new DataSourceConnectionAccessor ( factory, configuration.jdbcProperties );
        accessor.getDataSource ().setLoginTimeout ( configuration.loginTimeout );
        newData = accessor.doWithConnection ( new CommonConnectionTask<Map<String, String>> () {

            @Override
            protected Map<String, String> performTask ( final ConnectionContext connectionContext ) throws Exception
            {
                return doReload ( configuration, connectionContext );
            }
        } );
    }
    finally
    {
        tracker.close ();
    }

    configure ( newData, configuration.defaultValue );
}
 
Example 22
private void attach () throws InvalidSyntaxException
{
    logger.debug ( "Creating data source tracker: {}", this.driver );
    this.tracker = new DataSourceFactoryTracker ( this.context, this.driver, new SingleServiceListener<DataSourceFactory> () {

        @Override
        public void serviceChange ( final ServiceReference<DataSourceFactory> reference, final DataSourceFactory service )
        {
            setDataSource ( service );
        }
    } );
    this.tracker.open ();
}
 
Example 23
protected void setDataSource ( final DataSourceFactory service )
{
    logger.debug ( "Setting data source: {}", service );
    try
    {
        this.writeLock.lock ();

        if ( this.accessor != null )
        {
            this.accessor.dispose ();
            this.accessor = null;
        }

        try
        {
            if ( service != null )
            {
                this.accessor = new DataSourceConnectionAccessor ( service, this.connectionProperties );
            }
        }
        catch ( final SQLException e )
        {
            logger.error ( "Failed to create datasource for " + this.id, e );
        }
    }
    finally
    {
        this.writeLock.unlock ();
    }
}
 
Example 24
Source Project: neoscada   Source File: JdbcStorage.java    License: Eclipse Public License 1.0 5 votes vote down vote up
public JdbcStorage ( final DataSourceFactory dataSourceFactory, final ScheduledExecutorService scheduler, final Properties dbProperties, final boolean usePool, final String schema, final String instance ) throws SQLException
{
    super ();
    this.accessor = usePool ? new PoolConnectionAccessor ( dataSourceFactory, dbProperties ) : new DataSourceConnectionAccessor ( dataSourceFactory, dbProperties );
    this.jdbcDao = new JdbcDao ( this.accessor, schema, instance, new NodeIdProvider () {
        @Override
        public String getNodeId ()
        {
            return JdbcStorage.this.getNodeId ();
        }
    } );
    this.scheduler = scheduler;
    this.dbExecutor = ExportedExecutorService.newSingleThreadExportedExecutor ( "AE.JdbcStorage" );
}
 
Example 25
@Override
public void start(BundleContext context) throws Exception {
  Dictionary<String, Object> properties = new Hashtable<>();
  properties.put(DataSourceFactory.OSGI_JDBC_DRIVER_CLASS, Driver.class.getName());
  properties.put(DataSourceFactory.OSGI_JDBC_DRIVER_NAME, MariaDbDatabaseMetaData.DRIVER_NAME);
  properties.put(DataSourceFactory.OSGI_JDBC_DRIVER_VERSION, Version.version);
  service =
      context.registerService(
          DataSourceFactory.class, new MariaDbDataSourceFactory(), properties);
}
 
Example 26
Source Project: neoscada   Source File: JdbcStorageDaoBlobImpl.java    License: Eclipse Public License 1.0 4 votes vote down vote up
public JdbcStorageDaoBlobImpl ( final DataSourceFactory dataSourceFactory, final Properties paramProperties, final boolean usePool ) throws SQLException
{
    this.accessor = usePool ? new PoolConnectionAccessor ( dataSourceFactory, paramProperties ) : new DataSourceConnectionAccessor ( dataSourceFactory, paramProperties );
}
 
Example 27
Source Project: neoscada   Source File: PoolConnectionAccessor.java    License: Eclipse Public License 1.0 4 votes vote down vote up
public PoolConnectionAccessor ( final DataSourceFactory dataSourceFactory, final Properties paramProperties ) throws SQLException
{
    logger.debug ( "Creating pool connection accessor : {}", paramProperties );

    // first remove all our properties

    this.connectionPool = new GenericObjectPool<Object> ( null );
    this.connectionPool.setMaxActive ( getInteger ( paramProperties, PREFIX + "maxActive", 8 ) );
    this.connectionPool.setMaxIdle ( getInteger ( paramProperties, PREFIX + "maxIdle", 8 ) );
    this.connectionPool.setMinIdle ( getInteger ( paramProperties, PREFIX + "minIdle", 1 ) );
    this.connectionPool.setTestOnBorrow ( getBoolean ( paramProperties, PREFIX + "testOnBorrow", true ) );
    this.connectionPool.setTestOnReturn ( getBoolean ( paramProperties, PREFIX + "testOnReturn", true ) );

    this.connectionPool.setTimeBetweenEvictionRunsMillis ( getLong ( paramProperties, PREFIX + "timeBetweenEvictionRunsMillis", -1 ) );
    this.connectionPool.setMinEvictableIdleTimeMillis ( getLong ( paramProperties, PREFIX + "minEvictableIdleTimeMillis", 30 * 60 * 1000 ) );
    this.connectionPool.setTestWhileIdle ( getBoolean ( paramProperties, PREFIX + "testWhileIdle", false ) );
    this.connectionPool.setSoftMinEvictableIdleTimeMillis ( getLong ( paramProperties, PREFIX + "softMinEvictableIdleTimeMillis", -1 ) );
    this.connectionPool.setNumTestsPerEvictionRun ( getInteger ( paramProperties, PREFIX + "numTestsPerEvictionRun", 3 ) );

    final String connectionInitSql = getString ( paramProperties, PREFIX + "connectionInitSql", null );
    final String validationQuery = getString ( paramProperties, PREFIX + "validationQuery", null );
    final Integer validationQueryTimeout = getInteger ( paramProperties, PREFIX + "validationQueryTimeout", -1 );

    this.driverDataSource = dataSourceFactory.createDataSource ( paramProperties );

    final ConnectionFactory connectionFactory = new DataSourceConnectionFactory ( this.driverDataSource );
    this.poolableConnectionFactory = new PoolableConnectionFactory ( connectionFactory, this.connectionPool, null, null, false, true );

    if ( connectionInitSql != null )
    {
        this.poolableConnectionFactory.setConnectionInitSql ( Arrays.asList ( connectionInitSql ) );
    }
    if ( validationQuery != null )
    {
        this.poolableConnectionFactory.setValidationQuery ( validationQuery );
    }
    if ( validationQueryTimeout != null )
    {
        this.poolableConnectionFactory.setValidationQueryTimeout ( validationQueryTimeout );
    }

    this.dataSource = new PoolingDataSource ( this.connectionPool );
}
 
Example 28
public DataSourceConnectionAccessor ( final DataSourceFactory dataSourceFactory, final Properties paramProperties ) throws SQLException
{
    this ( dataSourceFactory, paramProperties, null );
}
 
Example 29
Source Project: neoscada   Source File: DataSourceFactoryTracker.java    License: Eclipse Public License 1.0 4 votes vote down vote up
public DataSourceFactoryTracker ( final BundleContext context, final String driver, final SingleServiceListener<DataSourceFactory> listener ) throws InvalidSyntaxException
{
    super ( context, context.createFilter ( "(&(objectClass=" + DataSourceFactory.class.getName () + ")(" + DataSourceFactory.OSGI_JDBC_DRIVER_CLASS + "=" + driver + "))" ), listener );
    this.driver = driver;
}
 
Example 30
Source Project: neoscada   Source File: DataSourceFactoryTracker.java    License: Eclipse Public License 1.0 4 votes vote down vote up
public DataSourceFactoryTracker ( final BundleContext context, final String driver, final SingleServiceListener<DataSourceFactory> listener, final boolean isConnectionPool ) throws InvalidSyntaxException
{
    super ( context, context.createFilter ( "(&(objectClass=" + DataSourceFactory.class.getName () + ")(" + DataSourceFactory.OSGI_JDBC_DRIVER_CLASS + "=" + driver + ")(isConnectionPool=" + isConnectionPool + "))" ), listener );
    this.driver = driver;
}