我有两个基于相同ecore模型的EMF实例版本。我需要以下面的格式准备一个从v1更改为v2的事情列表
对于模型对象名称中的每个对象:修改的属性:添加的属性:删除的属性:
每个emf实例文件实际上都是DB数据的表示。用户不会直接更改DB,但他们会更改emf实例文件。该工具需要标识这些更改,然后需要生成必要的DML语句。如果可以给出一个伪代码来说明如何实现这一点,或者是否有更好的选择。下面是我目前的代码
public Comparison compare()
{
// Load the two input models
ResourceSet resourceSet1 = new ResourceSetImpl();
ResourceSet resourceSet2 = new ResourceSetImpl();
String xmi1 = "src/test/java/com/equifax/ic/provisioning/service/v1.xmi";
String xmi2 = "src/test/java/com/equifax/ic/provisioning/service/v2.xmi";
load(xmi1, resourceSet1);
load(xmi2, resourceSet2);
// Configure EMF Compare
EMFCompare comparator = EMFCompare.builder().build();
// Compare the two models
IComparisonScope scope = EMFCompare.createDefaultScope(resourceSet1, resourceSet2);
return comparator.compare(scope);
}
@Test
public void testCompare()
{
Comparison comparison = compare();
List<Diff> differences = comparison.getDifferences();
for(Diff d: differences)
{
System.err.println("d.getKind(): "+d.getKind());
System.err.println("d.getMatch(): " + d.getMatch());
System.err.println("State: " + d.getState());
}
assertSame(Integer.valueOf(12), Integer.valueOf(differences.size()));
}输出
d.getKind(): ADD
d.getMatch(): MatchSpec{left=BillableSystemEvent@1b5340c Application Processed, right=BillableSystemEvent@16c163f Application Processed, origin=<null>, #differences=2, #submatches=2}
State: UNRESOLVED
d.getKind(): DELETE
d.getMatch(): MatchSpec{left=BillableSystemEvent@1b5340c Application Processed, right=BillableSystemEvent@16c163f Application Processed, origin=<null>, #differences=2, #submatches=2}
State: UNRESOLVED发布于 2013-04-15 07:54:06
我不能说我真的理解你想要达到的所有目标,但正如我所理解的,你并不真正感兴趣的是EMF比较使用的格式,因为它的不同。相反,您正试图为差异生成一种不同的表示。
您可能对重新实现IDiffProcessor感兴趣。每次检测到更改时,都会通知Diff处理器。默认情况下,我们创建"Diff“实例..。没有什么可以阻止您生成DML语句。您可以快速了解IDiffProcessor API 这里。
https://stackoverflow.com/questions/15883154
复制相似问题