Search in sources :

Example 21 with DatabasePortObject

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

the class DBTableSelectorNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected PortObject[] execute(final PortObject[] inObjects, final ExecutionContext exec) throws Exception {
    exec.setMessage("Retrieving metadata from database");
    DatabaseConnectionPortObject incomingConnection = (DatabaseConnectionPortObject) inObjects[0];
    DatabaseConnectionSettings connSettings = incomingConnection.getConnectionSettings(getCredentialsProvider());
    String sql = FlowVariableResolver.parse(m_settings.getQuery(), this);
    DatabaseQueryConnectionSettings querySettings = new DatabaseQueryConnectionSettings(connSettings, sql);
    DBReader conn = querySettings.getUtility().getReader(querySettings);
    try {
        DataTableSpec tableSpec = conn.getDataTableSpec(getCredentialsProvider());
        return new PortObject[] { new DatabasePortObject(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: " + cause.getMessage(), ex);
    }
}
Also used : DatabasePortObject(org.knime.core.node.port.database.DatabasePortObject) DatabaseConnectionPortObject(org.knime.core.node.port.database.DatabaseConnectionPortObject) DatabaseQueryConnectionSettings(org.knime.core.node.port.database.DatabaseQueryConnectionSettings) DataTableSpec(org.knime.core.data.DataTableSpec) DBReader(org.knime.core.node.port.database.reader.DBReader) DatabaseConnectionSettings(org.knime.core.node.port.database.DatabaseConnectionSettings) SQLException(java.sql.SQLException) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) DatabasePortObjectSpec(org.knime.core.node.port.database.DatabasePortObjectSpec) DatabaseConnectionPortObject(org.knime.core.node.port.database.DatabaseConnectionPortObject) DatabasePortObject(org.knime.core.node.port.database.DatabasePortObject) PortObject(org.knime.core.node.port.PortObject)

Example 22 with DatabasePortObject

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

the class DBGroupByNodeModel2 method execute.

/**
 * {@inheritDoc}
 */
@Override
protected final PortObject[] execute(final PortObject[] inData, final ExecutionContext exec) throws CanceledExecutionException, Exception {
    exec.setMessage("Retrieving metadata from database");
    final DatabasePortObject dbObject = (DatabasePortObject) inData[0];
    final DatabasePortObject outObject = new DatabasePortObject(createDbOutSpec(dbObject.getSpec(), false));
    return new PortObject[] { outObject };
}
Also used : DatabasePortObject(org.knime.core.node.port.database.DatabasePortObject) DatabasePortObject(org.knime.core.node.port.database.DatabasePortObject) PortObject(org.knime.core.node.port.PortObject)

Example 23 with DatabasePortObject

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

the class ParameterizedDBQueryNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected PortObject[] execute(final PortObject[] inData, final ExecutionContext exec) throws Exception {
    final BufferedDataTable inTable = (BufferedDataTable) inData[0];
    final DatabasePortObject dbObject = (DatabasePortObject) inData[1];
    DatabaseQueryConnectionSettings conn = dbObject.getConnectionSettings(getCredentialsProvider());
    final String newQuery = parseSQLStatement(inTable.getDataTableSpec(), conn.getQuery());
    conn = createDBQueryConnection(dbObject.getSpec(), newQuery);
    final DBReader reader = conn.getUtility().getReader(conn);
    final DataTableRowInput data = new DataTableRowInput(inTable);
    final BufferedDataTable outTable = reader.loopTable(exec, getCredentialsProvider(), data, inTable.size(), m_failIfExceptionModel.getBooleanValue(), m_appendInputColumnsModel.getBooleanValue(), m_includeEmptyResultsModel.getBooleanValue(), m_retainAllColumnsModel.getBooleanValue(), m_dataColumns.toArray(new String[m_dataColumns.size()])).getDataTable();
    final BufferedDataTable errorTable = reader.getErrorDataTable();
    return new BufferedDataTable[] { outTable, errorTable };
}
Also used : DatabasePortObject(org.knime.core.node.port.database.DatabasePortObject) DatabaseQueryConnectionSettings(org.knime.core.node.port.database.DatabaseQueryConnectionSettings) DBReader(org.knime.core.node.port.database.reader.DBReader) BufferedDataTable(org.knime.core.node.BufferedDataTable) DataTableRowInput(org.knime.core.node.streamable.DataTableRowInput)

Example 24 with DatabasePortObject

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

the class DBSamplingNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected final PortObject[] execute(final PortObject[] inData, final ExecutionContext exec) throws CanceledExecutionException, Exception {
    final DatabasePortObject dbObject = (DatabasePortObject) inData[0];
    final DatabasePortObject outObject = new DatabasePortObject(createDbOutSpec(dbObject.getSpec(), exec, false));
    return new PortObject[] { outObject };
}
Also used : DatabasePortObject(org.knime.core.node.port.database.DatabasePortObject) DatabasePortObject(org.knime.core.node.port.database.DatabasePortObject) PortObject(org.knime.core.node.port.PortObject)

Aggregations

DatabasePortObject (org.knime.core.node.port.database.DatabasePortObject)24 PortObject (org.knime.core.node.port.PortObject)18 DatabaseQueryConnectionSettings (org.knime.core.node.port.database.DatabaseQueryConnectionSettings)17 DatabasePortObjectSpec (org.knime.core.node.port.database.DatabasePortObjectSpec)13 DBReader (org.knime.core.node.port.database.reader.DBReader)8 DataTableSpec (org.knime.core.data.DataTableSpec)7 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)6 SettingsModelString (org.knime.core.node.defaultnodesettings.SettingsModelString)5 BufferedDataTable (org.knime.core.node.BufferedDataTable)4 PMMLPortObject (org.knime.core.node.port.pmml.PMMLPortObject)4 SQLException (java.sql.SQLException)3 StatementManipulator (org.knime.core.node.port.database.StatementManipulator)3 CredentialsProvider (org.knime.core.node.workflow.CredentialsProvider)3 DatabaseConnectionPortObject (org.knime.core.node.port.database.DatabaseConnectionPortObject)2 DatabaseConnectionSettings (org.knime.core.node.port.database.DatabaseConnectionSettings)2 FlowVariablePortObject (org.knime.core.node.port.flowvariable.FlowVariablePortObject)2 IOException (java.io.IOException)1 DBBinnerMaps (org.knime.base.node.io.database.binning.DBBinnerMaps)1 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)1 DataContainer (org.knime.core.data.container.DataContainer)1