Search in sources :

Example 11 with DatabaseConnectionSettings

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

the class JDBCConnectorNodeModel method validateSettings.

/**
 * {@inheritDoc}
 */
@Override
protected void validateSettings(final NodeSettingsRO settings) throws InvalidSettingsException {
    DatabaseConnectionSettings s = new DatabaseConnectionSettings();
    s.validateConnection(settings, getCredentialsProvider());
}
Also used : DatabaseConnectionSettings(org.knime.core.node.port.database.DatabaseConnectionSettings)

Example 12 with DatabaseConnectionSettings

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

the class DBDeleteRowsNodeModel method validateSettings.

/**
 * {@inheritDoc}
 */
@Override
protected void validateSettings(final NodeSettingsRO settings) throws InvalidSettingsException {
    // validate login settings
    new DatabaseConnectionSettings(settings, getCredentialsProvider());
    // validate table name
    final String tableName = settings.getString(KEY_TABLE_NAME);
    if (tableName == null || tableName.trim().isEmpty()) {
        throw new InvalidSettingsException("Configure node and enter a valid table name.");
    }
    // validate WHERE columns
    final DataColumnSpecFilterConfiguration confWHERE = new DataColumnSpecFilterConfiguration(KEY_WHERE_FILTER_COLUMN);
    confWHERE.loadConfigurationInModel(settings);
    // validate batch size
    final int batchSize = settings.getInt(KEY_BATCH_SIZE);
    if (batchSize <= 0) {
        throw new InvalidSettingsException("Batch size must be greater than 0, is " + batchSize);
    }
}
Also used : DatabaseConnectionSettings(org.knime.core.node.port.database.DatabaseConnectionSettings) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) DataColumnSpecFilterConfiguration(org.knime.core.node.util.filter.column.DataColumnSpecFilterConfiguration)

Example 13 with DatabaseConnectionSettings

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

the class DBDeleteRowsNodeModel method loadValidatedSettingsFrom.

/**
 * {@inheritDoc}
 */
@Override
protected void loadValidatedSettingsFrom(final NodeSettingsRO settings) throws InvalidSettingsException {
    // load WHERE columns
    final DataColumnSpecFilterConfiguration confWHERE = new DataColumnSpecFilterConfiguration(KEY_WHERE_FILTER_COLUMN);
    confWHERE.loadConfigurationInModel(settings);
    m_configWHERE = confWHERE;
    // load login settings
    m_loginConfig = new DatabaseConnectionSettings(settings, getCredentialsProvider());
    // load table name
    m_tableName = settings.getString(KEY_TABLE_NAME).trim();
    // load batch size
    m_batchSize = settings.getInt(KEY_BATCH_SIZE);
}
Also used : DataColumnSpecFilterConfiguration(org.knime.core.node.util.filter.column.DataColumnSpecFilterConfiguration) DatabaseConnectionSettings(org.knime.core.node.port.database.DatabaseConnectionSettings)

Example 14 with DatabaseConnectionSettings

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

the class DBDeleteRowsNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected PortObject[] execute(final PortObject[] inData, final ExecutionContext exec) throws Exception {
    final BufferedDataTable inTable = (BufferedDataTable) inData[0];
    final DataTableSpec inSpec = inTable.getSpec();
    final String[] whereIncludes = m_configWHERE.applyTo(inSpec).getIncludes();
    DatabaseConnectionSettings connSettings;
    if ((inData.length > 1) && (inData[1] instanceof DatabaseConnectionPortObject)) {
        connSettings = ((DatabaseConnectionPortObject) inData[1]).getConnectionSettings(getCredentialsProvider());
    } else {
        connSettings = m_loginConfig;
    }
    // DELETE rows
    final int[] deleteStatus = new int[inTable.getRowCount()];
    final DBWriter dbWriter = connSettings.getUtility().getWriter(connSettings);
    final String errMsg = dbWriter.deleteRows(null, m_tableName, inTable, whereIncludes, deleteStatus, exec, getCredentialsProvider(), m_batchSize);
    // set warning message generated during deleting rows
    if (errMsg != null) {
        setWarningMessage(errMsg);
    }
    // create out table with update column
    final ColumnRearranger colre = createColumnRearranger(inTable.getSpec(), deleteStatus);
    final BufferedDataTable outTable = exec.createColumnRearrangeTable(inTable, colre, exec.createSubProgress(1.0));
    return new BufferedDataTable[] { outTable };
}
Also used : DatabaseConnectionPortObject(org.knime.core.node.port.database.DatabaseConnectionPortObject) DataTableSpec(org.knime.core.data.DataTableSpec) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) DatabaseConnectionSettings(org.knime.core.node.port.database.DatabaseConnectionSettings) BufferedDataTable(org.knime.core.node.BufferedDataTable) DBWriter(org.knime.core.node.port.database.writer.DBWriter)

