use of org.knime.core.node.port.database.DatabaseConnectionPortObjectSpec in project knime-core by knime.
the class DBTableCreatorConfiguration method loadSettingsForDialog.
/**
* Load settings for NodeDialog
*
* @param settings NodeSettingsRO instance to load from
* @param specs PortObjectSpec array to load from
* @throws NotConfigurableException
*/
public void loadSettingsForDialog(final NodeSettingsRO settings, final PortObjectSpec[] specs) throws NotConfigurableException {
try {
loadSettingsForModel(settings);
final String dbIdentifier = ((DatabaseConnectionPortObjectSpec) specs[0]).getDatabaseIdentifier();
loadSettingsForSqlEditor(dbIdentifier);
m_tableSpec = (DataTableSpec) specs[1];
if (m_tableSpec != null && (useDynamicSettings() || getColumns().isEmpty())) {
loadColumnSettingsFromTableSpec(m_tableSpec);
if (useDynamicSettings()) {
updateKeysWithDynamicSettings();
}
} else {
loadSettingsForRowElements(CFG_COLUMNS_SETTINGS, settings);
loadSettingsForRowElements(CFG_KEYS_SETTINGS, settings);
}
} catch (InvalidSettingsException e) {
throw new NotConfigurableException(e.getMessage());
}
}
use of org.knime.core.node.port.database.DatabaseConnectionPortObjectSpec in project knime-core by knime.
the class DBWriterDialogPane method loadSettingsFrom.
/**
* {@inheritDoc}
*/
@Override
protected void loadSettingsFrom(final NodeSettingsRO settings, final PortObjectSpec[] specs) throws NotConfigurableException {
// get workflow credentials
m_loginPane.loadSettingsFrom(settings, specs, getCredentialsProvider());
// table name
m_table.setText(settings.getString(DBWriterNodeModel.KEY_TABLE_NAME, ""));
// append data flag
m_append.setSelected(settings.getBoolean(DBWriterNodeModel.KEY_APPEND_DATA, true));
m_insertNullForMissing.setSelected(settings.getBoolean(DBWriterNodeModel.KEY_INSERT_NULL_FOR_MISSING_COLS, false));
m_insertNullForMissing.setEnabled(m_append.isSelected());
// introduced in KNIME 3.3.1 default behavior was not failing e.g. false
m_failOnError.setSelected(settings.getBoolean(DBWriterNodeModel.KEY_FAIL_ON_ERROR, false));
// load SQL Types for each column
try {
NodeSettingsRO typeSett = settings.getNodeSettings(DBWriterNodeModel.CFG_SQL_TYPES);
m_typePanel.loadSettingsFrom(typeSett, (DataTableSpec) specs[0]);
} catch (InvalidSettingsException ise) {
m_typePanel.loadSettingsFrom(null, (DataTableSpec) specs[0]);
}
// load batch size
final int batchSize = settings.getInt(DBWriterNodeModel.KEY_BATCH_SIZE, DatabaseConnectionSettings.BATCH_WRITE_SIZE);
m_batchSize.setText(Integer.toString(batchSize));
if ((specs.length > 1) && (specs[1] instanceof DatabaseConnectionPortObjectSpec)) {
m_loginPane.setVisible(false);
} else {
m_loginPane.setVisible(true);
}
}
use of org.knime.core.node.port.database.DatabaseConnectionPortObjectSpec in project knime-core by knime.
the class DBWriterNodeModel method configure.
/**
* {@inheritDoc}
*/
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
DataTableSpec tableSpec = (DataTableSpec) inSpecs[0];
// 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().supportsInsert()) {
throw new InvalidSettingsException("Connected database does not support insert operations");
}
} else {
if (!m_conn.getUtility().supportsInsert()) {
throw new InvalidSettingsException("Selected database does not support insert operations");
}
}
// check table name
if ((m_tableName == null) || m_tableName.trim().isEmpty()) {
throw new InvalidSettingsException("Configure node and enter a valid table name.");
}
// throw exception if no data provided
if (tableSpec.getNumColumns() == 0) {
throw new InvalidSettingsException("No columns in input data.");
}
// copy map to ensure only columns which are with the data
Map<String, String> map = new LinkedHashMap<>();
// check that each column has a assigned type
for (int i = 0; i < tableSpec.getNumColumns(); i++) {
final String name = tableSpec.getColumnSpec(i).getName();
String sqlType = m_types.get(name);
if (sqlType == null) {
final DataType type = tableSpec.getColumnSpec(i).getType();
if (type.isCompatible(IntValue.class)) {
sqlType = DBWriterNodeModel.SQL_TYPE_INTEGER;
} else if (type.isCompatible(DoubleValue.class)) {
sqlType = DBWriterNodeModel.SQL_TYPE_DOUBLE;
} else if (type.isCompatible(DateAndTimeValue.class)) {
sqlType = DBWriterNodeModel.SQL_TYPE_DATEANDTIME;
} else {
sqlType = DBWriterNodeModel.SQL_TYPE_STRING;
}
}
map.put(name, sqlType);
}
m_types.clear();
m_types.putAll(map);
if (!m_append) {
super.setWarningMessage("Existing table \"" + m_tableName + "\" will be dropped!");
}
return new DataTableSpec[0];
}
use of org.knime.core.node.port.database.DatabaseConnectionPortObjectSpec in project knime-core by knime.
the class DBUpdateDialogPane 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(DBUpdateNodeModel.KEY_TABLE_NAME, ""));
// load SET column panel
DataColumnSpecFilterConfiguration configSet = new DataColumnSpecFilterConfiguration(DBUpdateNodeModel.KEY_SET_FILTER_COLUMN);
configSet.loadConfigurationInDialog(settings, tableSpec);
m_columnsInSetClause.loadConfiguration(configSet, tableSpec);
// load WHERE column panel
DataColumnSpecFilterConfiguration configWhere = new DataColumnSpecFilterConfiguration(DBUpdateNodeModel.KEY_WHERE_FILTER_COLUMN);
configWhere.loadConfigurationInDialog(settings, tableSpec);
m_columnsInWhereClause.loadConfiguration(configWhere, tableSpec);
// load batch size
final int batchSize = settings.getInt(DBUpdateNodeModel.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 DBUpdateNodeModel method configure.
/**
* {@inheritDoc}
*/
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
DataTableSpec tableSpec = (DataTableSpec) inSpecs[0];
// 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().supportsUpdate()) {
throw new InvalidSettingsException("Connected database does not support update operations");
}
} else {
if (!m_loginConfig.getUtility().supportsUpdate()) {
throw new InvalidSettingsException("Selected database does not support update operations");
}
}
// check table name
if ((m_tableName == null) || m_tableName.trim().isEmpty()) {
throw new InvalidSettingsException("Configure node and enter a valid table name.");
}
// check SET and WHERE for overlapping columns
final List<String> setIncludes = new ArrayList<>(Arrays.asList(m_configSET.applyTo(tableSpec).getIncludes()));
if (setIncludes.isEmpty()) {
throw new InvalidSettingsException("No SET column selected.");
}
final List<String> whereIncludes = new ArrayList<>(Arrays.asList(m_configWHERE.applyTo(tableSpec).getIncludes()));
if (whereIncludes.isEmpty()) {
throw new InvalidSettingsException("No WHERE column selected.");
}
if (!setIncludes.retainAll(whereIncludes)) {
throw new InvalidSettingsException("SET and WHERE column list contain duplicate columns.");
}
// forward input spec with one additional update (=int) column
final ColumnRearranger colre = createColumnRearranger(tableSpec, new int[] {});
return new DataTableSpec[] { colre.createSpec() };
}
Aggregations