Search in sources :

Example 16 with DatabasePortObject

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

the class DBJoinerNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected final PortObject[] execute(final PortObject[] inData, final ExecutionContext exec) throws CanceledExecutionException, Exception {
    exec.setMessage("Retrieving metadata from database");
    DatabasePortObject dbObjectLeft = (DatabasePortObject) inData[0];
    DatabasePortObject dbObjectRight = (DatabasePortObject) inData[1];
    DatabasePortObject outObject = new DatabasePortObject(createDbOutSpec(dbObjectLeft.getSpec(), dbObjectRight.getSpec()));
    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 17 with DatabasePortObject

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

the class DBReaderConnectionNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected PortObject[] execute(final PortObject[] inData, final ExecutionContext exec) throws CanceledExecutionException, Exception {
    // DatabaseQueryConnectionSettings conn = m_load.getQueryConnection();
    DatabaseQueryConnectionSettings conn = new DatabaseQueryConnectionSettings(m_conn, parseQuery(m_conn.getQuery()));
    DBReader load = conn.getUtility().getReader(conn);
    DataTableSpec spec = load.getDataTableSpec(getCredentialsProvider());
    DatabasePortObject dbObj = new DatabasePortObject(new DatabasePortObjectSpec(spec, conn.createConnectionModel()));
    return new PortObject[] { dbObj };
}
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) DatabasePortObject(org.knime.core.node.port.database.DatabasePortObject) PortObject(org.knime.core.node.port.PortObject)

Example 18 with DatabasePortObject

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

the class DBRowFilterNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected final PortObject[] execute(final PortObject[] inData, final ExecutionContext exec) throws CanceledExecutionException, Exception {
    DatabasePortObject dbObj = (DatabasePortObject) inData[0];
    DatabaseQueryConnectionSettings conn = dbObj.getConnectionSettings(getCredentialsProvider());
    String newQuery = createQuery(conn.getQuery(), conn.getUtility().getStatementManipulator());
    conn = createDBQueryConnection(dbObj.getSpec(), newQuery);
    DatabasePortObject outObj = new DatabasePortObject(new DatabasePortObjectSpec(dbObj.getSpec().getDataTableSpec(), conn.createConnectionModel()));
    return new PortObject[] { outObj };
}
Also used : DatabasePortObject(org.knime.core.node.port.database.DatabasePortObject) DatabaseQueryConnectionSettings(org.knime.core.node.port.database.DatabaseQueryConnectionSettings) DatabasePortObjectSpec(org.knime.core.node.port.database.DatabasePortObjectSpec) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) DatabasePortObject(org.knime.core.node.port.database.DatabasePortObject) PortObject(org.knime.core.node.port.PortObject)

Example 19 with DatabasePortObject

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

the class SQLExtractNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected PortObject[] execute(final PortObject[] inData, final ExecutionContext exec) throws Exception {
    DatabasePortObject dbIn = (DatabasePortObject) inData[0];
    String query = dbIn.getConnectionSettings(getCredentialsProvider()).getQuery();
    final String flowVarName = m_flowVariableName.getStringValue();
    pushFlowVariableString(flowVarName, query);
    // Create a table with the SQL query in a StringCell
    DataContainer container = exec.createDataContainer(createSpec(flowVarName));
    container.addRowToTable(new DefaultRow(RowKey.createRowKey(0), new StringCell(query)));
    container.close();
    BufferedDataTable outTable = (BufferedDataTable) container.getTable();
    return new PortObject[] { FlowVariablePortObject.INSTANCE, outTable };
}
Also used : DatabasePortObject(org.knime.core.node.port.database.DatabasePortObject) DataContainer(org.knime.core.data.container.DataContainer) StringCell(org.knime.core.data.def.StringCell) BufferedDataTable(org.knime.core.node.BufferedDataTable) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) DefaultRow(org.knime.core.data.def.DefaultRow) FlowVariablePortObject(org.knime.core.node.port.flowvariable.FlowVariablePortObject) DatabasePortObject(org.knime.core.node.port.database.DatabasePortObject) PortObject(org.knime.core.node.port.PortObject)

Example 20 with DatabasePortObject

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

the class DBApplyBinnerNodeModel method createDatabasePortObject.

private DatabasePortObject createDatabasePortObject(final DatabasePortObjectSpec inSpec, DatabaseQueryConnectionSettings connectionSettings, final PMMLPortObject pmmlPortObject) throws InvalidSettingsException {
    final StatementManipulator statementManipulator = connectionSettings.getUtility().getStatementManipulator();
    String newQuery = createQuery(connectionSettings.getQuery(), statementManipulator, inSpec.getDataTableSpec(), pmmlPortObject);
    connectionSettings = createDBQueryConnection(inSpec, newQuery);
    DatabaseQueryConnectionSettings querySettings = new DatabaseQueryConnectionSettings(connectionSettings, newQuery);
    DBReader reader = querySettings.getUtility().getReader(querySettings);
    try {
        DatabasePortObjectSpec databasePortObjectSpec = new DatabasePortObjectSpec(reader.getDataTableSpec(getCredentialsProvider()), connectionSettings.createConnectionModel());
        DatabasePortObject databasePortObject = new DatabasePortObject(databasePortObjectSpec);
        return databasePortObject;
    } catch (SQLException e) {
        throw new InvalidSettingsException("Failure during query generation. Error: " + e.getMessage());
    }
}
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) SQLException(java.sql.SQLException) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) DatabasePortObjectSpec(org.knime.core.node.port.database.DatabasePortObjectSpec) StatementManipulator(org.knime.core.node.port.database.StatementManipulator)

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