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()) };
}
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);
}
}
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 };
}
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;
}
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;
}
}
Aggregations