Search in sources :

Example 31 with DatabaseInterface

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

the class ValueMetaBaseTest method testGetBinaryWithLength_WhenBinarySqlTypesOfVertica.

@Test
public void testGetBinaryWithLength_WhenBinarySqlTypesOfVertica() throws Exception {
    final int binaryColumnIndex = 1;
    final int varbinaryColumnIndex = 2;
    final int expectedBinarylength = 1;
    final int expectedVarBinarylength = 80;
    ValueMetaBase obj = new ValueMetaBase();
    DatabaseMeta dbMeta = Mockito.spy(new DatabaseMeta());
    DatabaseInterface databaseInterface = new Vertica5DatabaseMeta();
    dbMeta.setDatabaseInterface(databaseInterface);
    ResultSet resultSet = Mockito.mock(ResultSet.class);
    ResultSetMetaData metaData = Mockito.mock(ResultSetMetaData.class);
    Mockito.when(resultSet.getMetaData()).thenReturn(metaData);
    Mockito.when(metaData.getColumnType(binaryColumnIndex)).thenReturn(Types.BINARY);
    Mockito.when(metaData.getPrecision(binaryColumnIndex)).thenReturn(expectedBinarylength);
    Mockito.when(metaData.getColumnDisplaySize(binaryColumnIndex)).thenReturn(expectedBinarylength * 2);
    Mockito.when(metaData.getColumnType(varbinaryColumnIndex)).thenReturn(Types.BINARY);
    Mockito.when(metaData.getPrecision(varbinaryColumnIndex)).thenReturn(expectedVarBinarylength);
    Mockito.when(metaData.getColumnDisplaySize(varbinaryColumnIndex)).thenReturn(expectedVarBinarylength * 2);
    // get value meta for binary type
    ValueMetaInterface binaryValueMeta = obj.getValueFromSQLType(dbMeta, TEST_NAME, metaData, binaryColumnIndex, false, false);
    assertNotNull(binaryValueMeta);
    assertTrue(TEST_NAME.equals(binaryValueMeta.getName()));
    assertTrue(ValueMetaInterface.TYPE_BINARY == binaryValueMeta.getType());
    assertTrue(expectedBinarylength == binaryValueMeta.getLength());
    Assert.assertFalse(binaryValueMeta.isLargeTextField());
    // get value meta for varbinary type
    ValueMetaInterface varbinaryValueMeta = obj.getValueFromSQLType(dbMeta, TEST_NAME, metaData, varbinaryColumnIndex, false, false);
    assertNotNull(varbinaryValueMeta);
    assertTrue(TEST_NAME.equals(varbinaryValueMeta.getName()));
    assertTrue(ValueMetaInterface.TYPE_BINARY == varbinaryValueMeta.getType());
    assertTrue(expectedVarBinarylength == varbinaryValueMeta.getLength());
    Assert.assertFalse(varbinaryValueMeta.isLargeTextField());
}
Also used : ResultSetMetaData(java.sql.ResultSetMetaData) DatabaseInterface(org.pentaho.di.core.database.DatabaseInterface) Vertica5DatabaseMeta(org.pentaho.di.core.database.Vertica5DatabaseMeta) ResultSet(java.sql.ResultSet) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) NetezzaDatabaseMeta(org.pentaho.di.core.database.NetezzaDatabaseMeta) MySQLDatabaseMeta(org.pentaho.di.core.database.MySQLDatabaseMeta) Vertica5DatabaseMeta(org.pentaho.di.core.database.Vertica5DatabaseMeta) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) Test(org.junit.Test)

Example 32 with DatabaseInterface

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

the class DataHandler method getConnectionSpecificInfo.

