Skip to content

Commit

Permalink
[PDI-13633] - Adding a fallback logic to connect the datasource using
Browse files Browse the repository at this point in the history
class if JNDI lookup fails
  • Loading branch information
rmansoor committed May 23, 2015
1 parent 7893eba commit be0fdc5
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions core/src/org/pentaho/di/core/database/Database.java
Expand Up @@ -399,15 +399,18 @@ public void normalConnect( String partitionId ) throws KettleDatabaseException {
}
} else if ( databaseMeta.getAccessType() == DatabaseMeta.TYPE_ACCESS_JNDI ) {
final String jndiName = environmentSubstitute( databaseMeta.getDatabaseName() );
connectUsingJNDIDataSource( jndiName );
} else {
// TODO connectUsingNamedDataSource can be called here but the current implementation of
// org.pentaho.platform.plugin.action.kettle.PlatformKettleDataSourceProvider can cause collision of name and
// JNDI name. See also [PDI-13633], [SP-1776].
connectUsingClass( databaseMeta.getDriverClass(), partitionId );
if ( log.isDetailed() ) {
log.logDetailed( "Connected to database." );
try {
connectUsingJNDIDataSource( jndiName );
} catch ( KettleDatabaseException kde ) {
// This was a new path that was added. If in case we did not find this datasource in JNDI,
// we were throwing exception and exiting out of this method. We will attempt to load this datasource
// using the classs if JNDI lookup fail. This is how it was working in 5.3
log.logDetailed( "Unable to find datasource using JNDI. Cause: " + kde.getLocalizedMessage() );
log.logDetailed( "Attempting to connect using the class" );
connectUsingClass();
}
} else {
connectUsingClass();
}
// See if we need to execute extra SQL statement...
String sql = environmentSubstitute( databaseMeta.getConnectSQL() );
Expand Down Expand Up @@ -4673,4 +4676,14 @@ public void setForcingSeparateLogging( boolean forcingSeparateLogging ) {
log.setForcingSeparateLogging( forcingSeparateLogging );
}
}

private void connectUsingClass() throws KettleDatabaseException{
// TODO connectUsingNamedDataSource can be called here but the current implementation of
// org.pentaho.platform.plugin.action.kettle.PlatformKettleDataSourceProvider can cause collision of name and
// JNDI name. See also [PDI-13633], [SP-1776].
connectUsingClass( databaseMeta.getDriverClass(), partitionId );
if ( log.isDetailed() ) {
log.logDetailed( "Connected to database." );
}
}
}

0 comments on commit be0fdc5

Please sign in to comment.