use of org.talend.core.model.metadata.IMetadataTable in project tdi-studio-se by Talend.
the class UpdateNodeParameterCommand method updateProperty.
@SuppressWarnings("unchecked")
private void updateProperty() {
Object updateObject = result.getUpdateObject();
if (updateObject == null) {
return;
}
if (updateObject instanceof Node) {
// opened job
Node node = (Node) updateObject;
boolean update = false;
// added by wzhang for bug 9302
boolean isXsdPath = false;
Object parameter = result.getParameter();
IElementParameter curPropertyParam = null;
//$NON-NLS-1$
String parentParamName = "PROPERTY";
ConnectionItem connectionItem = null;
if (parameter instanceof ConnectionItem) {
if (parameter instanceof XmlFileConnectionItem) {
String filePath = ((XmlFileConnection) ((XmlFileConnectionItem) parameter).getConnection()).getXmlFilePath();
if (filePath != null) {
if (XmlUtil.isXSDFile(filePath)) {
isXsdPath = true;
}
}
}
connectionItem = (ConnectionItem) result.getParameter();
for (IElementParameter param : node.getElementParameters()) {
if (param.getFieldType() == EParameterFieldType.PROPERTY_TYPE && param.getChildParameters().get(EParameterName.REPOSITORY_PROPERTY_TYPE.getName()).getValue().equals(connectionItem.getProperty().getId())) {
curPropertyParam = param;
parentParamName = curPropertyParam.getName();
if (connectionItem != null) {
ConnectionContextHelper.addContextForNodeParameter(node, connectionItem, false);
}
break;
}
}
}
if (result.getResultType() == EUpdateResult.UPDATE) {
// upgrade from repository
if (result.isChecked() && connectionItem != null) {
List<? extends IElementParameter> elemParameters = new ArrayList<>(node.getElementParameters());
for (IElementParameter param : elemParameters) {
String repositoryValue = param.getRepositoryValue();
if (param.getRepositoryValue() == null || (curPropertyParam != null && param.getRepositoryProperty() != null && !param.getRepositoryProperty().equals(curPropertyParam.getName()))) {
continue;
}
if (param.getFieldType() == EParameterFieldType.PROPERTY_TYPE) {
continue;
}
if ((repositoryValue != null) && (param.isShow(node.getElementParameters()) || node.getComponentProperties() != null || (node instanceof INode && ((INode) node).getComponent().getName().equals("tAdvancedFileOutputXML")) || (node instanceof INode && ((INode) node).getComponent().getName().equals("tESBProviderRequest")))) {
//$NON-NLS-1$
if (param.getName().equals(EParameterName.PROPERTY_TYPE.getName()) || param.getFieldType() == EParameterFieldType.MEMO_SQL) {
continue;
}
if (param.getFieldType().equals(EParameterFieldType.FILE) && isXsdPath) {
continue;
}
IMetadataTable table = null;
if (!node.getMetadataList().isEmpty()) {
table = node.getMetadataList().get(0);
}
Object objectValue = RepositoryToComponentProperty.getValue(connectionItem.getConnection(), repositoryValue, table);
if (objectValue == null || "".equals(objectValue)) {
if (GlobalServiceRegister.getDefault().isServiceRegistered(IESBService.class)) {
IESBService service = (IESBService) GlobalServiceRegister.getDefault().getService(IESBService.class);
if (service != null) {
String propertyValue = (String) node.getPropertyValue(EParameterName.REPOSITORY_PROPERTY_TYPE.getName());
if (node.getComponent().getName().startsWith("tESB")) {
if (propertyValue.contains(" - ")) {
propertyValue = propertyValue.split(" - ")[0];
}
}
IRepositoryViewObject lastVersion = UpdateRepositoryUtils.getRepositoryObjectById(propertyValue);
if (lastVersion != null) {
Item item = lastVersion.getProperty().getItem();
if (item != null) {
Object objectValueFromESB = service.getValue(item, repositoryValue, node);
if (objectValueFromESB != null) {
objectValue = objectValueFromESB;
}
}
}
}
}
}
if (param.getName().equals(EParameterName.CDC_TYPE_MODE.getName())) {
//
String propertyValue = (String) node.getPropertyValue(EParameterName.REPOSITORY_PROPERTY_TYPE.getName());
Item item = null;
IRepositoryViewObject lastVersion = UpdateRepositoryUtils.getRepositoryObjectById(propertyValue);
if (lastVersion != null) {
item = lastVersion.getProperty().getItem();
}
if (item != null && PluginChecker.isCDCPluginLoaded()) {
ICDCProviderService service = (ICDCProviderService) GlobalServiceRegister.getDefault().getService(ICDCProviderService.class);
if (service != null) {
try {
List<IRepositoryViewObject> all;
all = CorePlugin.getDefault().getProxyRepositoryFactory().getAll(ERepositoryObjectType.METADATA_CONNECTIONS);
for (IRepositoryViewObject obj : all) {
Item tempItem = obj.getProperty().getItem();
if (tempItem instanceof DatabaseConnectionItem) {
String cdcLinkId = service.getCDCConnectionLinkId((DatabaseConnectionItem) tempItem);
if (cdcLinkId != null && item.getProperty().getId().equals(cdcLinkId)) {
objectValue = RepositoryToComponentProperty.getValue(((DatabaseConnectionItem) tempItem).getConnection(), repositoryValue, node.getMetadataList().get(0));
}
}
}
} catch (PersistenceException e) {
ExceptionHandler.process(e);
}
}
}
}
if (GlobalServiceRegister.getDefault().isServiceRegistered(IJsonFileService.class)) {
IJsonFileService jsonService = (IJsonFileService) GlobalServiceRegister.getDefault().getService(IJsonFileService.class);
boolean paramChanged = jsonService.changeFilePathFromRepository(connectionItem.getConnection(), param, node, objectValue);
if (paramChanged) {
continue;
}
}
if (objectValue != null) {
if (param.getFieldType().equals(EParameterFieldType.CLOSED_LIST) && repositoryValue.equals(UpdatesConstants.TYPE)) {
boolean found = false;
String[] items = param.getListRepositoryItems();
for (int i = 0; (i < items.length) && (!found); i++) {
if (objectValue.equals(items[i])) {
found = true;
node.setPropertyValue(param.getName(), param.getListItemsValue()[i]);
}
}
} else {
// update tFileInputExcel job
if (param.getFieldType().equals(EParameterFieldType.TABLE)) {
String name = param.getName();
if (name.equals("ROOT") || name.equals("LOOP") || name.equals("GROUP") && objectValue instanceof List) {
param.setValue(objectValue);
} else if (param.getName().equals("SHEETLIST") && objectValue instanceof List) {
List<Map<String, Object>> paramMaps = (List<Map<String, Object>>) param.getValue();
if (paramMaps == null) {
paramMaps = new ArrayList<Map<String, Object>>();
node.setPropertyValue(param.getName(), paramMaps);
} else {
// hywang add for 9537
List<Map<String, Object>> objectValueList = (List<Map<String, Object>>) objectValue;
if (paramMaps.size() < objectValueList.size()) {
paramMaps.clear();
for (int i = 0; i < objectValueList.size(); i++) {
Map<String, Object> map = objectValueList.get(i);
paramMaps.add(map);
}
} else {
String value = null;
List<String> repNames = new ArrayList<String>();
for (int i = 0; i < objectValueList.size(); i++) {
repNames.add(objectValueList.get(i).get("SHEETNAME").toString());
}
for (int j = 0; j < paramMaps.size(); j++) {
Map<String, Object> map = paramMaps.get(j);
value = map.get("SHEETNAME").toString();
if (!repNames.contains(value)) {
paramMaps.remove(j);
}
}
}
}
} else if ((name.equals("HADOOP_ADVANCED_PROPERTIES") || name.equals("ADVANCED_PROPERTIES") || name.equals("HBASE_PARAMETERS") || name.equals("SAP_PROPERTIES") && objectValue instanceof List)) {
List<HashMap<String, Object>> oldValue = (List<HashMap<String, Object>>) param.getValue();
for (HashMap<String, Object> map : oldValue) {
if (map.get("BUILDIN") != null && !map.get("BUILDIN").equals("") && Boolean.valueOf(String.valueOf(map.get("BUILDIN")))) {
((List<HashMap<String, Object>>) objectValue).add(map);
}
}
param.setValue(objectValue);
} else // it in jobs
if (param.getName().equals("DRIVER_JAR") && objectValue instanceof List) {
param.setValue(objectValue);
}
} else {
node.setPropertyValue(param.getName(), objectValue);
}
}
} else if (param.getFieldType().equals(EParameterFieldType.TABLE) && UpdatesConstants.XML_MAPPING.equals(repositoryValue)) {
RepositoryToComponentProperty.getTableXMLMappingValue(connectionItem.getConnection(), (List<Map<String, Object>>) param.getValue(), node);
} else if (param.getFieldType().equals(EParameterFieldType.TABLE) && param.getName().equals("PARAMS")) {
objectValue = RepositoryToComponentProperty.getValue(connectionItem.getConnection(), "PARAMS", node.getMetadataList().get(0));
List<Map<String, Object>> paramMaps = (List<Map<String, Object>>) param.getValue();
if (paramMaps == null) {
paramMaps = new ArrayList<Map<String, Object>>();
} else {
paramMaps.clear();
}
if (objectValue != null) {
List<String> objectValueList = (List<String>) objectValue;
for (int i = 0; i < objectValueList.size(); i++) {
Map<String, Object> map = new HashedMap();
map.put("VALUE", TalendTextUtils.addQuotes(objectValueList.get(i)));
paramMaps.add(map);
}
}
} else if (node.getComponentProperties() != null && objectValue == null) {
// for new framework, still save the null value in component
node.setPropertyValue(param.getName(), objectValue);
}
if (!("tMDMReceive".equals(node.getComponent().getName()) && "XPATH_PREFIX".equals(//$NON-NLS-1$ //$NON-NLS-2$
param.getRepositoryValue()))) {
param.setRepositoryValueUsed(true);
param.setReadOnly(true);
update = true;
}
}
}
} else {
// Added TDQ-11688 20170309 yyin
ITDQPatternService service = null;
if (GlobalServiceRegister.getDefault().isServiceRegistered(ITDQPatternService.class)) {
service = (ITDQPatternService) GlobalServiceRegister.getDefault().getService(ITDQPatternService.class);
}
if (service != null && (service.isSinglePatternNode(node) || service.isMultiPatternNode(node)) && parameter != null && parameter instanceof IElementParameter) {
IElementParameter elementParameter = node.getElementParameter(((IElementParameter) parameter).getName());
if (elementParameter != null && !elementParameter.getValue().equals(((IElementParameter) parameter).getValue())) {
elementParameter.setValue(((IElementParameter) parameter).getValue());
}
update = true;
Object regexValue = null;
Object parameterValue = ((IElementParameter) parameter).getValue();
if ("PATTERN_REGEX".equals(((IElementParameter) parameter).getName())) {
regexValue = parameterValue;
} else if ("SCHEMA_PATTERN_CHECK".equals(((IElementParameter) parameter).getName())) {
List<Map<String, String>> multiPatternList = ((List<Map<String, String>>) parameterValue);
for (Map<String, String> patternMap : multiPatternList) {
regexValue = patternMap.get("PATTERN_REGEX");
if (regexValue == null) {
patternMap.put("PATTERN_PROPERTY", EmfComponent.BUILTIN);
}
}
}
if (regexValue == null || regexValue.toString().isEmpty()) {
update = false;
}
}
}
}
if (!update) {
// bult-in
String propertyName = parentParamName + ":" + EParameterName.PROPERTY_TYPE.getName();
if (this.result.getParameter() instanceof IElementParameter) {
IElementParameter parentParam = ((IElementParameter) this.result.getParameter()).getParentParameter();
if (parentParam != null) {
parentParamName = parentParam.getName();
propertyName = parentParam.getName() + ":" + parentParam.getChildParameters().get(EParameterName.PROPERTY_TYPE.getName()).getName();
}
}
node.setPropertyValue(propertyName, EmfComponent.BUILTIN);
for (IElementParameter param : node.getElementParameters()) {
if (param.getRepositoryValue() == null || param.getRepositoryProperty() != null && !param.getRepositoryProperty().equals(parentParamName)) {
continue;
}
if (param.getFieldType() == EParameterFieldType.PROPERTY_TYPE) {
continue;
}
if (param.isShow(node.getElementParameters())) {
if (param.getName().equals(EParameterName.PROPERTY_TYPE.getName()) || param.getFieldType() == EParameterFieldType.MEMO_SQL) {
continue;
}
param.setRepositoryValueUsed(false);
param.setReadOnly(false);
}
}
}
}
}
use of org.talend.core.model.metadata.IMetadataTable in project tdi-studio-se by Talend.
the class UpdateJobletNodeCommand method propagate.
private void propagate(Node jobletNode, boolean needPro) {
if (!needPro) {
return;
}
for (IConnection outConn : jobletNode.getOutgoingConnections()) {
IMetadataTable tab = jobletNode.getMetadataFromConnector(outConn.getConnectorName());
IMetadataTable tmpClone = tab.clone(true);
IMetadataTable newOutputMetadata = jobletNode.getMetadataTable(outConn.getConnectorName());
IMetadataTable toCopy = newOutputMetadata.clone();
Node targetNode = (Node) outConn.getTarget();
String dbmsId = null;
IMetadataTable copy = null;
if (targetNode.getMetadataFromConnector(outConn.getConnectorName()) != null) {
dbmsId = targetNode.getMetadataFromConnector(outConn.getConnectorName()).getDbms();
MetadataToolHelper.copyTable(dbmsId, toCopy, tmpClone);
toCopy = tmpClone;
// only if the target node have exactly the same connector
copy = targetNode.getMetadataFromConnector(outConn.getConnectorName()).clone(true);
} else {
// can only be FLOW right now for this case. //$NON-NLS-1$
final String mainConnector = "FLOW";
dbmsId = targetNode.getMetadataFromConnector(mainConnector).getDbms();
MetadataToolHelper.copyTable(dbmsId, toCopy, tmpClone);
toCopy = tmpClone;
// if don't have the same connector, take the main connector of the component.
copy = targetNode.getMetadataFromConnector(mainConnector).clone(true);
}
MetadataToolHelper.copyTable(dbmsId, toCopy, copy);
// inputSchemaParam);
ChangeMetadataCommand cmd = new ChangeMetadataCommand(targetNode, null, null, copy, null);
cmd.execute(true);
}
try {
ProxyRepositoryFactory.getInstance().save(((Process) jobletNode.getProcess()).getProperty().getItem());
} catch (PersistenceException e) {
ExceptionHandler.process(e);
}
}
use of org.talend.core.model.metadata.IMetadataTable in project tdi-studio-se by Talend.
the class UpdateJobletNodeCommand method updateGraphicalNodesSchema.
/**
* qzhang Comment method "updateGraphicalNodesSchema".
*
* this method is moved from class AbstractTalendEditor.
*
* @param evt
*/
@SuppressWarnings("unchecked")
private void updateGraphicalNodesSchema(Process process, PropertyChangeEvent evt) {
if (!(evt.getSource() instanceof INode)) {
return;
}
INode sourceNode = (INode) evt.getSource();
String componentName = sourceNode.getComponent().getName();
IComponent newComponent = ComponentsFactoryProvider.getInstance().get(componentName, process.getComponentsType());
if (newComponent == null) {
return;
}
Object[] newMetadataTables = (Object[]) evt.getNewValue();
List<IMetadataTable> newInputTableList = (List<IMetadataTable>) newMetadataTables[0];
List<IMetadataTable> newOutputTableList = (List<IMetadataTable>) newMetadataTables[1];
for (Node node : (List<Node>) process.getGraphicalNodes()) {
if (node.getComponent().getName().equals(componentName)) {
List<IElementParameter> outputElemParams = new ArrayList<IElementParameter>();
IElementParameter outputElemParam = null;
List<? extends IElementParameter> elementParameters = node.getElementParameters();
for (IElementParameter elementParameter : elementParameters) {
if (EParameterFieldType.SCHEMA_TYPE.equals(elementParameter.getFieldType())) {
outputElemParams.add(elementParameter);
}
}
ChangeMetadataCommand command;
List<? extends IConnection> incomingConnections = node.getIncomingConnections();
if (incomingConnections.size() <= 1) {
for (int i = 0; i < incomingConnections.size(); i++) {
IConnection connection = incomingConnections.get(i);
Node source = (Node) connection.getSource();
IMetadataTable metadataTable = connection.getMetadataTable();
IMetadataTable newInputMetadataTable = UpdateManagerUtils.getNewInputTableForConnection(newInputTableList, metadataTable.getAttachedConnector());
if (newInputMetadataTable != null && !metadataTable.sameMetadataAs(newInputMetadataTable)) {
IElementParameter elementParam = source.getElementParameterFromField(EParameterFieldType.SCHEMA_TYPE);
command = new ChangeMetadataCommand(source, elementParam, metadataTable, newInputMetadataTable);
command.execute(Boolean.FALSE);
}
}
} else {
for (IElementParameter param : node.getElementParameters()) {
if (param.isShow(node.getElementParameters()) && param.getFieldType().equals(EParameterFieldType.SCHEMA_TYPE)) {
IMetadataTable table = node.getMetadataFromConnector(param.getContext());
IElementParameter connParam = param.getChildParameters().get(EParameterName.CONNECTION.getName());
if (table != null && connParam != null && !StringUtils.isEmpty((String) connParam.getValue())) {
for (IConnection connection : incomingConnections) {
if (connection.isActivate() && connection.getName().equals(connParam.getValue())) {
if (!table.sameMetadataAs(connection.getMetadataTable(), IMetadataColumn.OPTIONS_IGNORE_KEY | IMetadataColumn.OPTIONS_IGNORE_NULLABLE | IMetadataColumn.OPTIONS_IGNORE_COMMENT | IMetadataColumn.OPTIONS_IGNORE_PATTERN | IMetadataColumn.OPTIONS_IGNORE_DBCOLUMNNAME | IMetadataColumn.OPTIONS_IGNORE_DBTYPE | IMetadataColumn.OPTIONS_IGNORE_DEFAULT | IMetadataColumn.OPTIONS_IGNORE_BIGGER_SIZE)) {
Node source = (Node) connection.getSource();
IMetadataTable metadataTable = connection.getMetadataTable();
IElementParameter elementParam = source.getElementParameterFromField(EParameterFieldType.SCHEMA_TYPE);
command = new ChangeMetadataCommand(source, elementParam, metadataTable, table);
command.execute(Boolean.FALSE);
}
}
}
}
}
}
}
List<? extends IConnection> outgoingConnections = node.getOutgoingConnections();
for (int i = 0; i < outgoingConnections.size(); i++) {
IConnection connection = outgoingConnections.get(i);
Node target = (Node) connection.getTarget();
IMetadataTable metadataTable = connection.getMetadataTable();
if (metadataTable != null) {
IMetadataTable newOutputMetadataTable = UpdateManagerUtils.getNewOutputTableForConnection(newOutputTableList, metadataTable.getAttachedConnector());
if (newOutputMetadataTable != null && !metadataTable.sameMetadataAs(newOutputMetadataTable)) {
IElementParameter elementParam = target.getElementParameterFromField(EParameterFieldType.SCHEMA_TYPE);
command = new ChangeMetadataCommand(target, elementParam, target.getMetadataFromConnector(metadataTable.getAttachedConnector()), newOutputMetadataTable);
command.execute(Boolean.FALSE);
}
}
}
List<IMetadataTable> metadataList = node.getMetadataList();
for (IMetadataTable metadataTable : metadataList) {
IMetadataTable newInputMetadataTable = UpdateManagerUtils.getNewInputTableForConnection(newInputTableList, metadataTable.getAttachedConnector());
IMetadataTable newOutputMetadataTable = UpdateManagerUtils.getNewOutputTableForConnection(newOutputTableList, metadataTable.getAttachedConnector());
outputElemParam = UpdateManagerUtils.getElemParam(outputElemParams, metadataTable.getAttachedConnector());
if (outputElemParam != null && newInputMetadataTable != null) {
command = new ChangeMetadataCommand(node, outputElemParam, (IMetadataTable) outputElemParam.getValue(), newInputMetadataTable);
command.execute(Boolean.FALSE);
IMetadataTable metadataFromConnector = node.getMetadataFromConnector(outputElemParam.getContext());
MetadataToolHelper.copyTable(newInputMetadataTable, metadataFromConnector);
} else if (outputElemParam != null && newOutputMetadataTable != null) {
command = new ChangeMetadataCommand(node, outputElemParam, (IMetadataTable) outputElemParam.getValue(), newOutputMetadataTable);
command.execute(Boolean.FALSE);
IMetadataTable metadataFromConnector = node.getMetadataFromConnector(outputElemParam.getContext());
MetadataToolHelper.copyTable(newOutputMetadataTable, metadataFromConnector);
}
}
}
}
}
use of org.talend.core.model.metadata.IMetadataTable in project tdi-studio-se by Talend.
the class DbGenerationManager method initExpression.
protected String initExpression(DbMapComponent component, ExternalDbMapEntry dbMapEntry) {
String expression = dbMapEntry.getExpression();
if (expression != null) {
List<Map<String, String>> itemNameList = null;
// MapExpressionParser mapParser = new MapExpressionParser("((\\s*(\\w+)\\s*\\.)*)(\\w+)");
// List<String> parseInTableEntryLocations = mapParser.parseInTableEntryLocations2(expression);
// for (String entryLocation : parseInTableEntryLocations) {
//
// }
// context.schema.context.table.column
// context.schema.table.column
// schema.context.table.column
// schema.table.column
// table.column
// add \\w*#* for oracle 12 , schema name start with C##
//$NON-NLS-1$
MapExpressionParser mapParser1 = new MapExpressionParser("((\\s*(\\w*#*\\w+)\\s*\\.)*)(\\w+)");
itemNameList = mapParser1.parseInTableEntryLocations2(expression);
if (itemNameList == null || itemNameList.isEmpty()) {
//$NON-NLS-1$
MapExpressionParser mapParser2 = new MapExpressionParser("\\s*(\\w+)\\s*\\.\\s*(\\w+)\\s*");
itemNameList = mapParser2.parseInTableEntryLocations(expression);
}
for (Map<String, String> itemNamemap : itemNameList) {
Set<Entry<String, String>> set = itemNamemap.entrySet();
Iterator<Entry<String, String>> ite = set.iterator();
while (ite.hasNext()) {
Entry<String, String> entry = ite.next();
String columnValue = entry.getKey();
String tableValue = entry.getValue();
String tableNameValue = tableValue;
// find original table name if tableValue is alias
String originaltableName = tableValue;
ExternalDbMapData externalData = (ExternalDbMapData) component.getExternalData();
final List<ExternalDbMapTable> inputTables = externalData.getInputTables();
for (ExternalDbMapTable inputTable : inputTables) {
if (inputTable.getAlias() != null && inputTable.getAlias().equals(tableValue)) {
originaltableName = inputTable.getTableName();
tableNameValue = inputTable.getAlias();
}
}
List<IConnection> inputConnections = (List<IConnection>) component.getIncomingConnections();
if (inputConnections == null) {
return expression;
}
for (IConnection iconn : inputConnections) {
IMetadataTable metadataTable = iconn.getMetadataTable();
String tName = iconn.getName();
if ((originaltableName.equals(tName) || tableValue.equals(tName)) && metadataTable != null) {
List<IMetadataColumn> lColumn = metadataTable.getListColumns();
String tableName = metadataTable.getTableName();
String tableColneName = tableName;
tableColneName = MetadataToolHelper.validateTableName(tableColneName);
if (tableValue.contains(".") && tableName != null) {
//$NON-NLS-1$
//$NON-NLS-1$
MapExpressionParser mapParser2 = new MapExpressionParser("\\s*(\\w+)\\s*\\.\\s*(\\w+)\\s*");
List<Map<String, String>> tableNameList = mapParser2.parseInTableEntryLocations(tableValue);
for (Map<String, String> tableNameMap : tableNameList) {
Set<Entry<String, String>> setTable = tableNameMap.entrySet();
Iterator<Entry<String, String>> iteTable = setTable.iterator();
while (iteTable.hasNext()) {
Entry<String, String> tableEntry = iteTable.next();
String tableLabel = tableEntry.getKey();
String schemaValue = tableEntry.getValue();
if (tableLabel.equals(metadataTable.getLabel()) && tableColneName.equals(tableLabel)) {
//$NON-NLS-1$//$NON-NLS-2$
tableName = tableName.replaceAll("\\$", "\\\\\\$");
//$NON-NLS-1$
expression = expression.replaceFirst(tableValue, schemaValue + "." + tableName);
}
}
}
} else if (tableName != null) {
if (tableValue.equals(metadataTable.getLabel()) && tableColneName.equals(tableValue)) {
//$NON-NLS-1$ //$NON-NLS-2$
tableName = tableName.replaceAll("\\$", "\\\\\\$");
expression = expression.replaceFirst(tableValue, tableName);
}
}
for (IMetadataColumn co : lColumn) {
if (columnValue.equals(co.getLabel())) {
String oriName = co.getOriginalDbColumnName();
// if OriginalDbColumn is empty , still use label to generate sql
if (oriName == null || "".equals(oriName)) {
//$NON-NLS-1$
continue;
}
if (expression.trim().equals(tableValue + "." + oriName)) {
continue;
}
if (expression.trim().equals(originaltableName + "." + oriName)) {
continue;
}
// if it is temp delived table, use label to generate sql
if (iconn.getLineStyle() == EConnectionType.TABLE_REF) {
continue;
}
//$NON-NLS-1$ //$NON-NLS-2$
oriName = oriName.replaceAll("\\$", "\\\\\\$");
expression = //$NON-NLS-1$
expression.replaceFirst(//$NON-NLS-1$
"\\." + co.getLabel(), //$NON-NLS-1$
"\\." + oriName);
expression = expression.replace("\"", "\\\"");
}
}
}
}
}
}
}
return expression;
}
use of org.talend.core.model.metadata.IMetadataTable in project tdi-studio-se by Talend.
the class DbGenerationManager method buildTableDeclaration.
protected void buildTableDeclaration(DbMapComponent component, StringBuilder sb, ExternalDbMapTable inputTable) {
Object inConns = component.getIncomingConnections();
List<IConnection> inputConnections = null;
if (inConns != null) {
inputConnections = (List<IConnection>) inConns;
}
if (inputConnections != null) {
IConnection iconn = this.getConnectonByName(inputConnections, inputTable.getTableName());
if (iconn == null) {
return;
}
boolean replace = false;
String inputTableName = inputTable.getName();
IMetadataTable metadataTable = iconn.getMetadataTable();
INode source = iconn.getSource();
String tableName = metadataTable.getTableName();
if (isELTDBMap(source)) {
DbMapComponent externalNode = null;
if (source instanceof DbMapComponent) {
externalNode = (DbMapComponent) source;
} else {
externalNode = (DbMapComponent) source.getExternalNode();
}
DbGenerationManager genManager = externalNode.getGenerationManager();
/* the new tabSpaceString in subquery must not be same with the parent!!! */
//$NON-NLS-1$
String deliveredTable = genManager.buildSqlSelect(externalNode, tableName, tabSpaceString + " ");
int begin = 1;
int end = deliveredTable.length() - 1;
if (begin <= end) {
//$NON-NLS-1$ //$NON-NLS-2$
sb.append("(").append(DbMapSqlConstants.NEW_LINE).append(tabSpaceString).append(" ");
sb.append(deliveredTable.substring(begin, end)).append(DbMapSqlConstants.NEW_LINE).append(tabSpaceString).append(//$NON-NLS-1$
" ) ");
}
}
String tableColneName = tableName;
tableColneName = MetadataToolHelper.validateTableName(tableColneName);
if (inputTableName.contains(".") && tableName != null) {
//$NON-NLS-1$
//$NON-NLS-1$
MapExpressionParser mapParser2 = new MapExpressionParser("\\s*(\\w+)\\s*\\.\\s*(\\w+)\\s*");
List<Map<String, String>> tableNameList = mapParser2.parseInTableEntryLocations(inputTableName);
for (Map<String, String> tableNameMap : tableNameList) {
Set<Entry<String, String>> setTable = tableNameMap.entrySet();
Iterator<Entry<String, String>> iteTable = setTable.iterator();
while (iteTable.hasNext()) {
Entry<String, String> tableEntry = iteTable.next();
String tableLabel = tableEntry.getKey();
String schemaValue = tableEntry.getValue();
if (tableLabel.equals(metadataTable.getLabel()) && tableColneName.equals(tableLabel)) {
sb.append(schemaValue);
//$NON-NLS-1$
sb.append(".");
sb.append(tableName);
replace = true;
}
}
}
} else if (tableName != null) {
if (inputTableName.equals(metadataTable.getLabel()) && tableColneName.equals(inputTableName)) {
sb.append(tableName);
replace = true;
}
}
if (!replace) {
sb.append(inputTable.getName());
}
}
}
Aggregations