use of org.talend.designer.dbmap.external.data.ExternalDbMapTable in project tdi-studio-se by Talend.
the class DbMapComponent method renameMetadataColumnName.
@Override
protected void renameMetadataColumnName(String conectionName, String oldColumnName, String newColumnName) {
if (conectionName == null || oldColumnName == null || newColumnName == null) {
throw new NullPointerException();
}
if (externalData != null) {
// rename metadata column name
List<ExternalDbMapTable> tables = new ArrayList<ExternalDbMapTable>(externalData.getInputTables());
tables.addAll(externalData.getOutputTables());
ExternalDbMapTable tableFound = null;
for (ExternalDbMapTable table : tables) {
if (table.getName().equals(conectionName)) {
List<ExternalDbMapEntry> metadataTableEntries = table.getMetadataTableEntries();
for (ExternalDbMapEntry entry : metadataTableEntries) {
if (entry.getName().equals(oldColumnName)) {
entry.setName(newColumnName);
tableFound = table;
break;
}
}
break;
}
}
// it is necessary to update expressions only if renamed column come from input table
if (tableFound != null && externalData.getInputTables().indexOf(tableFound) != -1) {
TableEntryLocation oldLocation = new TableEntryLocation(conectionName, oldColumnName);
TableEntryLocation newLocation = new TableEntryLocation(conectionName, newColumnName);
replaceLocationsInAllExpressions(oldLocation, newLocation, false);
}
}
}
use of org.talend.designer.dbmap.external.data.ExternalDbMapTable in project tdi-studio-se by Talend.
the class DbGenerationManager method removeUnmatchingEntriesWithColumnsOfMetadataTable.
/**
* DOC amaumont Comment method "removeUnmatchingEntriesWithColumnsOfMetadataTable".
*
* @param outputTable
* @param metadataTable
*/
protected ExternalDbMapTable removeUnmatchingEntriesWithColumnsOfMetadataTable(ExternalDbMapTable externalDbMapTable, IMetadataTable metadataTable) {
ExternalDbMapTable clonedTable = null;
try {
clonedTable = (ExternalDbMapTable) externalDbMapTable.clone();
} catch (CloneNotSupportedException e) {
ExceptionHandler.process(e);
}
List<ExternalDbMapEntry> metadataTableEntries = clonedTable.getMetadataTableEntries();
if (metadataTableEntries != null) {
HashMap<String, IMetadataColumn> hNameToColumn = new HashMap<String, IMetadataColumn>();
List<IMetadataColumn> listColumns = metadataTable.getListColumns();
for (IMetadataColumn column : listColumns) {
hNameToColumn.put(column.getLabel(), column);
}
List<ExternalDbMapEntry> dbMapEntriesToRemove = new ArrayList<ExternalDbMapEntry>();
for (ExternalDbMapEntry externalTableEntry : metadataTableEntries) {
String entryName = externalTableEntry.getName();
IMetadataColumn column = hNameToColumn.get(entryName);
if (column == null) {
dbMapEntriesToRemove.add(externalTableEntry);
}
}
metadataTableEntries.removeAll(dbMapEntriesToRemove);
}
return clonedTable;
}
use of org.talend.designer.dbmap.external.data.ExternalDbMapTable in project tdi-studio-se by Talend.
the class DbMapComponent method sortOutputsConnectionsLikeVisualOrder.
/**
* Sort outgoingConnections for code generation as visible output zone of tMap.
*/
@SuppressWarnings("unchecked")
private void sortOutputsConnectionsLikeVisualOrder() {
if (!MapperMain.isStandAloneMode()) {
List<IConnection> outgoingConnections = (List<IConnection>) getOutgoingConnections();
Map<String, IConnection> connectionNameToOutgoingConnection = new HashMap<String, IConnection>();
for (IConnection connection : outgoingConnections) {
connectionNameToOutgoingConnection.put(connection.getUniqueName(), connection);
}
List<ExternalDbMapTable> outputTables = externalData.getOutputTables();
List<IConnection> tmpList = new ArrayList<IConnection>(outgoingConnections);
outgoingConnections.clear();
int lstSize = outputTables.size();
for (int i = 0; i < lstSize; i++) {
ExternalDbMapTable table = outputTables.get(i);
String tableName = table.getName();
IConnection connection = connectionNameToOutgoingConnection.get(tableName);
if (connection != null) {
outgoingConnections.add(connection);
}
}
// add connections without metadata
for (IConnection connection : tmpList) {
if (!outgoingConnections.contains(connection)) {
outgoingConnections.add(connection);
}
}
}
}
use of org.talend.designer.dbmap.external.data.ExternalDbMapTable in project tdi-studio-se by Talend.
the class DbMapComponent method buildExternalData.
@Override
public void buildExternalData(AbstractExternalData abstractData) {
externalData = new ExternalDbMapData();
if (abstractData instanceof DBMapData) {
DBMapData mapperData = (DBMapData) abstractData;
List<ExternalDbMapTable> externalTables = new ArrayList<ExternalDbMapTable>();
// input
for (InputTable pTable : mapperData.getInputTables()) {
ExternalDbMapTable externalTable = new ExternalDbMapTable();
externalTable.setName(pTable.getName());
externalTable.setMinimized(pTable.isMinimized());
externalTable.setAlias(pTable.getAlias());
externalTable.setJoinType(pTable.getJoinType());
externalTable.setTableName(pTable.getTableName());
List<ExternalDbMapEntry> entities = new ArrayList<ExternalDbMapEntry>();
for (DBMapperTableEntry pEntity : pTable.getDBMapperTableEntries()) {
ExternalDbMapEntry entity = new ExternalDbMapEntry();
entity.setExpression(pEntity.getExpression());
entity.setJoin(pEntity.isJoin());
entity.setName(pEntity.getName());
entity.setOperator(pEntity.getOperator());
entities.add(entity);
}
externalTable.setMetadataTableEntries(entities);
externalTables.add(externalTable);
}
externalData.setInputTables(externalTables);
// output
externalTables = new ArrayList<ExternalDbMapTable>();
for (OutputTable pTable : mapperData.getOutputTables()) {
ExternalDbMapTable externalTable = new ExternalDbMapTable();
externalTable.setName(pTable.getName());
externalTable.setMinimized(pTable.isMinimized());
externalTable.setTableName(pTable.getTableName());
List<ExternalDbMapEntry> entities = new ArrayList<ExternalDbMapEntry>();
for (DBMapperTableEntry pEntity : pTable.getDBMapperTableEntries()) {
ExternalDbMapEntry entity = new ExternalDbMapEntry();
entity.setExpression(pEntity.getExpression());
entity.setName(pEntity.getName());
entities.add(entity);
}
externalTable.setMetadataTableEntries(entities);
// filters
entities = new ArrayList<ExternalDbMapEntry>();
List<ExternalDbMapEntry> otherFilterEntities = new ArrayList<ExternalDbMapEntry>();
for (FilterEntry pFilter : pTable.getFilterEntries()) {
ExternalDbMapEntry entity = new ExternalDbMapEntry();
entity.setExpression(pFilter.getExpression());
entity.setName(pFilter.getName());
if (FilterTableEntry.OTHER_FILTER.equals(pFilter.getFilterKind())) {
otherFilterEntities.add(entity);
} else {
entities.add(entity);
}
}
externalTable.setCustomWhereConditionsEntries(entities);
externalTable.setCustomOtherConditionsEntries(otherFilterEntities);
externalTables.add(externalTable);
}
externalData.setOutputTables(externalTables);
}
this.setExternalData(externalData);
}
use of org.talend.designer.dbmap.external.data.ExternalDbMapTable in project tdi-studio-se by Talend.
the class DbMapComponentDocumentation method generateXMLInfo.
/**
* Generates all information which for XML file.
*/
private void generateXMLInfo() {
document = DocumentHelper.createDocument();
//$NON-NLS-1$
Element externalNodeElement = document.addElement("externalNode");
generateMessages(externalNodeElement);
//$NON-NLS-1$
externalNodeElement.addAttribute("name", HTMLDocUtils.checkString(this.componentName));
//$NON-NLS-1$
externalNodeElement.addAttribute("preview", HTMLDocUtils.checkString(this.previewPicPath));
List<ExternalDbMapTable> inputTables = externalData.getInputTables();
List<ExternalDbMapTable> outputTables = externalData.getOutputTables();
List<ExternalDbMapTable> varTables = externalData.getVarsTables();
handleMapperTablesInfo(inputTables, externalNodeElement, IHTMLDocConstants.MAPPER_TABLE_INPUT);
handleMapperTablesInfo(outputTables, externalNodeElement, IHTMLDocConstants.MAPPER_TABLE_OUPUT);
handleMapperTablesInfo(varTables, externalNodeElement, IHTMLDocConstants.MAPPER_TABLE_VAR);
}
Aggregations