use of org.knime.core.node.port.database.DatabasePortObjectSpec in project knime-core by knime.
the class DBColumnFilterNodeDialogPane method loadSettingsFrom.
/**
* {@inheritDoc}
*/
@Override
protected void loadSettingsFrom(final NodeSettingsRO settings, final PortObjectSpec[] ports) throws NotConfigurableException {
DatabasePortObjectSpec dbSpec = (DatabasePortObjectSpec) ports[0];
final DataTableSpec[] specs;
if (dbSpec == null) {
specs = new DataTableSpec[] { null };
} else {
specs = new DataTableSpec[] { dbSpec.getDataTableSpec() };
}
m_panel.loadSettingsFrom(settings, specs);
}
use of org.knime.core.node.port.database.DatabasePortObjectSpec in project knime-core by knime.
the class DBColumnFilterNodeModel method configure.
/**
* {@inheritDoc}
*/
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
DatabasePortObjectSpec spec = (DatabasePortObjectSpec) inSpecs[0];
StringBuilder buf = new StringBuilder();
for (String column : m_filter.getIncludeList()) {
if (!spec.getDataTableSpec().containsName(column)) {
buf.append("\"" + column + "\" ");
}
}
if (buf.length() > 0) {
throw new InvalidSettingsException("Not all columns available in " + "input spec: " + buf.toString());
}
DatabaseQueryConnectionSettings conn = spec.getConnectionSettings(getCredentialsProvider());
ColumnRearranger colre = new ColumnRearranger(spec.getDataTableSpec());
colre.keepOnly(m_filter.getIncludeList().toArray(new String[0]));
final DataTableSpec resultSpec = colre.createSpec();
final String newQuery = createQuery(conn, resultSpec);
conn = createDBQueryConnection(spec, newQuery);
return new PortObjectSpec[] { new DatabasePortObjectSpec(resultSpec, conn.createConnectionModel()) };
}
use of org.knime.core.node.port.database.DatabasePortObjectSpec in project knime-core by knime.
the class DBColumnFilterNodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
protected final PortObject[] execute(final PortObject[] inData, final ExecutionContext exec) throws CanceledExecutionException, Exception {
DatabasePortObject dbObj = (DatabasePortObject) inData[0];
DatabaseQueryConnectionSettings conn = dbObj.getConnectionSettings(getCredentialsProvider());
ColumnRearranger colre = new ColumnRearranger(dbObj.getSpec().getDataTableSpec());
colre.keepOnly(m_filter.getIncludeList().toArray(new String[0]));
final DataTableSpec resultSpec = colre.createSpec();
final String newQuery = createQuery(conn, resultSpec);
conn = createDBQueryConnection(dbObj.getSpec(), newQuery);
DatabasePortObjectSpec outSpec = new DatabasePortObjectSpec(resultSpec, conn.createConnectionModel());
DatabasePortObject outObj = new DatabasePortObject(outSpec);
return new PortObject[] { outObj };
}
use of org.knime.core.node.port.database.DatabasePortObjectSpec in project knime-core by knime.
the class DBConnectionWriterNodeModel method configure.
/**
* {@inheritDoc}
*/
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
if (inSpecs == null || inSpecs.length < 1 || inSpecs[0] == null) {
throw new InvalidSettingsException("No input available");
}
// check table name
final String table = m_tableName.getStringValue();
if (table == null || table.trim().isEmpty()) {
throw new InvalidSettingsException("Configure node and enter a valid table name.");
}
DatabasePortObjectSpec spec = (DatabasePortObjectSpec) inSpecs[0];
try {
final DatabaseQueryConnectionSettings conn = spec.getConnectionSettings(getCredentialsProvider());
if (conn.getRetrieveMetadataInConfigure()) {
conn.execute(getCredentialsProvider(), c -> {
return c != null;
});
}
} catch (InvalidSettingsException ise) {
throw ise;
} catch (Throwable t) {
throw new InvalidSettingsException(t);
}
setWarningMessage("Existing table \"" + table + "\" will be dropped!");
return new DataTableSpec[0];
}
use of org.knime.core.node.port.database.DatabasePortObjectSpec in project knime-core by knime.
the class DBJoinerNodeDialog method loadSettingsFrom.
/**
* {@inheritDoc}
*/
@Override
protected void loadSettingsFrom(final NodeSettingsRO settings, final PortObjectSpec[] specs) throws NotConfigurableException {
if (specs == null || specs.length < 2 || specs[0] == null || specs[1] == null) {
throw new NotConfigurableException("No input specification available.");
}
DataTableSpec tableSpec1 = ((DatabasePortObjectSpec) specs[0]).getDataTableSpec();
DataTableSpec tableSpec2 = ((DatabasePortObjectSpec) specs[1]).getDataTableSpec();
DBJoinerSettings joinerSettings = new DBJoinerSettings();
joinerSettings.loadSettingsInDialog(settings);
m_joinMode.setSelectedItem(joinerSettings.getJoinMode());
m_matchAllButton.setSelected(joinerSettings.getAndComposition());
m_matchAnyButton.setSelected(!joinerSettings.getAndComposition());
m_columnPairs.updateData(new DataTableSpec[] { tableSpec1, tableSpec2 }, joinerSettings.getLeftJoinOnColumns(), joinerSettings.getRightJoinOnColumns());
m_leftFilterPanel.update(tableSpec1, false, joinerSettings.getLeftColumns());
m_rightFilterPanel.update(tableSpec2, false, joinerSettings.getRightColumns());
m_leftFilterPanel.setKeepAllSelected(joinerSettings.getAllLeftColumns());
m_rightFilterPanel.setKeepAllSelected(joinerSettings.getAllRightColumns());
m_removeLeftJoinCols.setSelected(joinerSettings.getFilterLeftJoinOnColumns());
m_removeRightJoinCols.setSelected(joinerSettings.getFilterRightJoinOnColumns());
m_suffix.setText(joinerSettings.getCustomSuffix());
m_filterDuplicates.setSelected(joinerSettings.getDuplicateHandling().equals(DuplicateHandling.Filter));
m_dontExecute.setSelected(joinerSettings.getDuplicateHandling().equals(DuplicateHandling.DontExecute));
m_appendSuffixAutomatic.setSelected(joinerSettings.getDuplicateHandling().equals(DuplicateHandling.AppendSuffixAutomatic));
m_appendSuffix.setSelected(joinerSettings.getDuplicateHandling().equals(DuplicateHandling.AppendSuffix));
m_suffix.setEnabled(joinerSettings.getDuplicateHandling().equals(DuplicateHandling.AppendSuffix));
}
Aggregations