use of org.pentaho.di.core.database.DatabaseInterface in project pentaho-kettle by pentaho.
the class DatabaseLogExceptionFactoryTest method testExceptionStrategyWithPacketTooBigExceptionPropSetY.
/**
* Property value has priority
*/
@Test
public void testExceptionStrategyWithPacketTooBigExceptionPropSetY() {
System.setProperty(DatabaseLogExceptionFactory.KETTLE_GLOBAL_PROP_NAME, PROPERTY_VALUE_TRUE);
DatabaseMeta databaseMeta = mock(DatabaseMeta.class);
DatabaseInterface databaseInterface = new MySQLDatabaseMeta();
PacketTooBigException e = new PacketTooBigException();
when(logTable.getDatabaseMeta()).thenReturn(databaseMeta);
when(databaseMeta.getDatabaseInterface()).thenReturn(databaseInterface);
LogExceptionBehaviourInterface exceptionStrategy = DatabaseLogExceptionFactory.getExceptionStrategy(logTable, new KettleDatabaseException(e));
String strategyName = exceptionStrategy.getClass().getName();
assertEquals(THROWABLE, strategyName);
}
use of org.pentaho.di.core.database.DatabaseInterface in project pentaho-platform by pentaho.
the class SqlMetadataQueryExec method getActiveDatabaseMeta.
protected DatabaseMeta getActiveDatabaseMeta(DatabaseMeta databaseMeta) {
if (getForceDbDialect() || driverClassesToForceMeta.contains(databaseMeta.getDriverClass())) {
return databaseMeta;
}
// retrieve a temporary connection to determine if a dialect change is necessary
// for generating the MQL Query.
SQLConnection tempConnection = getConnection(databaseMeta);
try {
// if the connection type is not of the current dialect, regenerate the query
DatabaseInterface di = getDatabaseInterface(tempConnection);
if ((di != null) && (!databaseMeta.getPluginId().equals(di.getPluginId()))) {
// we need to reinitialize our mqlQuery object and reset the query.
// note that using this di object wipes out connection info
DatabaseMeta meta = (DatabaseMeta) databaseMeta.clone();
DatabaseInterface di2 = (DatabaseInterface) di.clone();
di2.setAccessType(databaseMeta.getAccessType());
di2.setDatabaseName(databaseMeta.getDatabaseName());
di2.setAttributes(databaseMeta.getAttributes());
di2.setUsername(databaseMeta.getUsername());
di2.setPassword(databaseMeta.getPassword());
di2.setHostname(databaseMeta.getHostname());
meta.setDatabaseInterface(di2);
return meta;
} else {
return databaseMeta;
}
} finally {
if (tempConnection != null) {
tempConnection.close();
}
}
}
Aggregations