Search in sources :

Example 11 with DatabaseInterface

use of org.pentaho.di.core.database.DatabaseInterface in project pentaho-kettle by pentaho.

the class ValueMetaBaseTest method testGetValueFromSqlTypeNetezza.

/**
 * PDI-10877 Table input step returns no data when pulling a timestamp column from IBM Netezza
 *
 * @throws Exception
 */
@Test
public void testGetValueFromSqlTypeNetezza() throws Exception {
    ValueMetaBase obj = new ValueMetaBase();
    DatabaseInterface databaseInterface = new NetezzaDatabaseMeta();
    ResultSet resultSet = Mockito.mock(ResultSet.class);
    ResultSetMetaData metaData = Mockito.mock(ResultSetMetaData.class);
    Mockito.when(resultSet.getMetaData()).thenReturn(metaData);
    Mockito.when(metaData.getColumnType(1)).thenReturn(Types.DATE);
    Mockito.when(metaData.getColumnType(2)).thenReturn(Types.TIME);
    obj.type = ValueMetaInterface.TYPE_DATE;
    // call to testing method
    obj.getValueFromResultSet(databaseInterface, resultSet, 0);
    // for jdbc Date type getDate method called
    Mockito.verify(resultSet, Mockito.times(1)).getDate(Mockito.anyInt());
    obj.getValueFromResultSet(databaseInterface, resultSet, 1);
    // for jdbc Time type getTime method called
    Mockito.verify(resultSet, Mockito.times(1)).getTime(Mockito.anyInt());
}
Also used : ResultSetMetaData(java.sql.ResultSetMetaData) DatabaseInterface(org.pentaho.di.core.database.DatabaseInterface) ResultSet(java.sql.ResultSet) NetezzaDatabaseMeta(org.pentaho.di.core.database.NetezzaDatabaseMeta) Test(org.junit.Test)

Example 12 with DatabaseInterface

use of org.pentaho.di.core.database.DatabaseInterface in project pentaho-kettle by pentaho.

the class DataHandler method setConnectionSpecificInfo.

