Search in sources :

Example 1 with DBAggregationFunctionProvider

use of org.knime.base.node.io.database.groupby.dialog.DBAggregationFunctionProvider in project knime-core by knime.

the class DBPatternAggregationFunctionRow method loadFunctions.

/**
 * Loads the functions and handles invalid aggregation functions graceful.
 * @param settings {@link NodeSettingsRO}
 * @param key the config key
 * @param dbIdentifier the {@link AggregationFunctionProvider}
 * @param tableSpec the input {@link DataTableSpec}
 * @return {@link List} of {@link DBPatternAggregationFunctionRow}s
 * @throws InvalidSettingsException if the settings are invalid
 */
public static List<DBPatternAggregationFunctionRow> loadFunctions(final NodeSettingsRO settings, final String key, final String dbIdentifier, final DataTableSpec tableSpec) throws InvalidSettingsException {
    if (key == null || key.isEmpty()) {
        throw new IllegalArgumentException("key must not be null");
    }
    if (dbIdentifier == null || dbIdentifier.isEmpty()) {
        throw new IllegalArgumentException("dbIdentifier must not be empty");
    }
    if (settings == null || !settings.containsKey(key)) {
        return Collections.EMPTY_LIST;
    }
    final DatabaseUtility utility = DatabaseUtility.getUtility(dbIdentifier);
    DBAggregationFunctionProvider functionProvider = new DBAggregationFunctionProvider(utility);
    final NodeSettingsRO root = settings.getNodeSettings(key);
    final Set<String> settingsKeys = root.keySet();
    final List<DBPatternAggregationFunctionRow> colAggrList = new ArrayList<>(settingsKeys.size());
    for (String settingsKey : settingsKeys) {
        final NodeSettingsRO cfg = root.getNodeSettings(settingsKey);
        final String inputPattern = cfg.getString(CNFG_INPUT_PATTERN);
        final boolean isRegex = cfg.getBoolean(CNFG_IS_REGEX);
        final DBAggregationFunction function = AbstractDBAggregationFunctionRow.loadFunction(tableSpec, functionProvider, cfg);
        final DBPatternAggregationFunctionRow aggrFunctionRow = new DBPatternAggregationFunctionRow(inputPattern, isRegex, function);
        colAggrList.add(aggrFunctionRow);
    }
    return colAggrList;
}
Also used : DatabaseUtility(org.knime.core.node.port.database.DatabaseUtility) DBAggregationFunctionProvider(org.knime.base.node.io.database.groupby.dialog.DBAggregationFunctionProvider) ArrayList(java.util.ArrayList) DBAggregationFunction(org.knime.core.node.port.database.aggregation.DBAggregationFunction) NodeSettingsRO(org.knime.core.node.NodeSettingsRO)

Example 2 with DBAggregationFunctionProvider

use of org.knime.base.node.io.database.groupby.dialog.DBAggregationFunctionProvider in project knime-core by knime.

the class DBColumnAggregationFunctionPanel method loadSettingsFrom.

/**
 * @param settings the settings to read from
 * @param dbIdentifier the database identifier
 * @param spec initializes the component
 * @throws InvalidSettingsException if the settings are invalid
 */
public void loadSettingsFrom(final NodeSettingsRO settings, final String dbIdentifier, final DataTableSpec spec) throws InvalidSettingsException {
    final DatabaseUtility utility = DatabaseUtility.getUtility(dbIdentifier);
    setAggregationFunctionProvider(new DBAggregationFunctionProvider(utility));
    initialize(spec, DBColumnAggregationFunctionRow.loadFunctions(settings, m_key, dbIdentifier, spec));
}
Also used : DatabaseUtility(org.knime.core.node.port.database.DatabaseUtility) DBAggregationFunctionProvider(org.knime.base.node.io.database.groupby.dialog.DBAggregationFunctionProvider)

Example 3 with DBAggregationFunctionProvider

use of org.knime.base.node.io.database.groupby.dialog.DBAggregationFunctionProvider in project knime-core by knime.

the class DBPatternAggregationFunctionPanel method loadSettingsFrom.

/**
 * @param settings the settings to read from
 * @param dbIdentifier the database identifier
 * @param spec initializes the component
 * @throws InvalidSettingsException if the settings are invalid
 */
public void loadSettingsFrom(final NodeSettingsRO settings, final String dbIdentifier, final DataTableSpec spec) throws InvalidSettingsException {
    final DatabaseUtility utility = DatabaseUtility.getUtility(dbIdentifier);
    setAggregationFunctionProvider(new DBAggregationFunctionProvider(utility));
    initialize(spec, DBPatternAggregationFunctionRow.loadFunctions(settings, m_key, dbIdentifier, spec));
}
Also used : DatabaseUtility(org.knime.core.node.port.database.DatabaseUtility) DBAggregationFunctionProvider(org.knime.base.node.io.database.groupby.dialog.DBAggregationFunctionProvider)

Example 4 with DBAggregationFunctionProvider

use of org.knime.base.node.io.database.groupby.dialog.DBAggregationFunctionProvider 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 DBAggregationFunctionProvider

use of org.knime.base.node.io.database.groupby.dialog.DBAggregationFunctionProvider in project knime-core by knime.

the class DBGroupByNodeDialog2 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);
        m_patternPanel.loadSettingsFrom(settings, dbIdentifier, spec);
        m_typePanel.loadSettingsFrom(settings, dbIdentifier, spec);
        m_addCountStar.loadSettingsFrom(settings);
        m_countStarColName.loadSettingsFrom(settings);
        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 });
    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) DialogComponentString(org.knime.core.node.defaultnodesettings.DialogComponentString) SettingsModelFilterString(org.knime.core.node.defaultnodesettings.SettingsModelFilterString) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString)

Aggregations

DBAggregationFunctionProvider (org.knime.base.node.io.database.groupby.dialog.DBAggregationFunctionProvider)8 DatabaseUtility (org.knime.core.node.port.database.DatabaseUtility)6 ArrayList (java.util.ArrayList)3 NodeSettingsRO (org.knime.core.node.NodeSettingsRO)3 DBAggregationFunction (org.knime.core.node.port.database.aggregation.DBAggregationFunction)3 GridBagConstraints (java.awt.GridBagConstraints)2 DataTableSpec (org.knime.core.data.DataTableSpec)2 DataType (org.knime.core.data.DataType)2 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)2 NotConfigurableException (org.knime.core.node.NotConfigurableException)2 SettingsModelFilterString (org.knime.core.node.defaultnodesettings.SettingsModelFilterString)2 SettingsModelString (org.knime.core.node.defaultnodesettings.SettingsModelString)2 DatabasePortObjectSpec (org.knime.core.node.port.database.DatabasePortObjectSpec)2 DatabaseQueryConnectionSettings (org.knime.core.node.port.database.DatabaseQueryConnectionSettings)2 DataColumnSpec (org.knime.core.data.DataColumnSpec)1 DataColumnSpecCreator (org.knime.core.data.DataColumnSpecCreator)1 DialogComponentString (org.knime.core.node.defaultnodesettings.DialogComponentString)1