Search in sources :

Example 16 with DatabasePortObjectSpec

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

the class DBNumericBinnerNodeModel method createDatabasePortObjectSpec.

private DatabasePortObjectSpec createDatabasePortObjectSpec(DatabaseQueryConnectionSettings connectionSettings, final DatabasePortObjectSpec inDatabasePortObjectSpec, final DBBinnerMaps binnerMaps) throws InvalidSettingsException, SQLException, BadPaddingException, IllegalBlockSizeException, InvalidKeyException, IOException {
    final StatementManipulator statementManipulator = connectionSettings.getUtility().getStatementManipulator();
    final String newQuery = createQuery(connectionSettings.getQuery(), statementManipulator, inDatabasePortObjectSpec.getDataTableSpec(), binnerMaps);
    connectionSettings = createDBQueryConnection(inDatabasePortObjectSpec, newQuery);
    final DatabaseQueryConnectionSettings querySettings = new DatabaseQueryConnectionSettings(connectionSettings, newQuery);
    DBReader reader = querySettings.getUtility().getReader(querySettings);
    DataTableSpec outDataTableSpec = reader.getDataTableSpec(getCredentialsProvider());
    DatabasePortObjectSpec outDatabasePortObjectSpec = new DatabasePortObjectSpec(outDataTableSpec, connectionSettings.createConnectionModel());
    return outDatabasePortObjectSpec;
}
Also used : DatabaseQueryConnectionSettings(org.knime.core.node.port.database.DatabaseQueryConnectionSettings) DataTableSpec(org.knime.core.data.DataTableSpec) DBReader(org.knime.core.node.port.database.reader.DBReader) DatabasePortObjectSpec(org.knime.core.node.port.database.DatabasePortObjectSpec) StatementManipulator(org.knime.core.node.port.database.StatementManipulator)

Example 17 with DatabasePortObjectSpec

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

the class DBNumericBinnerNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected final PortObject[] execute(final PortObject[] inData, final ExecutionContext exec) throws CanceledExecutionException, Exception {
    exec.setMessage("Retrieving metadata from database");
    checkDuplicateBinNames();
    final DatabasePortObject inDatabasePortObject = (DatabasePortObject) inData[0];
    final DatabasePortObjectSpec inDatabasePortObjectSpec = inDatabasePortObject.getSpec();
    DatabaseQueryConnectionSettings connectionSettings = inDatabasePortObject.getConnectionSettings(getCredentialsProvider());
    DataTableSpec outDataTableSpec = DBAutoBinner.createNewDataTableSpec(inDatabasePortObjectSpec.getDataTableSpec(), m_columnToAppended);
    PMMLPortObject outPMMLPortObject = createPMMLPortObject(inDatabasePortObjectSpec.getDataTableSpec(), outDataTableSpec);
    DBBinnerMaps binnerMaps = DBAutoBinner.intoBinnerMaps(outPMMLPortObject, inDatabasePortObjectSpec.getDataTableSpec());
    DatabasePortObjectSpec outDatabasePortObjectSpec = createDatabasePortObjectSpec(connectionSettings, inDatabasePortObjectSpec, binnerMaps);
    return new PortObject[] { new DatabasePortObject(outDatabasePortObjectSpec), outPMMLPortObject };
}
Also used : DatabasePortObject(org.knime.core.node.port.database.DatabasePortObject) DBBinnerMaps(org.knime.base.node.io.database.binning.DBBinnerMaps) DatabaseQueryConnectionSettings(org.knime.core.node.port.database.DatabaseQueryConnectionSettings) DataTableSpec(org.knime.core.data.DataTableSpec) PMMLPortObject(org.knime.core.node.port.pmml.PMMLPortObject) DatabasePortObjectSpec(org.knime.core.node.port.database.DatabasePortObjectSpec) PMMLPortObject(org.knime.core.node.port.pmml.PMMLPortObject) DatabasePortObject(org.knime.core.node.port.database.DatabasePortObject) PortObject(org.knime.core.node.port.PortObject)

Example 18 with DatabasePortObjectSpec

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

the class DBTableSelectorNodeModel method configure.

