Search in sources :

Example 1 with DatabaseConnectionPortObjectSpec

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

the class DBTableCreatorConfiguration method loadSettingsForDialog.

/**
 * Load settings for NodeDialog
 *
 * @param settings NodeSettingsRO instance to load from
 * @param specs PortObjectSpec array to load from
 * @throws NotConfigurableException
 */
public void loadSettingsForDialog(final NodeSettingsRO settings, final PortObjectSpec[] specs) throws NotConfigurableException {
    try {
        loadSettingsForModel(settings);
        final String dbIdentifier = ((DatabaseConnectionPortObjectSpec) specs[0]).getDatabaseIdentifier();
        loadSettingsForSqlEditor(dbIdentifier);
        m_tableSpec = (DataTableSpec) specs[1];
        if (m_tableSpec != null && (useDynamicSettings() || getColumns().isEmpty())) {
            loadColumnSettingsFromTableSpec(m_tableSpec);
            if (useDynamicSettings()) {
                updateKeysWithDynamicSettings();
            }
        } else {
            loadSettingsForRowElements(CFG_COLUMNS_SETTINGS, settings);
            loadSettingsForRowElements(CFG_KEYS_SETTINGS, settings);
        }
    } catch (InvalidSettingsException e) {
        throw new NotConfigurableException(e.getMessage());
    }
}
Also used : NotConfigurableException(org.knime.core.node.NotConfigurableException) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) DatabaseConnectionPortObjectSpec(org.knime.core.node.port.database.DatabaseConnectionPortObjectSpec)

Example 2 with DatabaseConnectionPortObjectSpec

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

the class DBWriterDialogPane method loadSettingsFrom.

/**
 * {@inheritDoc}
 */
@Override
protected void loadSettingsFrom(final NodeSettingsRO settings, final PortObjectSpec[] specs) throws NotConfigurableException {
    // get workflow credentials
    m_loginPane.loadSettingsFrom(settings, specs, getCredentialsProvider());
    // table name
    m_table.setText(settings.getString(DBWriterNodeModel.KEY_TABLE_NAME, ""));
    // append data flag
    m_append.setSelected(settings.getBoolean(DBWriterNodeModel.KEY_APPEND_DATA, true));
    m_insertNullForMissing.setSelected(settings.getBoolean(DBWriterNodeModel.KEY_INSERT_NULL_FOR_MISSING_COLS, false));
    m_insertNullForMissing.setEnabled(m_append.isSelected());
    // introduced in KNIME 3.3.1 default behavior was not failing e.g. false
    m_failOnError.setSelected(settings.getBoolean(DBWriterNodeModel.KEY_FAIL_ON_ERROR, false));
    // load SQL Types for each column
    try {
        NodeSettingsRO typeSett = settings.getNodeSettings(DBWriterNodeModel.CFG_SQL_TYPES);
        m_typePanel.loadSettingsFrom(typeSett, (DataTableSpec) specs[0]);
    } catch (InvalidSettingsException ise) {
        m_typePanel.loadSettingsFrom(null, (DataTableSpec) specs[0]);
    }
    // load batch size
    final int batchSize = settings.getInt(DBWriterNodeModel.KEY_BATCH_SIZE, DatabaseConnectionSettings.BATCH_WRITE_SIZE);
    m_batchSize.setText(Integer.toString(batchSize));
    if ((specs.length > 1) && (specs[1] instanceof DatabaseConnectionPortObjectSpec)) {
        m_loginPane.setVisible(false);
    } else {
        m_loginPane.setVisible(true);
    }
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) NodeSettingsRO(org.knime.core.node.NodeSettingsRO) DatabaseConnectionPortObjectSpec(org.knime.core.node.port.database.DatabaseConnectionPortObjectSpec)

Example 3 with DatabaseConnectionPortObjectSpec

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

the class DBWriterNodeModel method configure.

/**
 * {@inheritDoc}
 */
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
    DataTableSpec tableSpec = (DataTableSpec) inSpecs[0];
    // 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().supportsInsert()) {
            throw new InvalidSettingsException("Connected database does not support insert operations");
        }
    } else {
        if (!m_conn.getUtility().supportsInsert()) {
            throw new InvalidSettingsException("Selected database does not support insert operations");
        }
    }
    // check table name
    if ((m_tableName == null) || m_tableName.trim().isEmpty()) {
        throw new InvalidSettingsException("Configure node and enter a valid table name.");
    }
    // throw exception if no data provided
    if (tableSpec.getNumColumns() == 0) {
        throw new InvalidSettingsException("No columns in input data.");
    }
    // copy map to ensure only columns which are with the data
    Map<String, String> map = new LinkedHashMap<>();
    // check that each column has a assigned type
    for (int i = 0; i < tableSpec.getNumColumns(); i++) {
        final String name = tableSpec.getColumnSpec(i).getName();
        String sqlType = m_types.get(name);
        if (sqlType == null) {
            final DataType type = tableSpec.getColumnSpec(i).getType();
            if (type.isCompatible(IntValue.class)) {
                sqlType = DBWriterNodeModel.SQL_TYPE_INTEGER;
            } else if (type.isCompatible(DoubleValue.class)) {
                sqlType = DBWriterNodeModel.SQL_TYPE_DOUBLE;
            } else if (type.isCompatible(DateAndTimeValue.class)) {
                sqlType = DBWriterNodeModel.SQL_TYPE_DATEANDTIME;
            } else {
                sqlType = DBWriterNodeModel.SQL_TYPE_STRING;
            }
        }
        map.put(name, sqlType);
    }
    m_types.clear();
    m_types.putAll(map);
    if (!m_append) {
        super.setWarningMessage("Existing table \"" + m_tableName + "\" will be dropped!");
    }
    return new DataTableSpec[0];
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) DatabaseConnectionSettings(org.knime.core.node.port.database.DatabaseConnectionSettings) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) DoubleValue(org.knime.core.data.DoubleValue) DataType(org.knime.core.data.DataType) DatabaseConnectionPortObjectSpec(org.knime.core.node.port.database.DatabaseConnectionPortObjectSpec) LinkedHashMap(java.util.LinkedHashMap)

