Search in sources :

Example 1 with SurrogateKey

use of org.talend.designer.scd.model.SurrogateKey in project tdi-studio-se by Talend.

the class SurrogateKeyManager method createSurrogateKey.

public SurrogateKey createSurrogateKey() {
    SurrogateKey key = new SurrogateKey();
    key.setColumn(generateKeyName());
    key.setCreation(SurrogateCreationType.AUTO_INCREMENT);
    //$NON-NLS-1$
    key.setComplement("");
    return key;
}
Also used : SurrogateKey(org.talend.designer.scd.model.SurrogateKey)

Example 2 with SurrogateKey

use of org.talend.designer.scd.model.SurrogateKey in project tdi-studio-se by Talend.

the class ScdManager method reloadSurrogateKeyParameter.

/**
     * DOC hcw Comment method "reloadSurrogateKeyParameter".
     */
private void reloadSurrogateKeyParameter() {
    surrogateKeys = new ArrayList<SurrogateKey>();
    SurrogateKey key = new SurrogateKey();
    surrogateKeys.add(key);
    key.setColumn(getStringParameter(ScdParameterConstants.SURROGATE_KEY));
    key.setCreation(SurrogateCreationType.getTypeByValue(getStringParameter(ScdParameterConstants.SK_CREATION)));
    if (key.getCreation() == SurrogateCreationType.INPUT_FIELD) {
        key.setComplement(getStringParameter(ScdParameterConstants.SK_INPUT_FIELD));
    } else if (key.getCreation() == SurrogateCreationType.ROUTINE) {
        key.setComplement(getStringParameter(ScdParameterConstants.SK_ROUTINE));
    } else if (key.getCreation() == SurrogateCreationType.DB_SEQUENCE) {
        key.setComplement(getStringParameter(ScdParameterConstants.SK_DB_SEQUENCE));
    }
}
Also used : SurrogateKey(org.talend.designer.scd.model.SurrogateKey)

Example 3 with SurrogateKey

use of org.talend.designer.scd.model.SurrogateKey in project tdi-studio-se by Talend.

the class ScdManager method removeUnusedAndGeneratedColumns.

// public boolean enableOracle() {
// IElementParameter param = getComponent().getElementParameter(EParameterName.PROPERTY_TYPE.getName());
// if (param != null && param.getRepositoryValue() != null) {
// String value = param.getRepositoryValue().toLowerCase();
// if (value.endsWith("oracle") || value.endsWith("ingres")) {
// return true;
// }
// }
// return false;
// }
/**
     * DOC chuang Comment method "removeGeneratedColumns".
     * 
     * @param metadataList
     * @param unusedFields
     * @return
     * @return
     */
private Map<String, IMetadataColumn> removeUnusedAndGeneratedColumns(List<IMetadataTable> metadataList, List<String> unusedFields) {
    Map<String, IMetadataColumn> columnsMap = new HashMap<String, IMetadataColumn>();
    if (metadataList != null) {
        for (IMetadataTable table : metadataList) {
            List<IMetadataColumn> columns = new ArrayList<IMetadataColumn>(table.getListColumns());
            // remove from backend
            for (int i = columns.size() - 1; i >= 0; i--) {
                IMetadataColumn col = columns.get(i);
                boolean generateColumn = GENERATE_COLUMN.equals(col.getComment());
                // generated field from schema should be remove when DB_SEQUENCE
                if (surrogateKeys != null && !surrogateKeys.isEmpty()) {
                    for (SurrogateKey key : surrogateKeys) {
                        if (key.getCreation() == SurrogateCreationType.DB_SEQUENCE && col.isKey()) {
                            generateColumn = true;
                        }
                    }
                }
                if (unusedFields.contains(col.getLabel()) || generateColumn) {
                    // remove unused field or generated field from schema
                    table.getListColumns().remove(i);
                } else {
                    columnsMap.put(col.getLabel(), col);
                }
            }
        }
    }
    return columnsMap;
}
Also used : IMetadataTable(org.talend.core.model.metadata.IMetadataTable) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) SurrogateKey(org.talend.designer.scd.model.SurrogateKey)

Example 4 with SurrogateKey

use of org.talend.designer.scd.model.SurrogateKey in project tdi-studio-se by Talend.

the class ScdManager method fixKeyColumnsInOutputSchema.

/**
     * DOC chuang Comment method "fixKeyColumnsInOutputSchema".
     * 
     * @param schema
     * @param inputColumnsMap
     * @param lang
     */
