Search in sources :

Example 26 with DatabasePortObjectSpec

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

the class DBColumnFilterNodeDialogPane method loadSettingsFrom.

/**
 * {@inheritDoc}
 */
@Override
protected void loadSettingsFrom(final NodeSettingsRO settings, final PortObjectSpec[] ports) throws NotConfigurableException {
    DatabasePortObjectSpec dbSpec = (DatabasePortObjectSpec) ports[0];
    final DataTableSpec[] specs;
    if (dbSpec == null) {
        specs = new DataTableSpec[] { null };
    } else {
        specs = new DataTableSpec[] { dbSpec.getDataTableSpec() };
    }
    m_panel.loadSettingsFrom(settings, specs);
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) DatabasePortObjectSpec(org.knime.core.node.port.database.DatabasePortObjectSpec)

Example 27 with DatabasePortObjectSpec

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

the class DBColumnFilterNodeModel method configure.

/**
 * {@inheritDoc}
 */
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
    DatabasePortObjectSpec spec = (DatabasePortObjectSpec) inSpecs[0];
    StringBuilder buf = new StringBuilder();
    for (String column : m_filter.getIncludeList()) {
        if (!spec.getDataTableSpec().containsName(column)) {
            buf.append("\"" + column + "\" ");
        }
    }
    if (buf.length() > 0) {
        throw new InvalidSettingsException("Not all columns available in " + "input spec: " + buf.toString());
    }
    DatabaseQueryConnectionSettings conn = spec.getConnectionSettings(getCredentialsProvider());
    ColumnRearranger colre = new ColumnRearranger(spec.getDataTableSpec());
    colre.keepOnly(m_filter.getIncludeList().toArray(new String[0]));
    final DataTableSpec resultSpec = colre.createSpec();
    final String newQuery = createQuery(conn, resultSpec);
    conn = createDBQueryConnection(spec, newQuery);
    return new PortObjectSpec[] { new DatabasePortObjectSpec(resultSpec, conn.createConnectionModel()) };
}
Also used : DatabaseQueryConnectionSettings(org.knime.core.node.port.database.DatabaseQueryConnectionSettings) DataTableSpec(org.knime.core.data.DataTableSpec) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) PortObjectSpec(org.knime.core.node.port.PortObjectSpec) DatabasePortObjectSpec(org.knime.core.node.port.database.DatabasePortObjectSpec) DatabasePortObjectSpec(org.knime.core.node.port.database.DatabasePortObjectSpec) SettingsModelFilterString(org.knime.core.node.defaultnodesettings.SettingsModelFilterString)

Example 28 with DatabasePortObjectSpec

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

the class DBColumnFilterNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected final PortObject[] execute(final PortObject[] inData, final ExecutionContext exec) throws CanceledExecutionException, Exception {
    DatabasePortObject dbObj = (DatabasePortObject) inData[0];
    DatabaseQueryConnectionSettings conn = dbObj.getConnectionSettings(getCredentialsProvider());
    ColumnRearranger colre = new ColumnRearranger(dbObj.getSpec().getDataTableSpec());
    colre.keepOnly(m_filter.getIncludeList().toArray(new String[0]));
    final DataTableSpec resultSpec = colre.createSpec();
    final String newQuery = createQuery(conn, resultSpec);
    conn = createDBQueryConnection(dbObj.getSpec(), newQuery);
    DatabasePortObjectSpec outSpec = new DatabasePortObjectSpec(resultSpec, conn.createConnectionModel());
    DatabasePortObject outObj = new DatabasePortObject(outSpec);
    return new PortObject[] { outObj };
}
Also used : DatabasePortObject(org.knime.core.node.port.database.DatabasePortObject) DatabaseQueryConnectionSettings(org.knime.core.node.port.database.DatabaseQueryConnectionSettings) DataTableSpec(org.knime.core.data.DataTableSpec) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) DatabasePortObjectSpec(org.knime.core.node.port.database.DatabasePortObjectSpec) SettingsModelFilterString(org.knime.core.node.defaultnodesettings.SettingsModelFilterString) DatabasePortObject(org.knime.core.node.port.database.DatabasePortObject) PortObject(org.knime.core.node.port.PortObject)

Example 29 with DatabasePortObjectSpec

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

the class DBConnectionWriterNodeModel method configure.

/**
 * {@inheritDoc}
 */
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
    if (inSpecs == null || inSpecs.length < 1 || inSpecs[0] == null) {
        throw new InvalidSettingsException("No input available");
    }
    // check table name
    final String table = m_tableName.getStringValue();
    if (table == null || table.trim().isEmpty()) {
        throw new InvalidSettingsException("Configure node and enter a valid table name.");
    }
    DatabasePortObjectSpec spec = (DatabasePortObjectSpec) inSpecs[0];
    try {
        final DatabaseQueryConnectionSettings conn = spec.getConnectionSettings(getCredentialsProvider());
        if (conn.getRetrieveMetadataInConfigure()) {
            conn.execute(getCredentialsProvider(), c -> {
                return c != null;
            });
        }
    } catch (InvalidSettingsException ise) {
        throw ise;
    } catch (Throwable t) {
        throw new InvalidSettingsException(t);
    }
    setWarningMessage("Existing table \"" + table + "\" will be dropped!");
    return new DataTableSpec[0];
}
Also used : DatabaseQueryConnectionSettings(org.knime.core.node.port.database.DatabaseQueryConnectionSettings) DataTableSpec(org.knime.core.data.DataTableSpec) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) DatabasePortObjectSpec(org.knime.core.node.port.database.DatabasePortObjectSpec) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString)

