Search in sources :

Example 36 with DatabaseInterface

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

the class DataHandler method getConnectionSpecificInfo.

protected 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());
    }
    // Snowflake
    if (warehouseBox != null) {
        meta.getAttributes().put(WAREHOUSE, warehouseBox.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");
    }
    // Azure SQL DB
    if (azureSqlDBJdbcAuthMethod != null) {
        meta.getAttributes().put(JDBC_AUTH_METHOD, azureSqlDBJdbcAuthMethod.getValue());
    }
    if (azureSqlDBClientSecretId != null) {
        meta.getAttributes().put(CLIENT_ID, azureSqlDBClientSecretId.getValue());
    }
    if (azureSqlDBAlwaysEncryptionEnabled != null) {
        if (azureSqlDBAlwaysEncryptionEnabled.isChecked()) {
            meta.getAttributes().put(IS_ALWAYS_ENCRYPTION_ENABLED, "true");
        } else {
            meta.getAttributes().put(IS_ALWAYS_ENCRYPTION_ENABLED, "false");
        }
    }
    if (azureSqlDBClientSecretKey != null) {
        meta.getAttributes().put(CLIENT_SECRET_KEY, azureSqlDBClientSecretKey.getValue());
    }
    if (jdbcAuthMethod != null) {
        meta.getAttributes().put(JDBC_AUTH_METHOD, jdbcAuthMethod.getValue());
    }
    if (iamAccessKeyId != null) {
        meta.getAttributes().put(IAM_ACCESS_KEY_ID, iamAccessKeyId.getValue());
    }
    if (iamSecretKeyId != null) {
        meta.getAttributes().put(IAM_SECRET_ACCESS_KEY, Encr.encryptPassword(iamSecretKeyId.getValue()));
    }
    if (iamSessionToken != null) {
        meta.getAttributes().put(IAM_SESSION_TOKEN, iamSessionToken.getValue());
    }
    if (iamProfileName != null) {
        meta.getAttributes().put(IAM_PROFILE_NAME, iamProfileName.getValue());
    }
    if (webAppName != null) {
        meta.setDBName(webAppName.getValue());
    }
    if (namedClusterList != null) {
        meta.getDatabaseInterface().setNamedCluster(namedClusterList.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 37 with DatabaseInterface

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

the class FragmentHandlerTest method testRefreshOptions.

@Test
public void testRefreshOptions() throws Exception {
    XulListbox connectionBox = mock(XulListbox.class);
    when(document.getElementById("connection-type-list")).thenReturn(connectionBox);
    when(connectionBox.getSelectedItem()).thenReturn("myDb");
    XulListbox accessBox = mock(XulListbox.class);
    when(document.getElementById("access-type-list")).thenReturn(accessBox);
    when(accessBox.getSelectedItem()).thenReturn("Native");
    DataHandler dataHandler = mock(DataHandler.class);
    when(xulDomContainer.getEventHandler("dataHandler")).thenReturn(dataHandler);
    DatabaseInterface dbInterface = mock(DatabaseInterface.class);
    when(dbInterface.getDefaultDatabasePort()).thenReturn(5309);
    DataHandler.connectionMap.put("myDb", dbInterface);
    XulComponent component = mock(XulComponent.class);
    XulComponent parent = mock(XulComponent.class);
    when(component.getParent()).thenReturn(parent);
    when(document.getElementById("database-options-box")).thenReturn(component);
    XulDomContainer fragmentContainer = mock(XulDomContainer.class);
    Document mockDoc = mock(Document.class);
    XulComponent firstChild = mock(XulComponent.class);
    when(mockDoc.getFirstChild()).thenReturn(firstChild);
    when(fragmentContainer.getDocumentRoot()).thenReturn(mockDoc);
    when(xulDomContainer.loadFragment(anyString(), any(Object.class))).thenReturn(fragmentContainer);
    XulTextbox portBox = mock(XulTextbox.class);
    when(document.getElementById("port-number-text")).thenReturn(portBox);
    fragmentHandler.refreshOptions();
    // Iterate through the other database access types
    when(accessBox.getSelectedItem()).thenReturn("JNDI");
    fragmentHandler.refreshOptions();
    when(accessBox.getSelectedItem()).thenReturn("ODBC");
    fragmentHandler.refreshOptions();
    when(accessBox.getSelectedItem()).thenReturn("OCI");
    fragmentHandler.refreshOptions();
    when(accessBox.getSelectedItem()).thenReturn("Plugin");
    fragmentHandler.refreshOptions();
}
Also used : DatabaseInterface(org.pentaho.di.core.database.DatabaseInterface) XulTextbox(org.pentaho.ui.xul.components.XulTextbox) XulListbox(org.pentaho.ui.xul.containers.XulListbox) XulDomContainer(org.pentaho.ui.xul.XulDomContainer) Document(org.pentaho.ui.xul.dom.Document) XulComponent(org.pentaho.ui.xul.XulComponent) Test(org.junit.Test)

Example 38 with DatabaseInterface

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

the class DataHandlerTest method testLoadConnectionData.

@Test
public void testLoadConnectionData() throws Exception {
    DatabaseInterface dbInterface = mock(DatabaseInterface.class);
    when(dbInterface.getDefaultDatabasePort()).thenReturn(5309);
    DataHandler.connectionMap.put("myDb", dbInterface);
    dataHandler.loadConnectionData();
    // Should immediately return if called again since the connectionBox will have been loaded
    dataHandler.loadConnectionData();
}
Also used : DatabaseInterface(org.pentaho.di.core.database.DatabaseInterface) Test(org.junit.Test)

Example 39 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 40 with DatabaseInterface

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

the class DatabaseLogExceptionFactoryTest method testExceptionStrategyWithMysqlDataTruncationException80driver.

@Test
public void testExceptionStrategyWithMysqlDataTruncationException80driver() {
    DatabaseMeta databaseMeta = mock(DatabaseMeta.class);
    DatabaseInterface databaseInterface = new MySQLDatabaseMeta();
    com.mysql.cj.jdbc.exceptions.MysqlDataTruncation e = new com.mysql.cj.jdbc.exceptions.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 : 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) DatabaseInterface(org.pentaho.di.core.database.DatabaseInterface) Test(org.junit.Test)

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