use of org.knime.core.node.port.database.DatabaseConnectionSettings in project knime-core by knime.
the class JDBCConnectorNodeModel method validateSettings.
/**
* {@inheritDoc}
*/
@Override
protected void validateSettings(final NodeSettingsRO settings) throws InvalidSettingsException {
DatabaseConnectionSettings s = new DatabaseConnectionSettings();
s.validateConnection(settings, getCredentialsProvider());
}
use of org.knime.core.node.port.database.DatabaseConnectionSettings in project knime-core by knime.
the class DBDeleteRowsNodeModel method validateSettings.
/**
* {@inheritDoc}
*/
@Override
protected void validateSettings(final NodeSettingsRO settings) throws InvalidSettingsException {
// validate login settings
new DatabaseConnectionSettings(settings, getCredentialsProvider());
// validate table name
final String tableName = settings.getString(KEY_TABLE_NAME);
if (tableName == null || tableName.trim().isEmpty()) {
throw new InvalidSettingsException("Configure node and enter a valid table name.");
}
// validate WHERE columns
final DataColumnSpecFilterConfiguration confWHERE = new DataColumnSpecFilterConfiguration(KEY_WHERE_FILTER_COLUMN);
confWHERE.loadConfigurationInModel(settings);
// validate batch size
final int batchSize = settings.getInt(KEY_BATCH_SIZE);
if (batchSize <= 0) {
throw new InvalidSettingsException("Batch size must be greater than 0, is " + batchSize);
}
}
use of org.knime.core.node.port.database.DatabaseConnectionSettings in project knime-core by knime.
the class DBDeleteRowsNodeModel method loadValidatedSettingsFrom.
/**
* {@inheritDoc}
*/
@Override
protected void loadValidatedSettingsFrom(final NodeSettingsRO settings) throws InvalidSettingsException {
// load WHERE columns
final DataColumnSpecFilterConfiguration confWHERE = new DataColumnSpecFilterConfiguration(KEY_WHERE_FILTER_COLUMN);
confWHERE.loadConfigurationInModel(settings);
m_configWHERE = confWHERE;
// load login settings
m_loginConfig = new DatabaseConnectionSettings(settings, getCredentialsProvider());
// load table name
m_tableName = settings.getString(KEY_TABLE_NAME).trim();
// load batch size
m_batchSize = settings.getInt(KEY_BATCH_SIZE);
}
use of org.knime.core.node.port.database.DatabaseConnectionSettings in project knime-core by knime.
the class DBDeleteRowsNodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
protected PortObject[] execute(final PortObject[] inData, final ExecutionContext exec) throws Exception {
final BufferedDataTable inTable = (BufferedDataTable) inData[0];
final DataTableSpec inSpec = inTable.getSpec();
final String[] whereIncludes = m_configWHERE.applyTo(inSpec).getIncludes();
DatabaseConnectionSettings connSettings;
if ((inData.length > 1) && (inData[1] instanceof DatabaseConnectionPortObject)) {
connSettings = ((DatabaseConnectionPortObject) inData[1]).getConnectionSettings(getCredentialsProvider());
} else {
connSettings = m_loginConfig;
}
// DELETE rows
final int[] deleteStatus = new int[inTable.getRowCount()];
final DBWriter dbWriter = connSettings.getUtility().getWriter(connSettings);
final String errMsg = dbWriter.deleteRows(null, m_tableName, inTable, whereIncludes, deleteStatus, exec, getCredentialsProvider(), m_batchSize);
// set warning message generated during deleting rows
if (errMsg != null) {
setWarningMessage(errMsg);
}
// create out table with update column
final ColumnRearranger colre = createColumnRearranger(inTable.getSpec(), deleteStatus);
final BufferedDataTable outTable = exec.createColumnRearrangeTable(inTable, colre, exec.createSubProgress(1.0));
return new BufferedDataTable[] { outTable };
}
use of org.knime.core.node.port.database.DatabaseConnectionSettings 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() };
}
Aggregations