use of org.knime.core.node.port.database.DatabaseConnectionPortObjectSpec 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.DatabaseConnectionPortObjectSpec in project knime-core by knime.
the class DBDeleteRowsDialogPane method loadSettingsFrom.
/**
* {@inheritDoc}
*/
@Override
protected void loadSettingsFrom(final NodeSettingsRO settings, final PortObjectSpec[] specs) throws NotConfigurableException {
DataTableSpec tableSpec = (DataTableSpec) specs[0];
// load login setting
m_loginPanel.loadSettingsFrom(settings, specs, getCredentialsProvider());
// load table name
m_tableName.setText(settings.getString(DBDeleteRowsNodeModel.KEY_TABLE_NAME, ""));
// load WHERE column panel
DataColumnSpecFilterConfiguration configWhere = new DataColumnSpecFilterConfiguration(DBDeleteRowsNodeModel.KEY_WHERE_FILTER_COLUMN);
configWhere.loadConfigurationInDialog(settings, tableSpec);
m_columnsInWhereClause.loadConfiguration(configWhere, tableSpec);
// load batch size
final int batchSize = settings.getInt(DBDeleteRowsNodeModel.KEY_BATCH_SIZE, 1);
m_batchSize.setText(Integer.toString(batchSize));
if ((specs.length > 1) && (specs[1] instanceof DatabaseConnectionPortObjectSpec)) {
m_loginPanel.setVisible(false);
} else {
m_loginPanel.setVisible(true);
}
}
use of org.knime.core.node.port.database.DatabaseConnectionPortObjectSpec in project knime-core by knime.
the class DBDeleteRowsNodeModel method configure.
/**
* {@inheritDoc}
*/
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
DataTableSpec tableSpec = (DataTableSpec) inSpecs[0];
// check table name
if (m_tableName == null || m_tableName.trim().isEmpty()) {
throw new InvalidSettingsException("Configure node and enter a valid table name.");
}
final List<String> whereIncludes = new ArrayList<String>(Arrays.asList(m_configWHERE.applyTo(tableSpec).getIncludes()));
if (whereIncludes.isEmpty()) {
throw new InvalidSettingsException("No WHERE column selected.");
}
// check optional incoming connection
if ((inSpecs.length > 1) && (inSpecs[1] instanceof DatabaseConnectionPortObjectSpec)) {
DatabaseConnectionSettings connSettings = ((DatabaseConnectionPortObjectSpec) inSpecs[1]).getConnectionSettings(getCredentialsProvider());
if ((connSettings.getJDBCUrl() == null) || connSettings.getJDBCUrl().isEmpty() || (connSettings.getDriver() == null) || connSettings.getDriver().isEmpty()) {
throw new InvalidSettingsException("No valid database connection provided via second input port");
}
if (!connSettings.getUtility().supportsDelete()) {
throw new InvalidSettingsException("Connected database does not support delete operations");
}
} else {
if (!m_loginConfig.getUtility().supportsDelete()) {
throw new InvalidSettingsException("Selected database does not support delete operations");
}
}
// forward input spec with one additional update (=int) column
final ColumnRearranger colre = createColumnRearranger(tableSpec, new int[] {});
return new DataTableSpec[] { colre.createSpec() };
}
use of org.knime.core.node.port.database.DatabaseConnectionPortObjectSpec in project knime-core by knime.
the class DBReaderNodeModel method getResultSpec.
/**
* @param inSpecs input spec
* @return the {@link DataTableSpec} of the result table
* @throws InvalidSettingsException if the connection settings are invalid
* @throws SQLException if the query is invalid
*/
protected DataTableSpec getResultSpec(final PortObjectSpec[] inSpecs) throws InvalidSettingsException, SQLException {
String query = parseQuery(m_settings.getQuery());
DatabaseQueryConnectionSettings connSettings;
if (hasDatabaseInputConnection(inSpecs)) {
DatabaseConnectionPortObjectSpec connSpec = (DatabaseConnectionPortObjectSpec) inSpecs[getNrInPorts() - 1];
connSettings = new DatabaseQueryConnectionSettings(connSpec.getConnectionSettings(getCredentialsProvider()), query);
} else {
connSettings = new DatabaseQueryConnectionSettings(m_settings, query);
}
DBReader reader = connSettings.getUtility().getReader(connSettings);
final DataTableSpec resultSpec = reader.getDataTableSpec(getCredentialsProvider());
return resultSpec;
}
use of org.knime.core.node.port.database.DatabaseConnectionPortObjectSpec in project knime-core by knime.
the class DatabaseLoopingNodeModel method configure.
/**
* {@inheritDoc}
*/
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
final DataTableSpec lastSpec = getLastSpec();
if (lastSpec != null) {
return new DataTableSpec[] { lastSpec };
}
final DataTableSpec tableSpec = (DataTableSpec) inSpecs[0];
String column = m_columnModel.getStringValue();
if (column == null) {
throw new InvalidSettingsException("No column selected.");
}
final int colIdx = tableSpec.findColumnIndex(column);
if (colIdx < 0) {
throw new InvalidSettingsException("Column '" + column + "' not found in input data.");
}
if ((inSpecs.length > 1) && (inSpecs[1] instanceof DatabaseConnectionPortObjectSpec)) {
DatabaseConnectionSettings connSettings = ((DatabaseConnectionPortObjectSpec) inSpecs[1]).getConnectionSettings(getCredentialsProvider());
m_settings.setValidateQuery(connSettings.getRetrieveMetadataInConfigure());
} else {
m_settings.setValidateQuery(true);
}
if (!m_settings.getValidateQuery()) {
setLastSpec(null);
return new DataTableSpec[] { null };
}
final String oQuery = getQuery();
PortObjectSpec[] spec = null;
try {
final String newQuery;
newQuery = createDummyValueQuery(tableSpec, colIdx, oQuery);
setQuery(newQuery);
spec = new DataTableSpec[] { getResultSpec(inSpecs) };
} catch (InvalidSettingsException e) {
setLastSpec(null);
throw e;
} catch (SQLException ex) {
setLastSpec(null);
Throwable cause = ExceptionUtils.getRootCause(ex);
if (cause == null) {
cause = ex;
}
throw new InvalidSettingsException("Could not determine table spec from database query: " + cause.getMessage(), ex);
} finally {
setQuery(oQuery);
}
if (spec[0] == null) {
return spec;
} else {
final DataTableSpec resultSpec = createSpec((DataTableSpec) spec[0], tableSpec.getColumnSpec(column));
setLastSpec(resultSpec);
return new DataTableSpec[] { resultSpec };
}
}
Aggregations