use of org.knime.core.node.port.database.DatabasePortObjectSpec 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.DatabasePortObjectSpec in project knime-core by knime.
the class DBNumericBinnerNodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
protected final PortObject[] execute(final PortObject[] inData, final ExecutionContext exec) throws CanceledExecutionException, Exception {
exec.setMessage("Retrieving metadata from database");
checkDuplicateBinNames();
final DatabasePortObject inDatabasePortObject = (DatabasePortObject) inData[0];
final DatabasePortObjectSpec inDatabasePortObjectSpec = inDatabasePortObject.getSpec();
DatabaseQueryConnectionSettings connectionSettings = inDatabasePortObject.getConnectionSettings(getCredentialsProvider());
DataTableSpec outDataTableSpec = DBAutoBinner.createNewDataTableSpec(inDatabasePortObjectSpec.getDataTableSpec(), m_columnToAppended);
PMMLPortObject outPMMLPortObject = createPMMLPortObject(inDatabasePortObjectSpec.getDataTableSpec(), outDataTableSpec);
DBBinnerMaps binnerMaps = DBAutoBinner.intoBinnerMaps(outPMMLPortObject, inDatabasePortObjectSpec.getDataTableSpec());
DatabasePortObjectSpec outDatabasePortObjectSpec = createDatabasePortObjectSpec(connectionSettings, inDatabasePortObjectSpec, binnerMaps);
return new PortObject[] { new DatabasePortObject(outDatabasePortObjectSpec), outPMMLPortObject };
}
use of org.knime.core.node.port.database.DatabasePortObjectSpec 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);
}
}
use of org.knime.core.node.port.database.DatabasePortObjectSpec in project knime-core by knime.
the class DBColumnRenameNodeModel method createDBOutSpec.
private DatabasePortObjectSpec createDBOutSpec(final DatabasePortObjectSpec inSpec) throws InvalidSettingsException {
if (m_config == null) {
throw new InvalidSettingsException("No configuration available");
}
final DataTableSpec tableSpec = inSpec.getDataTableSpec();
final DataTableSpec outSpec = m_config.getNewSpec(tableSpec);
final List<String> missingColumnNames = m_config.getMissingColumnNames();
if (missingColumnNames != null && !missingColumnNames.isEmpty()) {
setWarningMessage("The following columns are configured but no longer exist: " + ConvenienceMethods.getShortStringFrom(missingColumnNames, 5));
}
DatabaseQueryConnectionSettings conn = inSpec.getConnectionSettings(getCredentialsProvider());
final StatementManipulator statementManipulator = conn.getUtility().getStatementManipulator();
String newQuery = createQuery(conn.getQuery(), tableSpec, statementManipulator);
conn = createDBQueryConnection(inSpec, newQuery);
return new DatabasePortObjectSpec(outSpec, conn.createConnectionModel());
}
use of org.knime.core.node.port.database.DatabasePortObjectSpec in project knime-core by knime.
the class DBQueryNodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
protected final PortObject[] execute(final PortObject[] inData, final ExecutionContext exec) throws CanceledExecutionException, Exception {
DatabasePortObject dbObj = (DatabasePortObject) inData[0];
CredentialsProvider cp = getCredentialsProvider();
DatabaseQueryConnectionSettings conn = dbObj.getConnectionSettings(cp);
String newQuery = createQuery(conn.getQuery());
conn = createDBQueryConnection(dbObj.getSpec(), newQuery);
DBReader load = conn.getUtility().getReader(conn);
DataTableSpec outSpec = load.getDataTableSpec(cp);
DatabasePortObjectSpec dbSpec = new DatabasePortObjectSpec(outSpec, conn.createConnectionModel());
DatabasePortObject outObj = new DatabasePortObject(dbSpec);
return new PortObject[] { outObj };
}
Aggregations