use of org.talend.designer.dbmap.model.emf.dbmap.DBMapData in project tdi-studio-se by Talend.
the class DbMapComponent method getExternalEmfData.
@Override
public AbstractExternalData getExternalEmfData() {
final DBMapData emfMapperData = DbmapFactory.eINSTANCE.createDBMapData();
if (mapperMain == null) {
initMapperMain(false);
}
mapperMain.createModelFromExternalData(getIncomingConnections(), getOutgoingConnections(), externalData, getMetadataList(), false);
ExternalDbMapData data = mapperMain.buildExternalData();
if (mapperMain != null && data != null) {
if (externalData != null) {
DBMapHelper.saveDataToEmf(emfMapperData, externalData);
}
}
return emfMapperData;
}
use of org.talend.designer.dbmap.model.emf.dbmap.DBMapData in project tdi-studio-se by Talend.
the class DbMapService method updateEMFDBMapData.
@Override
public void updateEMFDBMapData(NodeType nodeType, String oldValue, String newValue) {
AbstractExternalData nodeData = nodeType.getNodeData();
if (nodeData instanceof DBMapData) {
DBMapData dbMapData = (DBMapData) nodeData;
for (InputTable input : dbMapData.getInputTables()) {
if (input.getName().equals(oldValue) || input.getTableName().equals(oldValue)) {
input.setName(newValue);
input.setTableName(newValue);
}
}
for (OutputTable output : dbMapData.getOutputTables()) {
List<DBMapperTableEntry> entries = output.getDBMapperTableEntries();
for (DBMapperTableEntry entry : entries) {
String expression = entry.getExpression();
if (expression != null && !"".equals(expression.trim())) {
//$NON-NLS-1$
//$NON-NLS-1$
int index = expression.lastIndexOf(".");
// at least "a.b"
if (index > 0) {
String connectionName = expression.substring(0, index);
if (oldValue.equals(connectionName)) {
entry.setExpression(newValue + expression.substring(index, expression.length()));
}
}
}
}
}
}
}
use of org.talend.designer.dbmap.model.emf.dbmap.DBMapData in project tdi-studio-se by Talend.
the class ELTMapSaveToEmfMigrationTask method execute.
/*
* (non-Javadoc)
*
* @see org.talend.core.model.migration.AbstractItemMigrationTask#execute(org.talend.core.model.properties.Item)
*/
@Override
public ExecutionResult execute(Item item) {
IProxyRepositoryFactory factory = CorePlugin.getDefault().getRepositoryService().getProxyRepositoryFactory();
ProcessType processType = getProcessType(item);
boolean modified = false;
if (processType != null) {
for (Object obj : processType.getNode()) {
NodeType nodeType = (NodeType) obj;
StringReader stringReader = null;
if (nodeType.getStringData() != null && !"".equals(nodeType.getStringData())) {
stringReader = new StringReader(nodeType.getStringData());
}
final String componentName = nodeType.getComponentName();
if (stringReader != null) {
if (componentName != null && componentName.startsWith("tELT") && componentName.endsWith("Map")) {
modified = true;
StringBuilder input = null;
Unmarshaller unmarshaller = new Unmarshaller(ExternalDbMapData.class);
unmarshaller.setWhitespacePreserve(true);
try {
BufferedReader r = new BufferedReader(stringReader);
input = new StringBuilder();
String line;
while ((line = r.readLine()) != null) {
input.append(line);
//$NON-NLS-0$
input.append("\r\n");
}
//$NON-NLS-0$ //$NON-NLS-1$
String buf = input.toString().replaceAll("<table-entries .*?>.*?</table-entries>", "");
stringReader.close();
stringReader = new StringReader(buf);
ExternalDbMapData externalData = (ExternalDbMapData) unmarshaller.unmarshal(stringReader);
DBMapData emfMapperData = DbmapFactory.eINSTANCE.createDBMapData();
DBMapHelper.saveDataToEmf(emfMapperData, externalData);
nodeType.setNodeData(emfMapperData);
nodeType.setStringData("");
} catch (MarshalException e) {
ExceptionHandler.process(e);
return ExecutionResult.FAILURE;
} catch (ValidationException e) {
ExceptionHandler.process(e);
return ExecutionResult.FAILURE;
} catch (IOException e) {
ExceptionHandler.process(e);
return ExecutionResult.FAILURE;
} finally {
if (stringReader != null) {
stringReader.close();
}
}
}
}
}
}
try {
if (modified) {
factory.save(item, true);
return ExecutionResult.SUCCESS_WITH_ALERT;
} else {
return ExecutionResult.SUCCESS_NO_ALERT;
}
} catch (Exception e) {
ExceptionHandler.process(e);
return ExecutionResult.FAILURE;
}
}
use of org.talend.designer.dbmap.model.emf.dbmap.DBMapData in project tdi-studio-se by Talend.
the class DbMapServiceTest method testUpdateEMFDBMapData.
@Test
public void testUpdateEMFDBMapData() {
DbMapService service = new DbMapService();
service.updateEMFDBMapData(nodeType, oldValue, newValue);
DBMapData data = (DBMapData) nodeType.getNodeData();
InputTable input = data.getInputTables().get(0);
assertEquals("context.schema.context.table", input.getName());
assertEquals("context.schema.context.table", input.getTableName());
OutputTable out = data.getOutputTables().get(0);
// output connection name should not be updated.
assertEquals("output", out.getName());
DBMapperTableEntry outEntry = out.getDBMapperTableEntries().get(0);
assertEquals("context.schema.context.table.column", outEntry.getExpression());
}
Aggregations