private void getConnectionSpecificInfo(DatabaseMeta meta) {
    // Hostname:
    if (hostNameBox != null) {
        meta.setHostname(hostNameBox.getValue());
    }
    // Database name:
    if (databaseNameBox != null) {
        meta.setDBName(databaseNameBox.getValue());
    }
    // Username:
    if (userNameBox != null) {
        meta.setUsername(userNameBox.getValue());
    }
    // Password:
    if (passwordBox != null) {
        meta.setPassword(passwordBox.getValue());
    }
    if (databaseDialectList != null) {
        DatabaseInterface databaseInterface = meta.getDatabaseInterface();
        if (databaseInterface instanceof GenericDatabaseMeta) {
            ((GenericDatabaseMeta) databaseInterface).setDatabaseDialect(databaseDialectList.getValue());
        }
    }
    // Streaming result cursor:
    if (resultStreamingCursorCheck != null) {
        meta.setStreamingResults(resultStreamingCursorCheck.isChecked());
    }
    // Data tablespace:
    if (dataTablespaceBox != null) {
        meta.setDataTablespace(dataTablespaceBox.getValue());
    }
    // Index tablespace
    if (indexTablespaceBox != null) {
        meta.setIndexTablespace(indexTablespaceBox.getValue());
    }
    if (serverInstanceBox != null) {
        meta.setSQLServerInstance(serverInstanceBox.getValue());
        if (optionsParameterTree != null && optionsParameterTree.getRootChildren() != null) {
            for (int i = 0; i < optionsParameterTree.getRootChildren().getItemCount(); i++) {
                XulTreeItem potRow = optionsParameterTree.getRootChildren().getItem(i);
                if (potRow != null && potRow.getRow() != null) {
                    XulTreeCell cell = potRow.getRow().getCell(0);
                    XulTreeCell cell2 = potRow.getRow().getCell(1);
                    if (cell != null && cell.getLabel() != null && cell.getLabel().equals("instance")) {
                        cell2.setLabel(serverInstanceBox.getValue());
                        if (serverInstanceBox.getValue().trim().length() == 0) {
                            cell.setLabel("");
                        }
                    }
                }
            }
        }
    }
    // SQL Server double decimal separator
    if (doubleDecimalSeparatorCheck != null) {
        meta.setUsingDoubleDecimalAsSchemaTableSeparator(doubleDecimalSeparatorCheck.isChecked());
    }
    // SAP Attributes...
    if (languageBox != null) {
        meta.getAttributes().put("SAPLanguage", languageBox.getValue());
    }
    if (systemNumberBox != null) {
        meta.getAttributes().put("SAPSystemNumber", systemNumberBox.getValue());
    }
    if (clientBox != null) {
        meta.getAttributes().put("SAPClient", clientBox.getValue());
    }
    // Generic settings...
    if (customUrlBox != null) {
        meta.getAttributes().put(GenericDatabaseMeta.ATRRIBUTE_CUSTOM_URL, customUrlBox.getValue());
    }
    if (customDriverClassBox != null) {
        meta.getAttributes().put(GenericDatabaseMeta.ATRRIBUTE_CUSTOM_DRIVER_CLASS, customDriverClassBox.getValue());
    }
    // Server Name: (Informix)
    if (serverNameBox != null) {
        meta.setServername(serverNameBox.getValue());
    }
    // Microsoft SQL Server Use Integrated Security
    if (useIntegratedSecurityCheck != null) {
        Boolean useIntegratedSecurity = useIntegratedSecurityCheck.isChecked();
        meta.getAttributes().put(MSSQLServerNativeDatabaseMeta.ATTRIBUTE_USE_INTEGRATED_SECURITY, useIntegratedSecurity != null ? useIntegratedSecurity.toString() : "false");
    }
    if (webAppName != null) {
        meta.setDBName(webAppName.getValue());
    }
}
Also used : DatabaseInterface(org.pentaho.di.core.database.DatabaseInterface) XulTreeItem(org.pentaho.ui.xul.containers.XulTreeItem) XulTreeCell(org.pentaho.ui.xul.components.XulTreeCell) GenericDatabaseMeta(org.pentaho.di.core.database.GenericDatabaseMeta)

Example 33 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 34 with DatabaseInterface

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

the class DatabaseLogExceptionFactoryTest method testExceptionStrategyWithPacketTooBigException.

/**
 * PDI-5153
 * Test that in case of PacketTooBigException exception there will be no stack trace in log
 */
@Test
public void testExceptionStrategyWithPacketTooBigException() {
    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(SUPPRESSABLE_WITH_SHORT_MESSAGE, 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 35 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)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