Example 4 with DatabaseConnectionPortObjectSpec

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

the class DBUpdateDialogPane method loadSettingsFrom.

/**
 * {@inheritDoc}
 */
@Override
protected void loadSettingsFrom(final NodeSettingsRO settings, final PortObjectSpec[] specs) throws NotConfigurableException {
    DataTableSpec tableSpec = (DataTableSpec) specs[0];
    // load login setting
    m_loginPanel.loadSettingsFrom(settings, specs, getCredentialsProvider());
    // load table name
    m_tableName.setText(settings.getString(DBUpdateNodeModel.KEY_TABLE_NAME, ""));
    // load SET column panel
    DataColumnSpecFilterConfiguration configSet = new DataColumnSpecFilterConfiguration(DBUpdateNodeModel.KEY_SET_FILTER_COLUMN);
    configSet.loadConfigurationInDialog(settings, tableSpec);
    m_columnsInSetClause.loadConfiguration(configSet, tableSpec);
    // load WHERE column panel
    DataColumnSpecFilterConfiguration configWhere = new DataColumnSpecFilterConfiguration(DBUpdateNodeModel.KEY_WHERE_FILTER_COLUMN);
    configWhere.loadConfigurationInDialog(settings, tableSpec);
    m_columnsInWhereClause.loadConfiguration(configWhere, tableSpec);
    // load batch size
    final int batchSize = settings.getInt(DBUpdateNodeModel.KEY_BATCH_SIZE, 1);
    m_batchSize.setText(Integer.toString(batchSize));
    if ((specs.length > 1) && (specs[1] instanceof DatabaseConnectionPortObjectSpec)) {
        m_loginPanel.setVisible(false);
    } else {
        m_loginPanel.setVisible(true);
    }
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) DataColumnSpecFilterConfiguration(org.knime.core.node.util.filter.column.DataColumnSpecFilterConfiguration) DatabaseConnectionPortObjectSpec(org.knime.core.node.port.database.DatabaseConnectionPortObjectSpec)

Example 5 with DatabaseConnectionPortObjectSpec

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

the class DBUpdateNodeModel method configure.

/**
 * {@inheritDoc}
 */
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
    DataTableSpec tableSpec = (DataTableSpec) inSpecs[0];
    // 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().supportsUpdate()) {
            throw new InvalidSettingsException("Connected database does not support update operations");
        }
    } else {
        if (!m_loginConfig.getUtility().supportsUpdate()) {
            throw new InvalidSettingsException("Selected database does not support update operations");
        }
    }
    // check table name
    if ((m_tableName == null) || m_tableName.trim().isEmpty()) {
        throw new InvalidSettingsException("Configure node and enter a valid table name.");
    }
    // check SET and WHERE for overlapping columns
    final List<String> setIncludes = new ArrayList<>(Arrays.asList(m_configSET.applyTo(tableSpec).getIncludes()));
    if (setIncludes.isEmpty()) {
        throw new InvalidSettingsException("No SET column selected.");
    }
    final List<String> whereIncludes = new ArrayList<>(Arrays.asList(m_configWHERE.applyTo(tableSpec).getIncludes()));
    if (whereIncludes.isEmpty()) {
        throw new InvalidSettingsException("No WHERE column selected.");
    }
    if (!setIncludes.retainAll(whereIncludes)) {
        throw new InvalidSettingsException("SET and WHERE column list contain duplicate columns.");
    }
    // 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) DatabaseConnectionSettings(org.knime.core.node.port.database.DatabaseConnectionSettings) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) ArrayList(java.util.ArrayList) DatabaseConnectionPortObjectSpec(org.knime.core.node.port.database.DatabaseConnectionPortObjectSpec)

Aggregations

DatabaseConnectionPortObjectSpec (org.knime.core.node.port.database.DatabaseConnectionPortObjectSpec)13 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)10 DataTableSpec (org.knime.core.data.DataTableSpec)9 DatabaseConnectionSettings (org.knime.core.node.port.database.DatabaseConnectionSettings)7 PortObjectSpec (org.knime.core.node.port.PortObjectSpec)4 SQLException (java.sql.SQLException)3 DatabaseQueryConnectionSettings (org.knime.core.node.port.database.DatabaseQueryConnectionSettings)3 ArrayList (java.util.ArrayList)2 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)2 SettingsModelString (org.knime.core.node.defaultnodesettings.SettingsModelString)2 DBReader (org.knime.core.node.port.database.reader.DBReader)2 DataColumnSpecFilterConfiguration (org.knime.core.node.util.filter.column.DataColumnSpecFilterConfiguration)2 IOException (java.io.IOException)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 DataType (org.knime.core.data.DataType)1 DoubleValue (org.knime.core.data.DoubleValue)1 CanceledExecutionException (org.knime.core.node.CanceledExecutionException)1 NodeSettingsRO (org.knime.core.node.NodeSettingsRO)1 NotConfigurableException (org.knime.core.node.NotConfigurableException)1