Search in sources :

Example 41 with DatabaseInterface

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);
}
Also used : DatabaseInterface(org.pentaho.di.core.database.DatabaseInterface) PacketTooBigException(com.mysql.jdbc.PacketTooBigException) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) MySQLDatabaseMeta(org.pentaho.di.core.database.MySQLDatabaseMeta) MariaDBDatabaseMeta(org.pentaho.di.core.database.MariaDBDatabaseMeta) MySQLDatabaseMeta(org.pentaho.di.core.database.MySQLDatabaseMeta) Test(org.junit.Test)

Example 42 with DatabaseInterface

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();
        }
    }
}
Also used : DatabaseInterface(org.pentaho.di.core.database.DatabaseInterface) SQLConnection(org.pentaho.platform.plugin.services.connections.sql.SQLConnection) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) GenericDatabaseMeta(org.pentaho.di.core.database.GenericDatabaseMeta)

Aggregations

DatabaseInterface (org.pentaho.di.core.database.DatabaseInterface)42 Test (org.junit.Test)28 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)22 MySQLDatabaseMeta (org.pentaho.di.core.database.MySQLDatabaseMeta)10 MariaDBDatabaseMeta (org.pentaho.di.core.database.MariaDBDatabaseMeta)7 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)7 ResultSetMetaData (java.sql.ResultSetMetaData)5 PacketTooBigException (com.mysql.jdbc.PacketTooBigException)4 BaseDatabaseMeta (org.pentaho.di.core.database.BaseDatabaseMeta)4 NetezzaDatabaseMeta (org.pentaho.di.core.database.NetezzaDatabaseMeta)4 OracleDatabaseMeta (org.pentaho.di.core.database.OracleDatabaseMeta)4 Vertica5DatabaseMeta (org.pentaho.di.core.database.Vertica5DatabaseMeta)4 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)4 GenericDatabaseMeta (org.pentaho.di.core.database.GenericDatabaseMeta)3 GreenplumDatabaseMeta (org.pentaho.di.core.database.GreenplumDatabaseMeta)3 PostgreSQLDatabaseMeta (org.pentaho.di.core.database.PostgreSQLDatabaseMeta)3 SQLiteDatabaseMeta (org.pentaho.di.core.database.SQLiteDatabaseMeta)3 TeradataDatabaseMeta (org.pentaho.di.core.database.TeradataDatabaseMeta)3 MysqlDataTruncation (com.mysql.jdbc.MysqlDataTruncation)2 KettleException (org.pentaho.di.core.exception.KettleException)2