use of org.knime.core.node.port.database.DatabasePortObjectSpec in project knime-core by knime.
the class DBSorterNodeDialog method loadSettingsFrom.
/**
* Calls the update method of the underlying update method of the {@link DBSorterNodeDialogPanel} using the input
* data table spec from this {@link DBSorterNodeModel}.
*
* @param settings the node settings to read from
* @param ports the input port objects
*
* @see NodeDialogPane#loadSettingsFrom(NodeSettingsRO, DataTableSpec[])
* @throws NotConfigurableException if the dialog cannot be opened.
*/
@SuppressWarnings("javadoc")
@Override
protected void loadSettingsFrom(final NodeSettingsRO settings, final PortObjectSpec[] ports) throws NotConfigurableException {
List<String> list = null;
boolean[] sortOrder = null;
if (settings.containsKey(DBSorterNodeModel.COLUMNS_KEY)) {
try {
String[] alist = settings.getStringArray(DBSorterNodeModel.COLUMNS_KEY);
if (alist != null) {
list = Arrays.asList(alist);
}
} catch (InvalidSettingsException ise) {
LOGGER.error(ise.getMessage());
}
}
if (settings.containsKey(DBSorterNodeModel.ASCENDING_KEY)) {
try {
sortOrder = settings.getBooleanArray(DBSorterNodeModel.ASCENDING_KEY);
} catch (InvalidSettingsException ise) {
LOGGER.error(ise.getMessage());
}
}
if (list == null || sortOrder == null || list.size() == 0 || list.size() != sortOrder.length) {
list = null;
sortOrder = null;
}
// set the values on the panel
DatabasePortObjectSpec dbSpec = (DatabasePortObjectSpec) ports[0];
final DataTableSpec spec;
if (dbSpec == null) {
spec = null;
} else {
spec = dbSpec.getDataTableSpec();
}
m_panel.update(spec, list, sortOrder, NRSORTITEMS);
}
use of org.knime.core.node.port.database.DatabasePortObjectSpec in project knime-core by knime.
the class DBSorterNodeModel method configure.
/**
* {@inheritDoc}
*/
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
DatabasePortObjectSpec spec = (DatabasePortObjectSpec) inSpecs[0];
for (String columnName : m_columns) {
if (!spec.getDataTableSpec().containsName(columnName)) {
throw new InvalidSettingsException("Can't filter according to selected column \"" + columnName + "\".");
}
}
DatabaseQueryConnectionSettings conn = spec.getConnectionSettings(getCredentialsProvider());
String newQuery = createQuery(conn.getQuery(), conn.getUtility().getStatementManipulator());
conn = createDBQueryConnection(spec, newQuery);
return new PortObjectSpec[] { new DatabasePortObjectSpec(spec.getDataTableSpec(), conn.createConnectionModel()) };
}
use of org.knime.core.node.port.database.DatabasePortObjectSpec in project knime-core by knime.
the class DBApplyBinnerNodeModel method createDatabasePortObject.
private DatabasePortObject createDatabasePortObject(final DatabasePortObjectSpec inSpec, DatabaseQueryConnectionSettings connectionSettings, final PMMLPortObject pmmlPortObject) throws InvalidSettingsException {
final StatementManipulator statementManipulator = connectionSettings.getUtility().getStatementManipulator();
String newQuery = createQuery(connectionSettings.getQuery(), statementManipulator, inSpec.getDataTableSpec(), pmmlPortObject);
connectionSettings = createDBQueryConnection(inSpec, newQuery);
DatabaseQueryConnectionSettings querySettings = new DatabaseQueryConnectionSettings(connectionSettings, newQuery);
DBReader reader = querySettings.getUtility().getReader(querySettings);
try {
DatabasePortObjectSpec databasePortObjectSpec = new DatabasePortObjectSpec(reader.getDataTableSpec(getCredentialsProvider()), connectionSettings.createConnectionModel());
DatabasePortObject databasePortObject = new DatabasePortObject(databasePortObjectSpec);
return databasePortObject;
} catch (SQLException e) {
throw new InvalidSettingsException("Failure during query generation. Error: " + e.getMessage());
}
}
use of org.knime.core.node.port.database.DatabasePortObjectSpec in project knime-core by knime.
the class DBNumericBinnerNodeModel method configure.
/**
* {@inheritDoc}
*/
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
final DatabasePortObjectSpec inDatabasePortObjectSpec = (DatabasePortObjectSpec) inSpecs[0];
DatabaseQueryConnectionSettings connectionSettings = inDatabasePortObjectSpec.getConnectionSettings(getCredentialsProvider());
boolean suppCase = connectionSettings.getUtility().supportsCase();
if (!suppCase) {
if (m_columnToBins.size() > 1) {
throw new InvalidSettingsException("Database does not support \"CASE\". Please choose only one column.");
}
}
if (m_columnToBins.isEmpty()) {
setWarningMessage("No columns selected for binning");
} else {
checkDuplicateBinNames();
}
DataTableSpec outDataTableSpec = DBAutoBinner.createNewDataTableSpec(inDatabasePortObjectSpec.getDataTableSpec(), m_columnToAppended);
PMMLPortObject outPMMLPortObject = createPMMLPortObject(inDatabasePortObjectSpec.getDataTableSpec(), outDataTableSpec);
DBBinnerMaps binnerMaps = DBAutoBinner.intoBinnerMaps(outPMMLPortObject, inDatabasePortObjectSpec.getDataTableSpec());
DatabasePortObjectSpec outDatabasePortObjectSpec = null;
try {
outDatabasePortObjectSpec = createDatabasePortObjectSpec(connectionSettings, inDatabasePortObjectSpec, binnerMaps);
} catch (InvalidKeyException | BadPaddingException | IllegalBlockSizeException | SQLException | IOException e) {
// TODO Auto-generated catch block
}
return new PortObjectSpec[] { outDatabasePortObjectSpec, outPMMLPortObject.getSpec() };
}
use of org.knime.core.node.port.database.DatabasePortObjectSpec in project knime-core by knime.
the class DBTableSelectorNodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
protected PortObject[] execute(final PortObject[] inObjects, final ExecutionContext exec) throws Exception {
exec.setMessage("Retrieving metadata from database");
DatabaseConnectionPortObject incomingConnection = (DatabaseConnectionPortObject) inObjects[0];
DatabaseConnectionSettings connSettings = incomingConnection.getConnectionSettings(getCredentialsProvider());
String sql = FlowVariableResolver.parse(m_settings.getQuery(), this);
DatabaseQueryConnectionSettings querySettings = new DatabaseQueryConnectionSettings(connSettings, sql);
DBReader conn = querySettings.getUtility().getReader(querySettings);
try {
DataTableSpec tableSpec = conn.getDataTableSpec(getCredentialsProvider());
return new PortObject[] { new DatabasePortObject(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: " + cause.getMessage(), ex);
}
}
Aggregations