private void fixKeyColumnsInOutputSchema(IMetadataTable schema, Map<String, IMetadataColumn> inputColumnsMap, Map<String, IMetadataColumn> surrogateKeysColumnMap, ECodeLanguage lang) {
    Map<String, IMetadataColumn> columnsMap = new HashMap<String, IMetadataColumn>();
    for (IMetadataColumn column : schema.getListColumns()) {
        columnsMap.put(column.getLabel(), column);
    }
    // all source keys are not keys in the output schema
    if (sourceKeys != null && !sourceKeys.isEmpty()) {
        for (String key : sourceKeys) {
            IMetadataColumn column = columnsMap.get(key);
            if (column != null && GENERATE_COLUMN.equals(column.getComment())) {
                column.setKey(false);
            }
        }
    }
    if (surrogateKeys != null && !surrogateKeys.isEmpty()) {
        for (SurrogateKey key : surrogateKeys) {
            if (StringUtils.isEmpty(key.getColumn())) {
                // name is missing
                continue;
            }
            IMetadataColumn column = columnsMap.get(key.getColumn());
            if (column == null) {
                // if not exist in output schema, create surrogate key
                if (key.getCreation() == SurrogateCreationType.INPUT_FIELD) {
                    IMetadataColumn inputCol = inputColumnsMap.get(key.getComplement());
                    if (inputCol != null) {
                        column = inputCol.clone();
                        column.setLabel(key.getColumn());
                        column.setOriginalDbColumnName(key.getColumn());
                        column.setComment(GENERATE_COLUMN);
                        // set as key in output schema
                        column.setKey(true);
                        schema.getListColumns().add(column);
                    }
                } else if (key.getCreation() == SurrogateCreationType.DB_SEQUENCE) {
                    IMetadataColumn surrogateCol = surrogateKeysColumnMap.get(key.getColumn());
                    // no change , will use the old column
                    if (surrogateCol != null) {
                        column = surrogateCol.clone();
                        schema.getListColumns().add(column);
                        columnsMap.put(column.getLabel(), column);
                    } else if (surrogateKeysColumnMap.size() == 1) {
                        // rename the key
                        for (String oldKey : surrogateKeysColumnMap.keySet()) {
                            surrogateCol = surrogateKeysColumnMap.get(oldKey);
                            if (surrogateCol != null) {
                                column = surrogateCol.clone();
                                column.setLabel(key.getColumn());
                                column.setOriginalDbColumnName(key.getColumn());
                                schema.getListColumns().add(column);
                                columnsMap.put(column.getLabel(), column);
                            }
                        }
                    } else {
                        column = createMetadataColumn(columnsMap, schema, key.getColumn(), Integer.class, lang);
                        // set as key in output schema
                        column.setKey(true);
                    }
                } else {
                    column = createMetadataColumn(columnsMap, schema, key.getColumn(), Integer.class, lang);
                    // set as key in output schema
                    column.setKey(true);
                    if (key.getCreation() == SurrogateCreationType.ROUTINE) {
                        // routine is treated as string now
                        column.setTalendType(getType(String.class, lang));
                    }
                }
            }
            if (column != null) {
                column.setCustomId(0);
                column.setCustom(true);
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) SurrogateKey(org.talend.designer.scd.model.SurrogateKey)

Example 5 with SurrogateKey

use of org.talend.designer.scd.model.SurrogateKey in project tdi-studio-se by Talend.

the class MultipleSurrogateSection method setTableInput.

public void setTableInput(List<SurrogateKey> input) {
    tableModel = new ArrayList<SurrogateKey>();
    if (input == null) {
        return;
    }
    for (SurrogateKey key : input) {
        createNewItem(key);
        surrogateManager.addSurrogateKey(key);
    }
}
Also used : SurrogateKey(org.talend.designer.scd.model.SurrogateKey)

Aggregations

SurrogateKey (org.talend.designer.scd.model.SurrogateKey)8 HashMap (java.util.HashMap)2 IMetadataColumn (org.talend.core.model.metadata.IMetadataColumn)2 ArrayList (java.util.ArrayList)1 CCombo (org.eclipse.swt.custom.CCombo)1 StackLayout (org.eclipse.swt.custom.StackLayout)1 ModifyEvent (org.eclipse.swt.events.ModifyEvent)1 ModifyListener (org.eclipse.swt.events.ModifyListener)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 Color (org.eclipse.swt.graphics.Color)1 Composite (org.eclipse.swt.widgets.Composite)1 Label (org.eclipse.swt.widgets.Label)1 Text (org.eclipse.swt.widgets.Text)1 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)1 SurrogateCreationType (org.talend.designer.scd.model.SurrogateCreationType)1 DragDropManager (org.talend.designer.scd.util.DragDropManager)1