Search in sources :

Example 1 with InvalidDBAggregationFunction

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

the class AbstractDBAggregationFunctionRow method loadFunction.

/**
 * @param tableSpec optional input {@link DataTableSpec}
 * @param functionProvider the {@link DBAggregationFunctionProvider}
 * @param cfg {@link NodeSettingsRO} to read from
 * @return the {@link DBAggregationFunction}
 * @throws InvalidSettingsException if the settings of the function are invalid
 */
public static DBAggregationFunction loadFunction(final DataTableSpec tableSpec, final DBAggregationFunctionProvider functionProvider, final NodeSettingsRO cfg) throws InvalidSettingsException {
    final String functionId = cfg.getString(CNFG_AGGR_COL_SECTION);
    DBAggregationFunction function = functionProvider.getFunction(functionId);
    if (function instanceof InvalidAggregationFunction) {
        final String errMsg = "Exception while loading database aggregation functions. " + ((InvalidAggregationFunction) function).getErrorMessage();
        LOGGER.warn(errMsg);
    } else {
        if (function.hasOptionalSettings()) {
            try {
                final NodeSettingsRO subSettings = cfg.getNodeSettings("functionSettings");
                if (tableSpec != null) {
                    // this method is called from the dialog
                    function.loadSettingsFrom(subSettings, tableSpec);
                } else {
                    // this method is called from the node model where we do not
                    // have the DataTableSpec
                    function.loadValidatedSettings(subSettings);
                }
            } catch (Exception e) {
                final String errMsg = "Exception while loading settings for aggreation function '" + function.getId() + "', reason: " + e.getMessage();
                function = new InvalidDBAggregationFunction(functionId, errMsg, null);
                LOGGER.error(errMsg);
            }
        }
    }
    return function;
}
Also used : InvalidAggregationFunction(org.knime.core.node.port.database.aggregation.InvalidAggregationFunction) InvalidDBAggregationFunction(org.knime.core.node.port.database.aggregation.InvalidDBAggregationFunction) DBAggregationFunction(org.knime.core.node.port.database.aggregation.DBAggregationFunction) NodeSettingsRO(org.knime.core.node.NodeSettingsRO) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) InvalidDBAggregationFunction(org.knime.core.node.port.database.aggregation.InvalidDBAggregationFunction)

Example 2 with InvalidDBAggregationFunction

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

the class DatabaseUtility method getAggregationFunction.

/**
 * Returns the aggregation function with the given id, if the current database supports it.
 * Otherwise a {@link InvalidDBAggregationFunction} is returned.
 *
 * @param id the id as returned by {@link DBAggregationFunction#getId()}
 * @return the {@link DBAggregationFunction} for the given name or an instance of the
 * {@link InvalidDBAggregationFunction} that has the given id
 * @since 2.11
 */
public DBAggregationFunction getAggregationFunction(final String id) {
    final DBAggregationFunctionFactory function = m_aggregationFunctions.get(id);
    if (function != null) {
        return function.createInstance();
    }
    final String dbIdentifier = getDatabaseIdentifier();
    String msg = "The function '" + id + "' is not supported by ";
    if (dbIdentifier != null) {
        msg += dbIdentifier + ".";
    } else {
        msg += "the current database.";
    }
    return new InvalidDBAggregationFunction(id, msg, dbIdentifier);
}
Also used : DBAggregationFunctionFactory(org.knime.core.node.port.database.aggregation.DBAggregationFunctionFactory) InvalidDBAggregationFunction(org.knime.core.node.port.database.aggregation.InvalidDBAggregationFunction)

Aggregations

InvalidDBAggregationFunction (org.knime.core.node.port.database.aggregation.InvalidDBAggregationFunction)2 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)1 NodeSettingsRO (org.knime.core.node.NodeSettingsRO)1 DBAggregationFunction (org.knime.core.node.port.database.aggregation.DBAggregationFunction)1 DBAggregationFunctionFactory (org.knime.core.node.port.database.aggregation.DBAggregationFunctionFactory)1 InvalidAggregationFunction (org.knime.core.node.port.database.aggregation.InvalidAggregationFunction)1