Search in sources :

Example 1 with DatabasePortObject

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

the class DBGroupByNodeModel method execute.

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

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

the class DBPivotNodeModel 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(), exec));
    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 3 with DatabasePortObject

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

the class DBSorterNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected final PortObject[] execute(final PortObject[] inData, final ExecutionContext exec) throws CanceledExecutionException, Exception {
    exec.setMessage("Retrieving metadata from database");
    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) DatabasePortObject(org.knime.core.node.port.database.DatabasePortObject) PortObject(org.knime.core.node.port.PortObject)

Example 4 with DatabasePortObject

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

the class SQLInjectNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected PortObject[] execute(final PortObject[] inData, final ExecutionContext exec) throws Exception {
    exec.setMessage("Retrieving metadata from database");
    final String varName = m_flowVariableName.getStringValue();
    if (varName == null) {
        throw new InvalidSettingsException("No flow variable for the SQL statement selected");
    }
    final String sql = peekFlowVariableString(varName);
    if (sql == null) {
        throw new InvalidSettingsException("The selected flow variable is not assigned");
    }
    DatabaseConnectionPortObject dbIn = (DatabaseConnectionPortObject) inData[0];
    DatabaseConnectionSettings inSettings = dbIn.getConnectionSettings(getCredentialsProvider());
    // Attach the SQL query
    DatabaseQueryConnectionSettings outSettings = new DatabaseQueryConnectionSettings(inSettings, sql);
    // Probe the database to see how the result table looks like
    DBReader load = outSettings.getUtility().getReader(outSettings);
    DataTableSpec tableSpec = load.getDataTableSpec(getCredentialsProvider());
    DatabasePortObjectSpec outSpec = new DatabasePortObjectSpec(tableSpec, outSettings.createConnectionModel());
    return new PortObject[] { new DatabasePortObject(outSpec) };
}
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) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) DatabaseConnectionSettings(org.knime.core.node.port.database.DatabaseConnectionSettings) DatabasePortObjectSpec(org.knime.core.node.port.database.DatabasePortObjectSpec) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) DatabaseConnectionPortObject(org.knime.core.node.port.database.DatabaseConnectionPortObject) FlowVariablePortObject(org.knime.core.node.port.flowvariable.FlowVariablePortObject) DatabasePortObject(org.knime.core.node.port.database.DatabasePortObject) PortObject(org.knime.core.node.port.PortObject)

Example 5 with DatabasePortObject

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

the class DBAutoBinnerNodeModel 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);
    DatabaseReaderConnection conn = new DatabaseReaderConnection(querySettings);
    DatabasePortObjectSpec databasePortObjectSpec = null;
    try {
        databasePortObjectSpec = new DatabasePortObjectSpec(conn.getDataTableSpec(getCredentialsProvider()), connectionSettings.createConnectionModel());
    } catch (SQLException e) {
        throw new InvalidSettingsException("Failure during query generation. Error: " + e.getMessage());
    }
    DatabasePortObject databasePortObject = new DatabasePortObject(databasePortObjectSpec);
    return databasePortObject;
}
Also used : DatabasePortObject(org.knime.core.node.port.database.DatabasePortObject) DatabaseQueryConnectionSettings(org.knime.core.node.port.database.DatabaseQueryConnectionSettings) DatabaseReaderConnection(org.knime.core.node.port.database.DatabaseReaderConnection) 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