Search in sources :

Example 11 with DatabaseConnectionPortObject

use of org.knime.core.node.port.database.DatabaseConnectionPortObject in project knime-core by knime.

the class JDBCConnectorNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected PortObject[] execute(final PortObject[] inObjects, final ExecutionContext exec) throws Exception {
    DatabaseConnectionSettings s = new DatabaseConnectionSettings(m_settings);
    // new behavior since 2.10
    s.setRowIdsStartWithZero(true);
    DatabaseConnectionPortObject dbPort = new DatabaseConnectionPortObject(new DatabaseConnectionPortObjectSpec(s));
    try {
        dbPort.getConnectionSettings(getCredentialsProvider()).execute(getCredentialsProvider(), conn -> {
            return conn != null;
        });
    } catch (SQLException ex) {
        Throwable cause = ExceptionUtils.getRootCause(ex);
        if (cause == null) {
            cause = ex;
        }
        if (cause instanceof ClassNotFoundException) {
            cause = new Exception("Could not find driver class: " + cause.getMessage());
        }
        throw new SQLException("Could not create connection to database: " + cause.getMessage(), ex);
    }
    return new PortObject[] { dbPort };
}
Also used : DatabaseConnectionPortObject(org.knime.core.node.port.database.DatabaseConnectionPortObject) DatabaseConnectionSettings(org.knime.core.node.port.database.DatabaseConnectionSettings) SQLException(java.sql.SQLException) DatabaseConnectionPortObject(org.knime.core.node.port.database.DatabaseConnectionPortObject) PortObject(org.knime.core.node.port.PortObject) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) CanceledExecutionException(org.knime.core.node.CanceledExecutionException) IOException(java.io.IOException) SQLException(java.sql.SQLException) DatabaseConnectionPortObjectSpec(org.knime.core.node.port.database.DatabaseConnectionPortObjectSpec)

Example 12 with DatabaseConnectionPortObject

use of org.knime.core.node.port.database.DatabaseConnectionPortObject in project knime-core by knime.

the class DBTableCreatorNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected PortObject[] execute(final PortObject[] inData, final ExecutionContext exec) throws Exception {
    exec.setMessage("Creating table");
    final DatabaseConnectionPortObject dbConn = (DatabaseConnectionPortObject) inData[0];
    final DatabaseConnectionSettings conn = dbConn.getConnectionSettings(getCredentialsProvider());
    final DBTableCreator tableCreator = conn.getUtility().getTableCreator(m_config.getSchema(), getTableName(), m_config.isTempTable());
    final List<DBColumn> columns = m_config.getColumns();
    final List<DBKey> keys = m_config.getKeys();
    tableCreator.createTable(conn, getCredentialsProvider(), m_config.ifNotExists(), columns.toArray(new DBColumn[columns.size()]), keys.toArray(new DBKey[keys.size()]), m_config.getAdditionalOptions());
    pushFlowVariables(tableCreator.getSchema(), tableCreator.getTableName());
    final String warning = tableCreator.getWarning();
    if (!StringUtils.isBlank(warning)) {
        setWarningMessage(warning);
    }
    return new PortObject[] { dbConn };
}
Also used : DatabaseConnectionPortObject(org.knime.core.node.port.database.DatabaseConnectionPortObject) DBTableCreator(org.knime.core.node.port.database.tablecreator.DBTableCreator) DatabaseConnectionSettings(org.knime.core.node.port.database.DatabaseConnectionSettings) DBColumn(org.knime.core.node.port.database.tablecreator.DBColumn) DBKey(org.knime.core.node.port.database.tablecreator.DBKey) DatabaseConnectionPortObject(org.knime.core.node.port.database.DatabaseConnectionPortObject) PortObject(org.knime.core.node.port.PortObject)

Aggregations

DatabaseConnectionPortObject (org.knime.core.node.port.database.DatabaseConnectionPortObject)12 DatabaseConnectionSettings (org.knime.core.node.port.database.DatabaseConnectionSettings)10 PortObject (org.knime.core.node.port.PortObject)6 DataTableSpec (org.knime.core.data.DataTableSpec)5 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)5 SQLException (java.sql.SQLException)4 BufferedDataTable (org.knime.core.node.BufferedDataTable)4 DBReader (org.knime.core.node.port.database.reader.DBReader)4 DBWriter (org.knime.core.node.port.database.writer.DBWriter)4 CanceledExecutionException (org.knime.core.node.CanceledExecutionException)3 SettingsModelString (org.knime.core.node.defaultnodesettings.SettingsModelString)3 DatabaseQueryConnectionSettings (org.knime.core.node.port.database.DatabaseQueryConnectionSettings)3 IOException (java.io.IOException)2 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)2 ExecutionContext (org.knime.core.node.ExecutionContext)2 PortObjectSpec (org.knime.core.node.port.PortObjectSpec)2 DatabaseConnectionPortObjectSpec (org.knime.core.node.port.database.DatabaseConnectionPortObjectSpec)2 DatabasePortObject (org.knime.core.node.port.database.DatabasePortObject)2 DatabasePortObjectSpec (org.knime.core.node.port.database.DatabasePortObjectSpec)2 DataTableRowInput (org.knime.core.node.streamable.DataTableRowInput)2