Example 30 with DatabasePortObjectSpec

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

the class DBJoinerNodeDialog method loadSettingsFrom.

/**
 * {@inheritDoc}
 */
@Override
protected void loadSettingsFrom(final NodeSettingsRO settings, final PortObjectSpec[] specs) throws NotConfigurableException {
    if (specs == null || specs.length < 2 || specs[0] == null || specs[1] == null) {
        throw new NotConfigurableException("No input specification available.");
    }
    DataTableSpec tableSpec1 = ((DatabasePortObjectSpec) specs[0]).getDataTableSpec();
    DataTableSpec tableSpec2 = ((DatabasePortObjectSpec) specs[1]).getDataTableSpec();
    DBJoinerSettings joinerSettings = new DBJoinerSettings();
    joinerSettings.loadSettingsInDialog(settings);
    m_joinMode.setSelectedItem(joinerSettings.getJoinMode());
    m_matchAllButton.setSelected(joinerSettings.getAndComposition());
    m_matchAnyButton.setSelected(!joinerSettings.getAndComposition());
    m_columnPairs.updateData(new DataTableSpec[] { tableSpec1, tableSpec2 }, joinerSettings.getLeftJoinOnColumns(), joinerSettings.getRightJoinOnColumns());
    m_leftFilterPanel.update(tableSpec1, false, joinerSettings.getLeftColumns());
    m_rightFilterPanel.update(tableSpec2, false, joinerSettings.getRightColumns());
    m_leftFilterPanel.setKeepAllSelected(joinerSettings.getAllLeftColumns());
    m_rightFilterPanel.setKeepAllSelected(joinerSettings.getAllRightColumns());
    m_removeLeftJoinCols.setSelected(joinerSettings.getFilterLeftJoinOnColumns());
    m_removeRightJoinCols.setSelected(joinerSettings.getFilterRightJoinOnColumns());
    m_suffix.setText(joinerSettings.getCustomSuffix());
    m_filterDuplicates.setSelected(joinerSettings.getDuplicateHandling().equals(DuplicateHandling.Filter));
    m_dontExecute.setSelected(joinerSettings.getDuplicateHandling().equals(DuplicateHandling.DontExecute));
    m_appendSuffixAutomatic.setSelected(joinerSettings.getDuplicateHandling().equals(DuplicateHandling.AppendSuffixAutomatic));
    m_appendSuffix.setSelected(joinerSettings.getDuplicateHandling().equals(DuplicateHandling.AppendSuffix));
    m_suffix.setEnabled(joinerSettings.getDuplicateHandling().equals(DuplicateHandling.AppendSuffix));
}
Also used : NotConfigurableException(org.knime.core.node.NotConfigurableException) DataTableSpec(org.knime.core.data.DataTableSpec) DatabasePortObjectSpec(org.knime.core.node.port.database.DatabasePortObjectSpec)

Aggregations

DatabasePortObjectSpec (org.knime.core.node.port.database.DatabasePortObjectSpec)46 DataTableSpec (org.knime.core.data.DataTableSpec)36 DatabaseQueryConnectionSettings (org.knime.core.node.port.database.DatabaseQueryConnectionSettings)33 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)29 SettingsModelString (org.knime.core.node.defaultnodesettings.SettingsModelString)14 DatabasePortObject (org.knime.core.node.port.database.DatabasePortObject)13 PortObjectSpec (org.knime.core.node.port.PortObjectSpec)12 DBReader (org.knime.core.node.port.database.reader.DBReader)12 PortObject (org.knime.core.node.port.PortObject)10 SettingsModelFilterString (org.knime.core.node.defaultnodesettings.SettingsModelFilterString)9 StatementManipulator (org.knime.core.node.port.database.StatementManipulator)8 SQLException (java.sql.SQLException)7 NotConfigurableException (org.knime.core.node.NotConfigurableException)5 DatabaseConnectionSettings (org.knime.core.node.port.database.DatabaseConnectionSettings)3 PMMLPortObject (org.knime.core.node.port.pmml.PMMLPortObject)3 GridBagConstraints (java.awt.GridBagConstraints)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 DBBinnerMaps (org.knime.base.node.io.database.binning.DBBinnerMaps)2 DBAggregationFunctionProvider (org.knime.base.node.io.database.groupby.dialog.DBAggregationFunctionProvider)2