use of org.knime.core.node.port.database.tablecreator.DBColumn in project knime-core by knime.
the class DBTableCreatorNodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
protected PortObject[] execute(final PortObject[] inData, final ExecutionContext exec) throws Exception {
exec.setMessage("Creating table");
final DatabaseConnectionPortObject dbConn = (DatabaseConnectionPortObject) inData[0];
final DatabaseConnectionSettings conn = dbConn.getConnectionSettings(getCredentialsProvider());
final DBTableCreator tableCreator = conn.getUtility().getTableCreator(m_config.getSchema(), getTableName(), m_config.isTempTable());
final List<DBColumn> columns = m_config.getColumns();
final List<DBKey> keys = m_config.getKeys();
tableCreator.createTable(conn, getCredentialsProvider(), m_config.ifNotExists(), columns.toArray(new DBColumn[columns.size()]), keys.toArray(new DBKey[keys.size()]), m_config.getAdditionalOptions());
pushFlowVariables(tableCreator.getSchema(), tableCreator.getTableName());
final String warning = tableCreator.getWarning();
if (!StringUtils.isBlank(warning)) {
setWarningMessage(warning);
}
return new PortObject[] { dbConn };
}
use of org.knime.core.node.port.database.tablecreator.DBColumn in project knime-core by knime.
the class ColumnsPanel method removeKeysWithColumns.
/**
* Removes all keys that contain at least one column from the column collections
*
* @param columnIndices the column indices
*/
void removeKeysWithColumns(final Collection<DBColumn> columns) {
final List<RowElement> keysToRemove = new LinkedList<>();
final List<RowElement> keyElems = getConfig().getRowElements(DBTableCreatorConfiguration.CFG_KEYS_SETTINGS);
for (RowElement elem : keyElems) {
for (DBColumn col : ((KeyElement) elem).getColumns()) {
if (columns.contains(col)) {
keysToRemove.add(elem);
}
}
}
keyElems.removeAll(keysToRemove);
}
use of org.knime.core.node.port.database.tablecreator.DBColumn in project knime-core by knime.
the class KeyElement method saveSettingsTo.
/**
* {@inheritDoc}
*/
@Override
protected void saveSettingsTo(final NodeSettingsWO settings) {
settings.addString(CFG_KEY_NAME, getName());
NodeSettingsWO cfg = settings.addNodeSettings(CFG_KEY_COLUMNS);
int idx = 0;
for (DBColumn col : getColumns()) {
cfg.addString(ColumnElement.DEFAULT_PREFIX + idx++, col.getName());
}
settings.addBoolean(CFG_KEY_PRIMARY, isPrimaryKey());
}
Aggregations