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;
}
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));
}
}
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;
}
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);
}
}
}
}
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);
}
}
Aggregations