use of org.knime.core.node.port.database.DatabasePortObjectSpec in project knime-core by knime.
the class DBSamplingNodeModel method createDbOutSpec.
/**
* @param inSpec Spec of the input database object
* @param exec The {@link ExecutionMonitor}
* @param checkRetrieveMetadata true if the retrieveMetadataInConfigure settings should be respected,
* <code>false</code> if the metadata should be retrieved in any case (for execute)
* @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, final boolean checkRetrieveMetadata) throws InvalidSettingsException, CanceledExecutionException {
final DatabaseQueryConnectionSettings connectionSettings = inSpec.getConnectionSettings(getCredentialsProvider());
final StatementManipulator statementManipulator = connectionSettings.getUtility().getStatementManipulator();
try {
// Connection connection = connectionSettings.createConnection(getCredentialsProvider());
final String newQuery = connectionSettings.execute(getCredentialsProvider(), conn -> {
return createQuery(conn, connectionSettings.getQuery(), statementManipulator, inSpec.getDataTableSpec(), exec);
});
DatabaseQueryConnectionSettings resultSettings = createDBQueryConnection(inSpec, newQuery);
DatabaseQueryConnectionSettings querySettings = new DatabaseQueryConnectionSettings(resultSettings, newQuery);
DatabaseReaderConnection conn = new DatabaseReaderConnection(querySettings);
DataTableSpec tableSpec;
exec.setMessage("Retrieving result specification.");
tableSpec = conn.getDataTableSpec(getCredentialsProvider());
return new DatabasePortObjectSpec(tableSpec, resultSettings.createConnectionModel());
} catch (SQLException e1) {
throw new InvalidSettingsException("Failure during query generation. Error: " + e1.getMessage(), e1);
}
}
use of org.knime.core.node.port.database.DatabasePortObjectSpec in project knime-core by knime.
the class DBSamplingNodeModel method configure.
/**
* {@inheritDoc}
*/
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
if (m_stratified.getBooleanValue()) {
final DatabasePortObjectSpec dbSpec = (DatabasePortObjectSpec) inSpecs[0];
final DataTableSpec tableSpec = dbSpec.getDataTableSpec();
if (!tableSpec.containsName(m_classColumnName.getStringValue())) {
throw new InvalidSettingsException("Please choose a suitable column for stratified sampling.");
}
}
return inSpecs;
}
use of org.knime.core.node.port.database.DatabasePortObjectSpec 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.DatabasePortObjectSpec 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 };
}
use of org.knime.core.node.port.database.DatabasePortObjectSpec 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) };
}
Aggregations