Example 15 with DatabaseConnectionSettings

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

the class DBDeleteRowsNodeModel method configure.

/**
 * {@inheritDoc}
 */
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
    DataTableSpec tableSpec = (DataTableSpec) inSpecs[0];
    // check table name
    if (m_tableName == null || m_tableName.trim().isEmpty()) {
        throw new InvalidSettingsException("Configure node and enter a valid table name.");
    }
    final List<String> whereIncludes = new ArrayList<String>(Arrays.asList(m_configWHERE.applyTo(tableSpec).getIncludes()));
    if (whereIncludes.isEmpty()) {
        throw new InvalidSettingsException("No WHERE column selected.");
    }
    // check optional incoming connection
    if ((inSpecs.length > 1) && (inSpecs[1] instanceof DatabaseConnectionPortObjectSpec)) {
        DatabaseConnectionSettings connSettings = ((DatabaseConnectionPortObjectSpec) inSpecs[1]).getConnectionSettings(getCredentialsProvider());
        if ((connSettings.getJDBCUrl() == null) || connSettings.getJDBCUrl().isEmpty() || (connSettings.getDriver() == null) || connSettings.getDriver().isEmpty()) {
            throw new InvalidSettingsException("No valid database connection provided via second input port");
        }
        if (!connSettings.getUtility().supportsDelete()) {
            throw new InvalidSettingsException("Connected database does not support delete operations");
        }
    } else {
        if (!m_loginConfig.getUtility().supportsDelete()) {
            throw new InvalidSettingsException("Selected database does not support delete operations");
        }
    }
    // forward input spec with one additional update (=int) column
    final ColumnRearranger colre = createColumnRearranger(tableSpec, new int[] {});
    return new DataTableSpec[] { colre.createSpec() };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) DatabaseConnectionSettings(org.knime.core.node.port.database.DatabaseConnectionSettings) ArrayList(java.util.ArrayList) DatabaseConnectionPortObjectSpec(org.knime.core.node.port.database.DatabaseConnectionPortObjectSpec)

Aggregations

DatabaseConnectionSettings (org.knime.core.node.port.database.DatabaseConnectionSettings)26 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)14 DataTableSpec (org.knime.core.data.DataTableSpec)12 DatabaseConnectionPortObject (org.knime.core.node.port.database.DatabaseConnectionPortObject)10 SQLException (java.sql.SQLException)7 DatabaseConnectionPortObjectSpec (org.knime.core.node.port.database.DatabaseConnectionPortObjectSpec)7 PortObject (org.knime.core.node.port.PortObject)6 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)4 PortObjectSpec (org.knime.core.node.port.PortObjectSpec)4 DBWriter (org.knime.core.node.port.database.writer.DBWriter)4 DataColumnSpecFilterConfiguration (org.knime.core.node.util.filter.column.DataColumnSpecFilterConfiguration)4 PreparedStatement (java.sql.PreparedStatement)3 ArrayList (java.util.ArrayList)3 TimeZone (java.util.TimeZone)3 DataCell (org.knime.core.data.DataCell)3 DataColumnSpec (org.knime.core.data.DataColumnSpec)3 DataRow (org.knime.core.data.DataRow)3 BufferedDataTable (org.knime.core.node.BufferedDataTable)3 SettingsModelString (org.knime.core.node.defaultnodesettings.SettingsModelString)3 DatabasePortObjectSpec (org.knime.core.node.port.database.DatabasePortObjectSpec)3