Search in sources :

Example 1 with DatabasePortObjectSpec

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

the class DBGroupByNodeDialog method loadSettingsFrom.

/**
 * {@inheritDoc}
 */
@Override
protected void loadSettingsFrom(final NodeSettingsRO settings, final PortObjectSpec[] specs) throws NotConfigurableException {
    if (specs == null || specs.length < 1 || specs[0] == null) {
        throw new NotConfigurableException("No input spec available");
    }
    final DatabasePortObjectSpec dbspec = (DatabasePortObjectSpec) specs[0];
    final DataTableSpec spec = dbspec.getDataTableSpec();
    try {
        m_columnNamePolicy.loadSettingsFrom(settings);
    } catch (final InvalidSettingsException e) {
        throw new NotConfigurableException(e.getMessage());
    }
    m_aggregationPanel.loadSettingsFrom(settings, dbspec, spec);
    m_groupCol.loadSettingsFrom(settings, new DataTableSpec[] { spec });
    columnsChanged();
}
Also used : NotConfigurableException(org.knime.core.node.NotConfigurableException) DataTableSpec(org.knime.core.data.DataTableSpec) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) DatabasePortObjectSpec(org.knime.core.node.port.database.DatabasePortObjectSpec)

Example 2 with DatabasePortObjectSpec

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

the class DBGroupByNodeModel method createDbOutSpec.

/**
 * @param inSpec Spec of the input database object
 * @param checkRetrieveMetadata true if the retrieveMetadataInConfigure settings should be respected,
 *            <code>false</code> if the metadata should be retrieved in any case (for execute)
 * @return Spec of the output database object
 * @throws InvalidSettingsException If the current settings are invalid
 */
private DatabasePortObjectSpec createDbOutSpec(final DatabasePortObjectSpec inSpec, final boolean checkRetrieveMetadata) throws InvalidSettingsException {
    if (m_groupByCols.getIncludeList().isEmpty() && m_aggregatedColumns.length == 0) {
        throw new InvalidSettingsException("Please select at least one group or aggregation column");
    }
    DatabaseQueryConnectionSettings connection = inSpec.getConnectionSettings(getCredentialsProvider());
    String newQuery = createQuery(connection.getQuery(), connection.getUtility().getStatementManipulator());
    connection = createDBQueryConnection(inSpec, newQuery);
    if (checkRetrieveMetadata && !connection.getRetrieveMetadataInConfigure()) {
        return null;
    }
    DataTableSpec tableSpec = createOutSpec(inSpec.getDataTableSpec(), connection, newQuery, checkRetrieveMetadata);
    return new DatabasePortObjectSpec(tableSpec, connection.createConnectionModel());
}
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) SettingsModelFilterString(org.knime.core.node.defaultnodesettings.SettingsModelFilterString) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString)

Example 3 with DatabasePortObjectSpec

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

the class ParameterizedDBQueryNodeModel method configure.

/**
 * {@inheritDoc}
 */
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
    final DataTableSpec inSpec = (DataTableSpec) inSpecs[0];
    if (inSpec.getNumColumns() < 1) {
        throw new InvalidSettingsException("No column spec available.");
    }
    if ((inSpecs[1] == null) || !(inSpecs[1] instanceof DatabasePortObjectSpec)) {
        throw new InvalidSettingsException("No valid database connection available.");
    }
    final DatabasePortObjectSpec dbSpec = (DatabasePortObjectSpec) inSpecs[1];
    parseSQLStatement(inSpec, dbSpec.getConnectionSettings(getCredentialsProvider()).getQuery());
    return new DataTableSpec[] { null, null };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) DatabasePortObjectSpec(org.knime.core.node.port.database.DatabasePortObjectSpec)

Example 4 with DatabasePortObjectSpec

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

the class DBPivotNodeDialog method loadSettingsFrom.

/**
 * {@inheritDoc}
 */
@Override
protected void loadSettingsFrom(final NodeSettingsRO settings, final PortObjectSpec[] specs) throws NotConfigurableException {
    if (specs == null || specs.length < 1 || specs[0] == null) {
        throw new NotConfigurableException("No input connection found.");
    }
    final DatabasePortObjectSpec dbspec = (DatabasePortObjectSpec) specs[0];
    final DataTableSpec spec = dbspec.getDataTableSpec();
    try {
        final DatabaseQueryConnectionSettings connectionSettings = dbspec.getConnectionSettings(null);
        m_columnNamePolicy.loadSettingsFrom(settings);
        final String dbIdentifier = connectionSettings.getDatabaseIdentifier();
        m_aggregationPanel.loadSettingsFrom(settings, dbIdentifier, spec);
        final DBAggregationFunctionProvider functionProvider = new DBAggregationFunctionProvider(connectionSettings.getUtility());
        m_descriptionTab.removeAll();
        final GridBagConstraints c = new GridBagConstraints();
        c.anchor = GridBagConstraints.CENTER;
        c.fill = GridBagConstraints.BOTH;
        c.weightx = 1;
        c.weighty = 1;
        m_descriptionTab.add(functionProvider.getDescriptionPane(), c);
    } catch (final InvalidSettingsException e) {
        throw new NotConfigurableException(e.getMessage());
    }
    m_groupCol.loadSettingsFrom(settings, new DataTableSpec[] { spec });
    m_pivotCol.loadSettingsFrom(settings, new DataTableSpec[] { spec });
    columnsChanged();
}
Also used : NotConfigurableException(org.knime.core.node.NotConfigurableException) DataTableSpec(org.knime.core.data.DataTableSpec) DatabaseQueryConnectionSettings(org.knime.core.node.port.database.DatabaseQueryConnectionSettings) GridBagConstraints(java.awt.GridBagConstraints) DBAggregationFunctionProvider(org.knime.base.node.io.database.groupby.dialog.DBAggregationFunctionProvider) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) DatabasePortObjectSpec(org.knime.core.node.port.database.DatabasePortObjectSpec) SettingsModelFilterString(org.knime.core.node.defaultnodesettings.SettingsModelFilterString) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString)

Example 5 with DatabasePortObjectSpec

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

the class DBSamplingNodeDialog method loadSettingsFrom.

/**
 * {@inheritDoc}
 */
@SuppressWarnings("null")
@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() };
    }
    boolean random;
    try {
        random = dbSpec.getConnectionSettings(getCredentialsProvider()).getUtility().supportsRandomSampling();
    } catch (InvalidSettingsException e) {
        throw new NotConfigurableException(e.getMessage());
    }
    m_countComp.loadSettingsFrom(settings, specs);
    m_absoluteComp.loadSettingsFrom(settings, specs);
    m_relativeComp.loadSettingsFrom(settings, specs);
    m_samplingComp.loadSettingsFrom(settings, specs);
    m_stratifiedComp.loadSettingsFrom(settings, specs);
    m_columnComp.loadSettingsFrom(settings, specs);
    if (!random) {
        m_samplingComp.setToolTipText("Connected database does not support random sampling");
        m_samplingMethod.setStringValue(DBSamplingNodeModel.SamplingMethod.FIRST.getActionCommand());
    } else {
        m_samplingComp.setToolTipText(null);
    }
    m_samplingMethod.setEnabled(random);
}
Also used : NotConfigurableException(org.knime.core.node.NotConfigurableException) DataTableSpec(org.knime.core.data.DataTableSpec) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) 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