/**
 * {@inheritDoc}
 */
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
    if ((m_settings.getQuery() == null) || m_settings.getQuery().isEmpty()) {
        throw new InvalidSettingsException("No query configured");
    }
    DatabaseConnectionPortObjectSpec incomingConnection = (DatabaseConnectionPortObjectSpec) inSpecs[0];
    DatabaseConnectionSettings connSettings = incomingConnection.getConnectionSettings(getCredentialsProvider());
    String sql = FlowVariableResolver.parse(m_settings.getQuery(), this);
    DatabaseQueryConnectionSettings querySettings = new DatabaseQueryConnectionSettings(connSettings, sql);
    final DBReader conn = connSettings.getUtility().getReader(querySettings);
    if (!connSettings.getRetrieveMetadataInConfigure()) {
        return new PortObjectSpec[1];
    }
    try {
        DataTableSpec tableSpec = conn.getDataTableSpec(getCredentialsProvider());
        return new PortObjectSpec[] { new DatabasePortObjectSpec(tableSpec, querySettings) };
    } catch (SQLException ex) {
        Throwable cause = ExceptionUtils.getRootCause(ex);
        if (cause == null) {
            cause = ex;
        }
        throw new InvalidSettingsException("Error while validating SQL query '" + sql + "' : " + cause.getMessage(), ex);
    }
}
Also used : DatabaseQueryConnectionSettings(org.knime.core.node.port.database.DatabaseQueryConnectionSettings) DataTableSpec(org.knime.core.data.DataTableSpec) DBReader(org.knime.core.node.port.database.reader.DBReader) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) DatabaseConnectionSettings(org.knime.core.node.port.database.DatabaseConnectionSettings) SQLException(java.sql.SQLException) PortObjectSpec(org.knime.core.node.port.PortObjectSpec) DatabasePortObjectSpec(org.knime.core.node.port.database.DatabasePortObjectSpec) DatabaseConnectionPortObjectSpec(org.knime.core.node.port.database.DatabaseConnectionPortObjectSpec) DatabasePortObjectSpec(org.knime.core.node.port.database.DatabasePortObjectSpec) DatabaseConnectionPortObjectSpec(org.knime.core.node.port.database.DatabaseConnectionPortObjectSpec)

Example 19 with DatabasePortObjectSpec

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

the class DBColumnRenameNodeModel method createDBOutSpec.

private DatabasePortObjectSpec createDBOutSpec(final DatabasePortObjectSpec inSpec) throws InvalidSettingsException {
    if (m_config == null) {
        throw new InvalidSettingsException("No configuration available");
    }
    final DataTableSpec tableSpec = inSpec.getDataTableSpec();
    final DataTableSpec outSpec = m_config.getNewSpec(tableSpec);
    final List<String> missingColumnNames = m_config.getMissingColumnNames();
    if (missingColumnNames != null && !missingColumnNames.isEmpty()) {
        setWarningMessage("The following columns are configured but no longer exist: " + ConvenienceMethods.getShortStringFrom(missingColumnNames, 5));
    }
    DatabaseQueryConnectionSettings conn = inSpec.getConnectionSettings(getCredentialsProvider());
    final StatementManipulator statementManipulator = conn.getUtility().getStatementManipulator();
    String newQuery = createQuery(conn.getQuery(), tableSpec, statementManipulator);
    conn = createDBQueryConnection(inSpec, newQuery);
    return new DatabasePortObjectSpec(outSpec, conn.createConnectionModel());
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) DatabaseQueryConnectionSettings(org.knime.core.node.port.database.DatabaseQueryConnectionSettings) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) DatabasePortObjectSpec(org.knime.core.node.port.database.DatabasePortObjectSpec) StatementManipulator(org.knime.core.node.port.database.StatementManipulator)

Example 20 with DatabasePortObjectSpec

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

the class DBQueryNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected final PortObject[] execute(final PortObject[] inData, final ExecutionContext exec) throws CanceledExecutionException, Exception {
    DatabasePortObject dbObj = (DatabasePortObject) inData[0];
    CredentialsProvider cp = getCredentialsProvider();
    DatabaseQueryConnectionSettings conn = dbObj.getConnectionSettings(cp);
    String newQuery = createQuery(conn.getQuery());
    conn = createDBQueryConnection(dbObj.getSpec(), newQuery);
    DBReader load = conn.getUtility().getReader(conn);
    DataTableSpec outSpec = load.getDataTableSpec(cp);
    DatabasePortObjectSpec dbSpec = new DatabasePortObjectSpec(outSpec, conn.createConnectionModel());
    DatabasePortObject outObj = new DatabasePortObject(dbSpec);
    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) DBReader(org.knime.core.node.port.database.reader.DBReader) DatabasePortObjectSpec(org.knime.core.node.port.database.DatabasePortObjectSpec) CredentialsProvider(org.knime.core.node.workflow.CredentialsProvider) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) DatabasePortObject(org.knime.core.node.port.database.DatabasePortObject) PortObject(org.knime.core.node.port.PortObject)

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