private void setConnectionSpecificInfo(DatabaseMeta meta) {
    getControls();
    if (databaseDialectList != null) {
        databaseDialectList.setElements(databaseDialects);
        DatabaseInterface databaseInterface = meta.getDatabaseInterface();
        if (databaseInterface instanceof GenericDatabaseMeta) {
            databaseDialectList.setSelectedItem(((GenericDatabaseMeta) databaseInterface).getDatabaseDialect());
        }
    }
    if (hostNameBox != null) {
        hostNameBox.setValue(meta.getHostname());
    }
    // Database name:
    if (databaseNameBox != null) {
        databaseNameBox.setValue(meta.getDatabaseName());
    }
    // Username:
    if (userNameBox != null) {
        userNameBox.setValue(meta.getUsername());
    }
    // Password:
    if (passwordBox != null) {
        passwordBox.setValue(meta.getPassword());
    }
    // Streaming result cursor:
    if (resultStreamingCursorCheck != null) {
        resultStreamingCursorCheck.setChecked(meta.isStreamingResults());
    }
    // Data tablespace:
    if (dataTablespaceBox != null) {
        dataTablespaceBox.setValue(meta.getDataTablespace());
    }
    // Index tablespace
    if (indexTablespaceBox != null) {
        indexTablespaceBox.setValue(meta.getIndexTablespace());
    }
    // Strict Number(38) interpretation
    if (strictBigNumberInterpretaion != null) {
        // Check if oracle
        if (meta.getDatabaseInterface() instanceof OracleDatabaseMeta) {
            strictBigNumberInterpretaion.setVisible(true);
            strictBigNumberInterpretaion.setChecked(((OracleDatabaseMeta) meta.getDatabaseInterface()).strictBigNumberInterpretation());
        } else {
            strictBigNumberInterpretaion.setVisible(false);
            strictBigNumberInterpretaion.setChecked(false);
        }
    }
    if (serverInstanceBox != null) {
        serverInstanceBox.setValue(meta.getSQLServerInstance());
    }
    // SQL Server double decimal separator
    if (doubleDecimalSeparatorCheck != null) {
        doubleDecimalSeparatorCheck.setChecked(meta.isUsingDoubleDecimalAsSchemaTableSeparator());
    }
    // SAP Attributes...
    if (languageBox != null) {
        languageBox.setValue(meta.getAttributes().getProperty("SAPLanguage"));
    }
    if (systemNumberBox != null) {
        systemNumberBox.setValue(meta.getAttributes().getProperty("SAPSystemNumber"));
    }
    if (clientBox != null) {
        clientBox.setValue(meta.getAttributes().getProperty("SAPClient"));
    }
    // Generic settings...
    if (customUrlBox != null) {
        customUrlBox.setValue(meta.getAttributes().getProperty(GenericDatabaseMeta.ATRRIBUTE_CUSTOM_URL));
    }
    if (customDriverClassBox != null) {
        customDriverClassBox.setValue(meta.getAttributes().getProperty(GenericDatabaseMeta.ATRRIBUTE_CUSTOM_DRIVER_CLASS));
    }
    // Server Name: (Informix)
    if (serverNameBox != null) {
        serverNameBox.setValue(meta.getServername());
    }
    // Microsoft SQL Server Use Integrated Security
    if (useIntegratedSecurityCheck != null) {
        Object value = meta.getAttributes().get(MSSQLServerNativeDatabaseMeta.ATTRIBUTE_USE_INTEGRATED_SECURITY);
        if (value != null && value instanceof String) {
            String useIntegratedSecurity = (String) value;
            useIntegratedSecurityCheck.setChecked(Boolean.parseBoolean(useIntegratedSecurity));
        } else {
            useIntegratedSecurityCheck.setChecked(false);
        }
    }
    if (webAppName != null) {
        // Insert default value only for new connection, allowing it to be empty in case of editing existing one
        if (databaseMeta == null || Utils.isEmpty(databaseMeta.getDisplayName())) {
            webAppName.setValue(DEFAULT_WEB_APPLICATION_NAME);
        } else {
            webAppName.setValue(meta.getDatabaseName());
        }
    }
}
Also used : DatabaseInterface(org.pentaho.di.core.database.DatabaseInterface) OracleDatabaseMeta(org.pentaho.di.core.database.OracleDatabaseMeta) GenericDatabaseMeta(org.pentaho.di.core.database.GenericDatabaseMeta)

Example 13 with DatabaseInterface

use of org.pentaho.di.core.database.DatabaseInterface in project pentaho-kettle by pentaho.

the class DatabaseLogExceptionFactoryTest method testExceptionStrategyWithMysqlDataTruncationException.

/**
 * PDI-5153
 * Test that in case of MysqlDataTruncation exception there will be no stack trace in log
 */
@Test
public void testExceptionStrategyWithMysqlDataTruncationException() {
    DatabaseMeta databaseMeta = mock(DatabaseMeta.class);
    DatabaseInterface databaseInterface = new MySQLDatabaseMeta();
    MysqlDataTruncation e = new MysqlDataTruncation();
    when(logTable.getDatabaseMeta()).thenReturn(databaseMeta);
    when(databaseMeta.getDatabaseInterface()).thenReturn(databaseInterface);
    LogExceptionBehaviourInterface exceptionStrategy = DatabaseLogExceptionFactory.getExceptionStrategy(logTable, new KettleDatabaseException(e));
    String strategyName = exceptionStrategy.getClass().getName();
    assertEquals(SUPPRESSABLE_WITH_SHORT_MESSAGE, strategyName);
}
Also used : DatabaseInterface(org.pentaho.di.core.database.DatabaseInterface) MysqlDataTruncation(com.mysql.jdbc.MysqlDataTruncation) 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 14 with DatabaseInterface

use of org.pentaho.di.core.database.DatabaseInterface in project pentaho-kettle by pentaho.

the class DatabaseLogExceptionFactoryTest method testExceptionStrategyWithMaxAllowedPacketException.

