Search in sources :

Example 6 with DBColumn

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 };
}
Also used : DatabaseConnectionPortObject(org.knime.core.node.port.database.DatabaseConnectionPortObject) DBTableCreator(org.knime.core.node.port.database.tablecreator.DBTableCreator) DatabaseConnectionSettings(org.knime.core.node.port.database.DatabaseConnectionSettings) DBColumn(org.knime.core.node.port.database.tablecreator.DBColumn) DBKey(org.knime.core.node.port.database.tablecreator.DBKey) DatabaseConnectionPortObject(org.knime.core.node.port.database.DatabaseConnectionPortObject) PortObject(org.knime.core.node.port.PortObject)

Example 7 with DBColumn

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);
}
Also used : DBColumn(org.knime.core.node.port.database.tablecreator.DBColumn) LinkedList(java.util.LinkedList)

Example 8 with DBColumn

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());
}
Also used : NodeSettingsWO(org.knime.core.node.NodeSettingsWO) DBColumn(org.knime.core.node.port.database.tablecreator.DBColumn)

Aggregations

DBColumn (org.knime.core.node.port.database.tablecreator.DBColumn)8 DBKey (org.knime.core.node.port.database.tablecreator.DBKey)3 ArrayList (java.util.ArrayList)2 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)2 DatabaseConnectionSettings (org.knime.core.node.port.database.DatabaseConnectionSettings)2 DBTableCreator (org.knime.core.node.port.database.tablecreator.DBTableCreator)2 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 TreeMap (java.util.TreeMap)1 JList (javax.swing.JList)1 JMenu (javax.swing.JMenu)1 JMenuItem (javax.swing.JMenuItem)1 NodeSettingsRO (org.knime.core.node.NodeSettingsRO)1 NodeSettingsWO (org.knime.core.node.NodeSettingsWO)1 PortObject (org.knime.core.node.port.PortObject)1 PortObjectSpec (org.knime.core.node.port.PortObjectSpec)1