use of org.knime.core.node.port.database.DatabasePortObjectSpec in project knime-core by knime.
the class DBGroupByNodeDialog method loadSettingsFrom.
/**
* {@inheritDoc}
*/
@Override
protected void loadSettingsFrom(final NodeSettingsRO settings, final PortObjectSpec[] specs) throws NotConfigurableException {
if (specs == null || specs.length < 1 || specs[0] == null) {
throw new NotConfigurableException("No input spec available");
}
final DatabasePortObjectSpec dbspec = (DatabasePortObjectSpec) specs[0];
final DataTableSpec spec = dbspec.getDataTableSpec();
try {
m_columnNamePolicy.loadSettingsFrom(settings);
} catch (final InvalidSettingsException e) {
throw new NotConfigurableException(e.getMessage());
}
m_aggregationPanel.loadSettingsFrom(settings, dbspec, spec);
m_groupCol.loadSettingsFrom(settings, new DataTableSpec[] { spec });
columnsChanged();
}
use of org.knime.core.node.port.database.DatabasePortObjectSpec in project knime-core by knime.
the class DBGroupByNodeModel method createDbOutSpec.
/**
* @param inSpec Spec of the input database object
* @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
*/
private DatabasePortObjectSpec createDbOutSpec(final DatabasePortObjectSpec inSpec, final boolean checkRetrieveMetadata) throws InvalidSettingsException {
if (m_groupByCols.getIncludeList().isEmpty() && m_aggregatedColumns.length == 0) {
throw new InvalidSettingsException("Please select at least one group or aggregation column");
}
DatabaseQueryConnectionSettings connection = inSpec.getConnectionSettings(getCredentialsProvider());
String newQuery = createQuery(connection.getQuery(), connection.getUtility().getStatementManipulator());
connection = createDBQueryConnection(inSpec, newQuery);
if (checkRetrieveMetadata && !connection.getRetrieveMetadataInConfigure()) {
return null;
}
DataTableSpec tableSpec = createOutSpec(inSpec.getDataTableSpec(), connection, newQuery, checkRetrieveMetadata);
return new DatabasePortObjectSpec(tableSpec, connection.createConnectionModel());
}
use of org.knime.core.node.port.database.DatabasePortObjectSpec in project knime-core by knime.
the class ParameterizedDBQueryNodeModel method configure.
/**
* {@inheritDoc}
*/
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
final DataTableSpec inSpec = (DataTableSpec) inSpecs[0];
if (inSpec.getNumColumns() < 1) {
throw new InvalidSettingsException("No column spec available.");
}
if ((inSpecs[1] == null) || !(inSpecs[1] instanceof DatabasePortObjectSpec)) {
throw new InvalidSettingsException("No valid database connection available.");
}
final DatabasePortObjectSpec dbSpec = (DatabasePortObjectSpec) inSpecs[1];
parseSQLStatement(inSpec, dbSpec.getConnectionSettings(getCredentialsProvider()).getQuery());
return new DataTableSpec[] { null, null };
}
use of org.knime.core.node.port.database.DatabasePortObjectSpec in project knime-core by knime.
the class DBPivotNodeDialog method loadSettingsFrom.
/**
* {@inheritDoc}
*/
@Override
protected void loadSettingsFrom(final NodeSettingsRO settings, final PortObjectSpec[] specs) throws NotConfigurableException {
if (specs == null || specs.length < 1 || specs[0] == null) {
throw new NotConfigurableException("No input connection found.");
}
final DatabasePortObjectSpec dbspec = (DatabasePortObjectSpec) specs[0];
final DataTableSpec spec = dbspec.getDataTableSpec();
try {
final DatabaseQueryConnectionSettings connectionSettings = dbspec.getConnectionSettings(null);
m_columnNamePolicy.loadSettingsFrom(settings);
final String dbIdentifier = connectionSettings.getDatabaseIdentifier();
m_aggregationPanel.loadSettingsFrom(settings, dbIdentifier, spec);
final DBAggregationFunctionProvider functionProvider = new DBAggregationFunctionProvider(connectionSettings.getUtility());
m_descriptionTab.removeAll();
final GridBagConstraints c = new GridBagConstraints();
c.anchor = GridBagConstraints.CENTER;
c.fill = GridBagConstraints.BOTH;
c.weightx = 1;
c.weighty = 1;
m_descriptionTab.add(functionProvider.getDescriptionPane(), c);
} catch (final InvalidSettingsException e) {
throw new NotConfigurableException(e.getMessage());
}
m_groupCol.loadSettingsFrom(settings, new DataTableSpec[] { spec });
m_pivotCol.loadSettingsFrom(settings, new DataTableSpec[] { spec });
columnsChanged();
}
use of org.knime.core.node.port.database.DatabasePortObjectSpec in project knime-core by knime.
the class DBSamplingNodeDialog method loadSettingsFrom.
/**
* {@inheritDoc}
*/
@SuppressWarnings("null")
@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() };
}
boolean random;
try {
random = dbSpec.getConnectionSettings(getCredentialsProvider()).getUtility().supportsRandomSampling();
} catch (InvalidSettingsException e) {
throw new NotConfigurableException(e.getMessage());
}
m_countComp.loadSettingsFrom(settings, specs);
m_absoluteComp.loadSettingsFrom(settings, specs);
m_relativeComp.loadSettingsFrom(settings, specs);
m_samplingComp.loadSettingsFrom(settings, specs);
m_stratifiedComp.loadSettingsFrom(settings, specs);
m_columnComp.loadSettingsFrom(settings, specs);
if (!random) {
m_samplingComp.setToolTipText("Connected database does not support random sampling");
m_samplingMethod.setStringValue(DBSamplingNodeModel.SamplingMethod.FIRST.getActionCommand());
} else {
m_samplingComp.setToolTipText(null);
}
m_samplingMethod.setEnabled(random);
}
Aggregations