/**
 * PDI-5153
 * Test that in case of MaxAllowedPacketException exception there will be no stack trace in log (MariaDB)
 */
@Test
public void testExceptionStrategyWithMaxAllowedPacketException() {
    DatabaseMeta databaseMeta = mock(DatabaseMeta.class);
    DatabaseInterface databaseInterface = new MariaDBDatabaseMeta();
    MaxAllowedPacketException e = new MaxAllowedPacketException();
    when(logTable.getDatabaseMeta()).thenReturn(databaseMeta);
    when(databaseMeta.getDatabaseInterface()).thenReturn(databaseInterface);
    LogExceptionBehaviourInterface exceptionStrategy = DatabaseLogExceptionFactory.getExceptionStrategy(logTable, new KettleDatabaseException(e));
    String strategyName = exceptionStrategy.getClass().getName();
    assertEquals(SUPPRESSABLE_WITH_SHORT_MESSAGE, strategyName);
}
Also used : DatabaseInterface(org.pentaho.di.core.database.DatabaseInterface) MariaDBDatabaseMeta(org.pentaho.di.core.database.MariaDBDatabaseMeta) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) MaxAllowedPacketException(org.mariadb.jdbc.internal.stream.MaxAllowedPacketException) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) MySQLDatabaseMeta(org.pentaho.di.core.database.MySQLDatabaseMeta) MariaDBDatabaseMeta(org.pentaho.di.core.database.MariaDBDatabaseMeta) Test(org.junit.Test)

Example 15 with DatabaseInterface

use of org.pentaho.di.core.database.DatabaseInterface in project pentaho-kettle by pentaho.

the class TableOutputMetaTest method testSupportsErrorHandling.

@Test
public void testSupportsErrorHandling() throws Exception {
    TableOutputMeta tableOutputMeta = new TableOutputMeta();
    DatabaseMeta dbMeta = mock(DatabaseMeta.class);
    tableOutputMeta.setDatabaseMeta(dbMeta);
    DatabaseInterface databaseInterface = mock(DatabaseInterface.class);
    when(dbMeta.getDatabaseInterface()).thenReturn(databaseInterface);
    when(databaseInterface.supportsErrorHandling()).thenReturn(true, false);
    assertTrue(tableOutputMeta.supportsErrorHandling());
    assertFalse(tableOutputMeta.supportsErrorHandling());
    tableOutputMeta.setDatabaseMeta(null);
    assertTrue(tableOutputMeta.supportsErrorHandling());
}
Also used : DatabaseInterface(org.pentaho.di.core.database.DatabaseInterface) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) Test(org.junit.Test)

Aggregations

DatabaseInterface (org.pentaho.di.core.database.DatabaseInterface)35 Test (org.junit.Test)22 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)16 MySQLDatabaseMeta (org.pentaho.di.core.database.MySQLDatabaseMeta)7 ResultSetMetaData (java.sql.ResultSetMetaData)5 ResultSet (java.sql.ResultSet)4 MariaDBDatabaseMeta (org.pentaho.di.core.database.MariaDBDatabaseMeta)4 NetezzaDatabaseMeta (org.pentaho.di.core.database.NetezzaDatabaseMeta)4 Vertica5DatabaseMeta (org.pentaho.di.core.database.Vertica5DatabaseMeta)4 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)4 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)4 GenericDatabaseMeta (org.pentaho.di.core.database.GenericDatabaseMeta)3 PacketTooBigException (com.mysql.jdbc.PacketTooBigException)2 PluginInterface (org.pentaho.di.core.plugins.PluginInterface)2 PluginRegistry (org.pentaho.di.core.plugins.PluginRegistry)2 TableOutputMeta (org.pentaho.di.trans.steps.tableoutput.TableOutputMeta)2 AnalysisContext (org.pentaho.metaverse.api.AnalysisContext)2 IExternalResourceInfo (org.pentaho.metaverse.api.model.IExternalResourceInfo)2 XulTextbox (org.pentaho.ui.xul.components.XulTextbox)2 MysqlDataTruncation (com.mysql.jdbc.MysqlDataTruncation)1