use of org.knime.core.node.port.database.reader.DBReader in project knime-core by knime.
the class DatabasePortObject method getDataTable.
/**
* @return underlying data
*/
private DataTable getDataTable(final int cacheNoRows) {
try {
DatabaseQueryConnectionSettings connSettings = getConnectionSettings(m_credentials);
DBReader load = connSettings.getUtility().getReader(connSettings);
return load.getTable(new ExecutionMonitor(), m_credentials, false, cacheNoRows);
} catch (Throwable t) {
LOGGER.error("Could not fetch data from database, reason: " + t.getMessage(), t);
return null;
}
}
use of org.knime.core.node.port.database.reader.DBReader in project knime-core by knime.
the class DBPivotNodeModel method createDbOutSpec.
/**
* @param inSpec Spec of the input database object
* @param exec The {@link ExecutionMonitor}
* @return Spec of the output database object
* @throws InvalidSettingsException if the current settings are invalid
* @throws CanceledExecutionException if execution is canceled
*/
private DatabasePortObjectSpec createDbOutSpec(final DatabasePortObjectSpec inSpec, final ExecutionMonitor exec) throws InvalidSettingsException, CanceledExecutionException {
DatabaseQueryConnectionSettings connectionSettings = inSpec.getConnectionSettings(getCredentialsProvider());
final StatementManipulator statementManipulator = connectionSettings.getUtility().getStatementManipulator();
try {
// Connection connection = connectionSettings.createConnection(getCredentialsProvider());
String newQuery = createQuery(connectionSettings, inSpec.getDataTableSpec(), exec);
connectionSettings = createDBQueryConnection(inSpec, newQuery);
DatabaseQueryConnectionSettings querySettings = new DatabaseQueryConnectionSettings(connectionSettings, newQuery);
DBReader reader = querySettings.getUtility().getReader(querySettings);
DataTableSpec tableSpec;
exec.setMessage("Retrieving result specification.");
tableSpec = reader.getDataTableSpec(getCredentialsProvider());
return new DatabasePortObjectSpec(tableSpec, connectionSettings.createConnectionModel());
} catch (SQLException e1) {
throw new InvalidSettingsException("Failure during query generation. Error: " + e1.getMessage(), e1);
}
}
use of org.knime.core.node.port.database.reader.DBReader 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) };
}
use of org.knime.core.node.port.database.reader.DBReader in project knime-core by knime.
the class DBNumericBinnerNodeModel method createDatabasePortObjectSpec.
private DatabasePortObjectSpec createDatabasePortObjectSpec(DatabaseQueryConnectionSettings connectionSettings, final DatabasePortObjectSpec inDatabasePortObjectSpec, final DBBinnerMaps binnerMaps) throws InvalidSettingsException, SQLException, BadPaddingException, IllegalBlockSizeException, InvalidKeyException, IOException {
final StatementManipulator statementManipulator = connectionSettings.getUtility().getStatementManipulator();
final String newQuery = createQuery(connectionSettings.getQuery(), statementManipulator, inDatabasePortObjectSpec.getDataTableSpec(), binnerMaps);
connectionSettings = createDBQueryConnection(inDatabasePortObjectSpec, newQuery);
final DatabaseQueryConnectionSettings querySettings = new DatabaseQueryConnectionSettings(connectionSettings, newQuery);
DBReader reader = querySettings.getUtility().getReader(querySettings);
DataTableSpec outDataTableSpec = reader.getDataTableSpec(getCredentialsProvider());
DatabasePortObjectSpec outDatabasePortObjectSpec = new DatabasePortObjectSpec(outDataTableSpec, connectionSettings.createConnectionModel());
return outDatabasePortObjectSpec;
}
use of org.knime.core.node.port.database.reader.DBReader in project knime-core by knime.
the class DBTableSelectorNodeModel method configure.
/**
* {@inheritDoc}
*/
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
if ((m_settings.getQuery() == null) || m_settings.getQuery().isEmpty()) {
throw new InvalidSettingsException("No query configured");
}
DatabaseConnectionPortObjectSpec incomingConnection = (DatabaseConnectionPortObjectSpec) inSpecs[0];
DatabaseConnectionSettings connSettings = incomingConnection.getConnectionSettings(getCredentialsProvider());
String sql = FlowVariableResolver.parse(m_settings.getQuery(), this);
DatabaseQueryConnectionSettings querySettings = new DatabaseQueryConnectionSettings(connSettings, sql);
final DBReader conn = connSettings.getUtility().getReader(querySettings);
if (!connSettings.getRetrieveMetadataInConfigure()) {
return new PortObjectSpec[1];
}
try {
DataTableSpec tableSpec = conn.getDataTableSpec(getCredentialsProvider());
return new PortObjectSpec[] { 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 '" + sql + "' : " + cause.getMessage(), ex);
}
}
Aggregations