Search in sources :

Example 11 with DBReader

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

the class DBConnectionNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected PortObject[] execute(final PortObject[] inData, final ExecutionContext exec) throws CanceledExecutionException, Exception {
    exec.setProgress("Opening database connection...");
    DatabasePortObject dbObj = (DatabasePortObject) inData[0];
    DatabaseQueryConnectionSettings conn = dbObj.getConnectionSettings(getCredentialsProvider());
    final DBReader reader = conn.getUtility().getReader(conn);
    // final DatabaseReaderConnection load = new DatabaseReaderConnection(conn);
    exec.setProgress("Reading data from database...");
    CredentialsProvider cp = getCredentialsProvider();
    return new BufferedDataTable[] { reader.createTable(exec, cp, m_useDbRowId.getBooleanValue()) };
}
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) CredentialsProvider(org.knime.core.node.workflow.CredentialsProvider)

Example 12 with DBReader

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

the class DBQueryNodeModel method configure.

/**
 * {@inheritDoc}
 */
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
    DatabasePortObjectSpec spec = (DatabasePortObjectSpec) inSpecs[0];
    DatabaseQueryConnectionSettings conn = spec.getConnectionSettings(getCredentialsProvider());
    String newQuery = createQuery(conn.getQuery());
    conn = createDBQueryConnection(spec, newQuery);
    if (!conn.getRetrieveMetadataInConfigure()) {
        return new PortObjectSpec[1];
    }
    try {
        DBReader reader = conn.getUtility().getReader(conn);
        DataTableSpec outSpec = reader.getDataTableSpec(getCredentialsProvider());
        DatabasePortObjectSpec dbSpec = new DatabasePortObjectSpec(outSpec, conn.createConnectionModel());
        return new PortObjectSpec[] { dbSpec };
    } catch (Throwable t) {
        throw new InvalidSettingsException(t);
    }
}
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) PortObjectSpec(org.knime.core.node.port.PortObjectSpec) DatabasePortObjectSpec(org.knime.core.node.port.database.DatabasePortObjectSpec) DatabasePortObjectSpec(org.knime.core.node.port.database.DatabasePortObjectSpec) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString)

Example 13 with DBReader

use of org.knime.core.node.port.database.reader.DBReader 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 14 with DBReader

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

the class DBReaderNodeModel method getResultSpec.

/**
 * @param inSpecs input spec
 * @return the {@link DataTableSpec} of the result table
 * @throws InvalidSettingsException if the connection settings are invalid
 * @throws SQLException if the query is invalid
 */
protected DataTableSpec getResultSpec(final PortObjectSpec[] inSpecs) throws InvalidSettingsException, SQLException {
    String query = parseQuery(m_settings.getQuery());
    DatabaseQueryConnectionSettings connSettings;
    if (hasDatabaseInputConnection(inSpecs)) {
        DatabaseConnectionPortObjectSpec connSpec = (DatabaseConnectionPortObjectSpec) inSpecs[getNrInPorts() - 1];
        connSettings = new DatabaseQueryConnectionSettings(connSpec.getConnectionSettings(getCredentialsProvider()), query);
    } else {
        connSettings = new DatabaseQueryConnectionSettings(m_settings, query);
    }
    DBReader reader = connSettings.getUtility().getReader(connSettings);
    final DataTableSpec resultSpec = reader.getDataTableSpec(getCredentialsProvider());
    return resultSpec;
}
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) DatabaseConnectionPortObjectSpec(org.knime.core.node.port.database.DatabaseConnectionPortObjectSpec)

Example 15 with DBReader

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

the class DBReaderNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected PortObject[] execute(final PortObject[] inData, final ExecutionContext exec) throws CanceledExecutionException, Exception {
    exec.setProgress("Opening database connection...");
    try {
        exec.setProgress("Reading data from database...");
        DBReader load = loadConnectionSettings(inData[getNrInPorts() - 1]);
        final BufferedDataTable result = getResultTable(exec, inData, load);
        setLastSpec(result.getDataTableSpec());
        return new BufferedDataTable[] { result };
    } catch (CanceledExecutionException cee) {
        throw cee;
    } catch (Exception e) {
        setLastSpec(null);
        throw e;
    }
}
Also used : DBReader(org.knime.core.node.port.database.reader.DBReader) CanceledExecutionException(org.knime.core.node.CanceledExecutionException) BufferedDataTable(org.knime.core.node.BufferedDataTable) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) CanceledExecutionException(org.knime.core.node.CanceledExecutionException) SQLException(java.sql.SQLException) IOException(java.io.IOException)

Aggregations

DBReader (org.knime.core.node.port.database.reader.DBReader)20 DatabaseQueryConnectionSettings (org.knime.core.node.port.database.DatabaseQueryConnectionSettings)17 DataTableSpec (org.knime.core.data.DataTableSpec)14 DatabasePortObjectSpec (org.knime.core.node.port.database.DatabasePortObjectSpec)12 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)11 DatabasePortObject (org.knime.core.node.port.database.DatabasePortObject)8 SQLException (java.sql.SQLException)7 SettingsModelString (org.knime.core.node.defaultnodesettings.SettingsModelString)6 PortObject (org.knime.core.node.port.PortObject)5 PortObjectSpec (org.knime.core.node.port.PortObjectSpec)5 BufferedDataTable (org.knime.core.node.BufferedDataTable)4 DatabaseConnectionPortObject (org.knime.core.node.port.database.DatabaseConnectionPortObject)4 DatabaseConnectionPortObjectSpec (org.knime.core.node.port.database.DatabaseConnectionPortObjectSpec)3 DatabaseConnectionSettings (org.knime.core.node.port.database.DatabaseConnectionSettings)3 StatementManipulator (org.knime.core.node.port.database.StatementManipulator)3 CanceledExecutionException (org.knime.core.node.CanceledExecutionException)2 SettingsModelFilterString (org.knime.core.node.defaultnodesettings.SettingsModelFilterString)2 CredentialsProvider (org.knime.core.node.workflow.CredentialsProvider)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1