void init ( ) { if ( dataSource == null ) { if ( connectionType . equals ( ConnectionType . POOLED ) ) { HikariConfig config = new HikariConfig ( ) ; config . setMaximumPoolSize ( maximumPoolSize ) ; config . setDataSourceClassName ( dataSourceClass ) ; config . addDataSourceProperty ( "url" , url ) ; config . addDataSourceProperty ( "user" , user ) ; config . addDataSourceProperty ( "password" , password ) ; config . setPoolName ( CONNECTION_POOL_NAME ) ; config . setAutoCommit ( autoCommit ) ; config . setMaximumPoolSize ( maximumPoolSize ) ; // config.setConnectionTestQuery("SELECT 1"); if ( connectionTimeout != null ) { config . setConnectionTimeout ( connectionTimeout ) ; } if ( idleTimeout != null ) { config . setIdleTimeout ( idleTimeout ) ; } if ( maxLifetime != null ) { config . setMaxLifetime ( maxLifetime ) ; } if ( minimumIdle != null ) { config . setMinimumIdle ( minimumIdle ) ; } ds = new HikariDataSource ( config ) ; dataSource = ds ; } else if ( connectionType . equals ( ConnectionType . JNDI ) ) { if ( null == jndiDataSource ) { throw new InitializationException ( "Could not obtain the db connection: jndi data source is null" ) ; } String DATASOURCE_CONTEXT = jndiDataSource ; try { Context initialContext = new InitialContext ( ) ; dataSource = ( DataSource ) initialContext . lookup ( DATASOURCE_CONTEXT ) ; if ( dataSource == null ) { Log . error ( "Failed to lookup datasource." ) ; throw new InitializationException ( "Could not obtain the db connection: Failed to lookup datasource: " + jndiDataSource ) ; } } catch ( NamingException ex ) { throw new InitializationException ( "Could not obtain the db connection: jndi lookup failed" , ex ) ; } } } }
initialize connection factory . This will created the necessary connection pools and jndi lookups in advance .