Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Datagraph change summary
Datagraph change summary [message #394612] Fri, 29 July 2005 10:34 Go to next message
Nicolas Tanghe is currently offline Nicolas Tanghe
Messages: 19
Registered: July 2009
Junior Member
Hello,

I use EMF/SDO and I have a problem with the change summary.

I initialize a EMF Object with a list of others EMF object (containment =
true). After that initialization, I make a beginLogin on the datagraph.
Then I add a children in my list and I want see this modification.

if (datagraph.getChangeSummary().isLogging()) {
datagraph.getChangeSummary().endLogging();
}
EChangeSummary summary = (EChangeSummary) ((DataGraph)
datagraph).getChangeSummary();

for (Iterator iter = summary.getObjectChanges().entrySet().iterator();
iter.hasNext();) {

Map.Entry entry = (Map.Entry) iter.next();
DataObject element = (DataObject) entry.getKey();

List oldValues = summary.getOldValues(element);

for (Iterator iterator = oldValues.iterator(); iterator.hasNext();) {

ChangeSummary.Setting change = (ChangeSummary.Setting) iterator
.next();
Property p = change.getProperty();
System.out.println("\tProperty " + p.getName() + ": "
+ change.getValue() + " => " + element.get(p));

There, no problem, the change summary see the added children, it's good.
Example, I have : Property list : [object 1,object 2] -> [object 1,object
2, Object 3]

I do a new beginLogging on the datagraph for see the new changes on the
"new" datagraph and now I delete one element in the list.
I return in the method :

if (datagraph.getChangeSummary().isLogging()) {
datagraph.getChangeSummary().endLogging();
}
EChangeSummary summary = (EChangeSummary) ((DataGraph)
datagraph).getChangeSummary();

for (Iterator iter = summary.getObjectChanges().entrySet().iterator();
iter.hasNext();) {

Map.Entry entry = (Map.Entry) iter.next();
DataObject element = (DataObject) entry.getKey();

List oldValues = summary.getOldValues(element);

for (Iterator iterator = oldValues.iterator(); iterator.hasNext();) {

ChangeSummary.Setting change = (ChangeSummary.Setting) iterator
.next();
Property p = change.getProperty();
System.out.println("\tProperty " + p.getName() + ": "
+ change.getValue() + " => " + element.get(p));


But, in this case, my ChangeSummary.Setting change is null, it don't see
the "old" list of children and I don't see my modifications in the list...

Property list : [] -> [object 1,object 2]

Someone body have the same problem ??
Help me please...

Nicolas
Re: Datagraph change summary [message #394639 is a reply to message #394612] Tue, 02 August 2005 02:51 Go to previous messageGo to next message
Nicolas Tanghe is currently offline Nicolas Tanghe
Messages: 19
Registered: July 2009
Junior Member
Hello,

I think that I find the origin of my problem. It's de method : public List
getOldValues(DataObject dataObject) in package
org.eclipse.emf.ecore.sdo.impl.EchangeSummaryImpl.
Before, in a older version of EMF-SDO, the code of this method were :

public List getOldValues(DataObject dataObject)
{
return (List)getObjectChanges().get(dataObject);
}

And with this code, I have no problem, my code works fine...
Now, in the latest version, the code of this method is :

public List getOldValues(DataObject dataObject)
{
List sdoSettings = (List)cachedSDOObjectChanges.get(dataObject);
if (sdoSettings != null)
{
return sdoSettings;
}
List settings = (List)getObjectChanges().get(dataObject);
// TODO it is possible that settings is null, should we create empty
list then?
// TODO declaring serialVersionUID?
for (int i = 0; i < settings.size(); i++)
{
FeatureChange change = (FeatureChange)settings.get(i);
EStructuralFeature feature = change.getFeature();
if (FeatureMapUtil.isFeatureMap(feature))
{
final List values = (List)change.getValue();
if (sdoSettings == null)
{
sdoSettings = new BasicEList(settings);
}
DelegatingFeatureMap featureMap = new
DelegatingFeatureMap(((InternalEObject)dataObject), feature)
{
protected final List theList = values;

protected List delegateList()
{
return theList;
}
};

// create new settings and replace the setting for mixed feature
sdoSettings.set(i,
SDOFactory.eINSTANCE.createEChangeSummarySetting(feature, new
BasicESequence(featureMap), change.isSet()));
// add all derived features
for (int k = 0; k < featureMap.size(); k++)
{
EStructuralFeature f = featureMap.getEStructuralFeature(k);

sdoSettings.add(SDOFactory.eINSTANCE.createEChangeSummarySet ting(f,
featureMap.get(f, false), true));
}
}
}
sdoSettings = (sdoSettings != null) ? sdoSettings : settings;
cachedSDOObjectChanges.put(dataObject, sdoSettings);
return sdoSettings;
}

I observe that there is a "cache" : cachedSDOObjectChanges (but I don't
good understand how it's works). The first time, sdoSettings is null and
the method use (List)getObjectChanges().get(dataObject) and thus It's
works fine. But in a second time, the cache is not empty and the method
use List sdoSettings = (List)cachedSDOObjectChanges.get(dataObject) and
there, it's not good for me...

But It is a bug, a feature ? How use the new public List
getOldValues(DataObject dataObject) method ?

Someone can help me, please ?

Thanks,
Nicolas
Re: Datagraph change summary [message #394720 is a reply to message #394639] Tue, 02 August 2005 11:27 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 25945
Registered: July 2009
Senior Member
Nicolas,

It's hard to know if there's a bug here or not. It certainly doesn't
sound so good. Could you provide a complete test case (one that I can
run myself locally) that illustrates the problem?


Nicolas wrote:

> Hello,
>
> I think that I find the origin of my problem. It's de method : public
> List getOldValues(DataObject dataObject) in package
> org.eclipse.emf.ecore.sdo.impl.EchangeSummaryImpl.
> Before, in a older version of EMF-SDO, the code of this method were :
> public List getOldValues(DataObject dataObject)
> {
> return (List)getObjectChanges().get(dataObject);
> }
>
> And with this code, I have no problem, my code works fine...
> Now, in the latest version, the code of this method is :
> public List getOldValues(DataObject dataObject)
> {
> List sdoSettings = (List)cachedSDOObjectChanges.get(dataObject);
> if (sdoSettings != null)
> {
> return sdoSettings;
> }
> List settings = (List)getObjectChanges().get(dataObject);
> // TODO it is possible that settings is null, should we create
> empty list then? // TODO declaring serialVersionUID?
> for (int i = 0; i < settings.size(); i++)
> {
> FeatureChange change = (FeatureChange)settings.get(i);
> EStructuralFeature feature = change.getFeature();
> if (FeatureMapUtil.isFeatureMap(feature))
> {
> final List values = (List)change.getValue();
> if (sdoSettings == null)
> {
> sdoSettings = new BasicEList(settings);
> }
> DelegatingFeatureMap featureMap = new
> DelegatingFeatureMap(((InternalEObject)dataObject), feature)
> {
> protected final List theList = values;
>
> protected List delegateList()
> {
> return theList;
> }
> };
>
> // create new settings and replace the setting for mixed feature
> sdoSettings.set(i,
> SDOFactory.eINSTANCE.createEChangeSummarySetting(feature, new
> BasicESequence(featureMap), change.isSet()));
> // add all derived features
> for (int k = 0; k < featureMap.size(); k++)
> {
> EStructuralFeature f = featureMap.getEStructuralFeature(k);
>
> sdoSettings.add(SDOFactory.eINSTANCE.createEChangeSummarySet ting(f,
> featureMap.get(f, false), true));
> }
> }
> }
> sdoSettings = (sdoSettings != null) ? sdoSettings : settings;
> cachedSDOObjectChanges.put(dataObject, sdoSettings);
> return sdoSettings;
> }
>
> I observe that there is a "cache" : cachedSDOObjectChanges (but I
> don't good understand how it's works). The first time, sdoSettings is
> null and the method use (List)getObjectChanges().get(dataObject) and
> thus It's works fine. But in a second time, the cache is not empty and
> the method use List sdoSettings =
> (List)cachedSDOObjectChanges.get(dataObject) and there, it's not good
> for me...
>
> But It is a bug, a feature ? How use the new public List
> getOldValues(DataObject dataObject) method ?
>
> Someone can help me, please ?
>
> Thanks,
> Nicolas
>
Re: Datagraph change summary [message #394771 is a reply to message #394720] Wed, 03 August 2005 09:45 Go to previous messageGo to next message
Nicolas Tanghe is currently offline Nicolas Tanghe
Messages: 19
Registered: July 2009
Junior Member
Hello Ed,

I give you a complete class that illustrates my problem with an another
example... This class works locally, you can simply make a cut and paste.

Initially, I have a employee (Boss) wich have two employees (A and B).
I begin the logging and I add a employee C and I remove the employee A.

My datagraph is :

<?xml version="1.0" encoding="UTF-8"?>
<sdo:datagraph xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:company="http://com.example.company.ecore"
xmlns:sdo="commonj.sdo"
xmlns:sdo_1="http://www.eclipse.org/emf/2003/SDO">
<changeSummary xmlns="">
<objectChanges key="#//@eRootObject">
<value xsi:type="sdo_1:EChangeSummarySetting"
featureName="employees">
<listChanges index="0"
referenceValues="#//@eChangeSummary/@objectsToAttach.0"/>
<listChanges kind="REMOVE" index="2"/>
</value>
</objectChanges>
<objectsToAttach xsi:type="company:Employee" name="A"/>
</changeSummary>
<company:Employee name="Boss">
<employees name="B"/>
<employees name="C"/>
</company:Employee>
</sdo:datagraph>

TO UPDATE:
Property employees:
Old value
Name: A
Name: B
=>
New value
Name: B
Name: C

Ok, It's works fine !! Now, I begin the logging and I remove the employee C

My datagraph is :

<?xml version="1.0" encoding="UTF-8"?>
<sdo:datagraph xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:company="http://com.example.company.ecore"
xmlns:sdo="commonj.sdo"
xmlns:sdo_1="http://www.eclipse.org/emf/2003/SDO">
<changeSummary xmlns="">
<objectChanges key="#//@eRootObject">
<value xsi:type="sdo_1:EChangeSummarySetting"
featureName="employees">
<listChanges index="1"
referenceValues="#//@eChangeSummary/@objectsToAttach.0"/>
</value>
</objectChanges>
<objectsToAttach xsi:type="company:Employee" name="C"/>
</changeSummary>
<company:Employee name="Boss">
<employees name="B"/>
</company:Employee>
</sdo:datagraph>

TO UPDATE:
Property employees:
Old value
Name: A
Name: B
=>
New value
Name: B


And there, it's not good, my old value is A B and this must be B C ! (but
the change summary seem good ).
If I change the call to summary.getOldValues(element) by
summary.getObjectChanges().get(element) (wich is the body of the method
getOldValues in a older version of EMF, in the latest version this
function use also a cache), it's works fine, my Old value is B C...

Bug ?

Thanks,
Nicolas



//////////////////////////////////////////////////////////// ///////////////

public class TestGetOldValues {

protected EClass employeeClass;

protected EAttribute employeeNameFeature;

protected EReference employeeEmployeesFeature;

public TestGetOldValues() {
initializeEmployeeDataGraphModel();
}

protected void initializeEmployeeDataGraphModel() {
EcoreFactory ecoreFactory = EcoreFactory.eINSTANCE;
EcorePackage ecorePackage = EcorePackage.eINSTANCE;

employeeClass = ecoreFactory.createEClass();
employeeClass.setName("Employee");

// name
employeeNameFeature = ecoreFactory.createEAttribute();
employeeNameFeature.setName("name");
employeeNameFeature.setEType(ecorePackage.getEString());
employeeClass.getEStructuralFeatures().add(employeeNameFeatu re);

// employees (that the employee manages)
employeeEmployeesFeature = ecoreFactory.createEReference();
employeeEmployeesFeature.setName("employees");
employeeEmployeesFeature.setEType(employeeClass);
employeeEmployeesFeature
.setUpperBound(EStructuralFeature.UNBOUNDED_MULTIPLICITY);
employeeEmployeesFeature.setContainment(true); // must be true so that
// nested employees will
// be in the graph
employeeClass.getEStructuralFeatures().add(employeeEmployees Feature);

EPackage employeePackage = ecoreFactory.createEPackage();
employeePackage.setName("company");
employeePackage.setNsPrefix("company");
employeePackage.setNsURI("http://com.example.company.ecore");
employeePackage.getEClassifiers().add(employeeClass);

// Have the factory for this package build SDO Objects
employeePackage
.setEFactoryInstance(new DynamicEDataObjectImpl.FactoryImpl());
}

public EObject createDataObject(String name) {
EObject eObject = EcoreUtil.create(employeeClass);
// Note: we could cast the object to DataObject, but chose to use
// EObject APIs instead.
eObject.eSet(employeeNameFeature, name);
return eObject;
}

// Give a dataGraph with a Employee (Boss) wich have two employees (A and
B)
// and begin the logging

public DataGraph getInitDataGraph() {

initializeEmployeeDataGraphModel();

EDataGraph employeeGraph = SDOFactory.eINSTANCE.createEDataGraph();

EObject rootObject = null;

EObject boss = createDataObject("Boss");
EObject A = createDataObject("A");
((List) boss.eGet(employeeEmployeesFeature)).add(A);
EObject B = createDataObject("B");
((List) boss.eGet(employeeEmployeesFeature)).add(B);

rootObject = boss;

if (rootObject != null) {
employeeGraph.setERootObject(rootObject);
}

// Call beginLogging() so that the Change Summary is populated when
// changes are made to the Data Graph.
// The DMS should call beginLogging() and endLogging(), not the client.
employeeGraph.getChangeSummary().beginLogging();

return employeeGraph;
}

public DataGraph saveUpdate(DataGraph datagraph) throws Exception {

EChangeSummary summary = (EChangeSummary) ((DataGraph) datagraph)
.getChangeSummary();

if (summary.isLogging()) {
summary.endLogging();
}

System.out.println("\nTO UPDATE:");

for (Iterator iter = summary.getObjectChanges().entrySet().iterator();
iter
.hasNext();) {

Map.Entry entry = (Map.Entry) iter.next();
DataObject element = (DataObject) entry.getKey();

if (summary.isCreated(element)) {
System.out.println("created: " + element);
System.out.println("\n");

} else if (summary.isDeleted(element)) {
System.out.println("deleted: " + element);
System.out.println("\n");
} else {

List oldValues = summary.getOldValues(element);
//List oldValues = (List) summary.getObjectChanges().get(element);

for (Iterator iterator = oldValues.iterator(); iterator
.hasNext();) {

ChangeSummary.Setting change = (ChangeSummary.Setting) iterator
.next();
Property p = change.getProperty();

// We wath the list of employee
if (p.getName().equals("employees")) {
System.out.println("\tProperty " + p.getName() + ": ");
// System.out.println(change.getValue());
System.out.println("Old value ");
for (Iterator iterator2 = ((List) change.getValue())
.iterator(); iterator2.hasNext();) {
DataObject empl = (DataObject) iterator2.next();
System.out.println("Name: "
+ empl.getString("name"));

}
System.out.println(" => ");

System.out.println("New value ");
for (Iterator iterator3 = ((List) element.get(p))
.iterator(); iterator3.hasNext();) {
DataObject empl = (DataObject) iterator3.next();
System.out.println("Name: "
+ empl.getString("name"));

}

}

}

}

}

return datagraph;

}

public void testChanges() {

DataGraph graph = getInitDataGraph();

EObject boss = (EObject) graph.getRootObject();

// add a employee C and remove employee A
EObject C = createDataObject("C");
((List) boss.eGet(employeeEmployeesFeature)).add(C);

((List) boss.eGet(employeeEmployeesFeature)).remove(0);

try {
((EDataGraph) graph).getDataGraphResource().save(System.out, null);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}

try {
saveUpdate(graph);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

// I make a new beginLogging
graph.getChangeSummary().beginLogging();


//I remove employee C
((List) boss.eGet(employeeEmployeesFeature)).remove(1);

try {
((EDataGraph) graph).getDataGraphResource().save(System.out, null);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}

try {
saveUpdate(graph);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}


}

public static void main(String[] args) {

TestGetOldValues test = new TestGetOldValues();

test.testChanges();

}

}

//////////////////////////////////////////////////////////// ///////////
Re: Datagraph change summary [message #394790 is a reply to message #394771] Wed, 03 August 2005 14:04 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 25945
Registered: July 2009
Senior Member
Nicolas,

Marcelo will look into the problem. Thanks for the test case!


Nicolas Tanghe wrote:

> Hello Ed,
>
> I give you a complete class that illustrates my problem with an
> another example... This class works locally, you can simply make a cut
> and paste.
>
> Initially, I have a employee (Boss) wich have two employees (A and B).
> I begin the logging and I add a employee C and I remove the employee A.
>
> My datagraph is :
>
> <?xml version="1.0" encoding="UTF-8"?>
> <sdo:datagraph xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:company="http://com.example.company.ecore"
> xmlns:sdo="commonj.sdo"
> xmlns:sdo_1="http://www.eclipse.org/emf/2003/SDO">
> <changeSummary xmlns="">
> <objectChanges key="#//@eRootObject">
> <value xsi:type="sdo_1:EChangeSummarySetting"
> featureName="employees">
> <listChanges index="0"
> referenceValues="#//@eChangeSummary/@objectsToAttach.0"/>
> <listChanges kind="REMOVE" index="2"/>
> </value>
> </objectChanges>
> <objectsToAttach xsi:type="company:Employee" name="A"/>
> </changeSummary>
> <company:Employee name="Boss">
> <employees name="B"/>
> <employees name="C"/>
> </company:Employee>
> </sdo:datagraph>
>
> TO UPDATE:
> Property employees: Old value Name: A
> Name: B
> => New value Name: B
> Name: C
>
> Ok, It's works fine !! Now, I begin the logging and I remove the
> employee C
>
> My datagraph is :
>
> <?xml version="1.0" encoding="UTF-8"?>
> <sdo:datagraph xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:company="http://com.example.company.ecore"
> xmlns:sdo="commonj.sdo"
> xmlns:sdo_1="http://www.eclipse.org/emf/2003/SDO">
> <changeSummary xmlns="">
> <objectChanges key="#//@eRootObject">
> <value xsi:type="sdo_1:EChangeSummarySetting"
> featureName="employees">
> <listChanges index="1"
> referenceValues="#//@eChangeSummary/@objectsToAttach.0"/>
> </value>
> </objectChanges>
> <objectsToAttach xsi:type="company:Employee" name="C"/>
> </changeSummary>
> <company:Employee name="Boss">
> <employees name="B"/>
> </company:Employee>
> </sdo:datagraph>
>
> TO UPDATE:
> Property employees: Old value Name: A
> Name: B
> => New value Name: B
>
>
> And there, it's not good, my old value is A B and this must be B C !
> (but the change summary seem good ).
> If I change the call to summary.getOldValues(element) by
> summary.getObjectChanges().get(element) (wich is the body of the
> method getOldValues in a older version of EMF, in the latest version
> this function use also a cache), it's works fine, my Old value is B C...
>
> Bug ?
>
> Thanks,
> Nicolas
>
>
>
> //////////////////////////////////////////////////////////// ///////////////
>
>
> public class TestGetOldValues {
>
> protected EClass employeeClass;
>
> protected EAttribute employeeNameFeature;
>
> protected EReference employeeEmployeesFeature;
>
> public TestGetOldValues() {
> initializeEmployeeDataGraphModel();
> }
>
> protected void initializeEmployeeDataGraphModel() {
> EcoreFactory ecoreFactory = EcoreFactory.eINSTANCE;
> EcorePackage ecorePackage = EcorePackage.eINSTANCE;
>
> employeeClass = ecoreFactory.createEClass();
> employeeClass.setName("Employee");
>
> // name
> employeeNameFeature = ecoreFactory.createEAttribute();
> employeeNameFeature.setName("name");
> employeeNameFeature.setEType(ecorePackage.getEString());
> employeeClass.getEStructuralFeatures().add(employeeNameFeatu re);
>
> // employees (that the employee manages)
> employeeEmployeesFeature = ecoreFactory.createEReference();
> employeeEmployeesFeature.setName("employees");
> employeeEmployeesFeature.setEType(employeeClass);
> employeeEmployeesFeature
>
> .setUpperBound(EStructuralFeature.UNBOUNDED_MULTIPLICITY);
> employeeEmployeesFeature.setContainment(true); // must be true
> so that
> // nested employees will
> // be in the graph
>
> employeeClass.getEStructuralFeatures().add(employeeEmployees Feature);
>
> EPackage employeePackage = ecoreFactory.createEPackage();
> employeePackage.setName("company");
> employeePackage.setNsPrefix("company");
> employeePackage.setNsURI("http://com.example.company.ecore");
> employeePackage.getEClassifiers().add(employeeClass);
>
> // Have the factory for this package build SDO Objects
> employeePackage
> .setEFactoryInstance(new
> DynamicEDataObjectImpl.FactoryImpl());
> }
>
> public EObject createDataObject(String name) {
> EObject eObject = EcoreUtil.create(employeeClass);
> // Note: we could cast the object to DataObject, but chose to use
> // EObject APIs instead.
> eObject.eSet(employeeNameFeature, name);
> return eObject;
> }
>
> // Give a dataGraph with a Employee (Boss) wich have two employees
> (A and B)
> // and begin the logging
>
> public DataGraph getInitDataGraph() {
>
> initializeEmployeeDataGraphModel();
>
> EDataGraph employeeGraph =
> SDOFactory.eINSTANCE.createEDataGraph();
>
> EObject rootObject = null;
>
> EObject boss = createDataObject("Boss");
> EObject A = createDataObject("A");
> ((List) boss.eGet(employeeEmployeesFeature)).add(A);
> EObject B = createDataObject("B");
> ((List) boss.eGet(employeeEmployeesFeature)).add(B);
>
> rootObject = boss;
>
> if (rootObject != null) {
> employeeGraph.setERootObject(rootObject);
> }
>
> // Call beginLogging() so that the Change Summary is populated
> when
> // changes are made to the Data Graph.
> // The DMS should call beginLogging() and endLogging(), not
> the client.
> employeeGraph.getChangeSummary().beginLogging();
>
> return employeeGraph;
> }
>
> public DataGraph saveUpdate(DataGraph datagraph) throws Exception {
>
> EChangeSummary summary = (EChangeSummary) ((DataGraph) datagraph)
> .getChangeSummary();
>
> if (summary.isLogging()) {
> summary.endLogging();
> }
>
> System.out.println("\nTO UPDATE:");
>
> for (Iterator iter =
> summary.getObjectChanges().entrySet().iterator(); iter
> .hasNext();) {
>
> Map.Entry entry = (Map.Entry) iter.next();
> DataObject element = (DataObject) entry.getKey();
>
> if (summary.isCreated(element)) {
> System.out.println("created: " + element);
> System.out.println("\n");
>
> } else if (summary.isDeleted(element)) {
> System.out.println("deleted: " + element);
> System.out.println("\n");
> } else {
>
> List oldValues = summary.getOldValues(element);
> //List oldValues = (List)
> summary.getObjectChanges().get(element);
>
> for (Iterator iterator = oldValues.iterator(); iterator
> .hasNext();) {
>
> ChangeSummary.Setting change =
> (ChangeSummary.Setting) iterator
> .next();
> Property p = change.getProperty();
>
> // We wath the list of employee
> if (p.getName().equals("employees")) {
> System.out.println("\tProperty " + p.getName()
> + ": ");
> // System.out.println(change.getValue());
> System.out.println("Old value ");
> for (Iterator iterator2 = ((List)
> change.getValue())
> .iterator(); iterator2.hasNext();) {
> DataObject empl = (DataObject)
> iterator2.next();
> System.out.println("Name: "
> + empl.getString("name"));
>
> }
> System.out.println(" => ");
>
> System.out.println("New value ");
> for (Iterator iterator3 = ((List) element.get(p))
> .iterator(); iterator3.hasNext();) {
> DataObject empl = (DataObject)
> iterator3.next();
> System.out.println("Name: "
> + empl.getString("name"));
>
> }
>
> }
>
> }
>
> }
>
> }
>
> return datagraph;
>
> }
>
> public void testChanges() {
>
> DataGraph graph = getInitDataGraph();
>
> EObject boss = (EObject) graph.getRootObject();
>
> // add a employee C and remove employee A
> EObject C = createDataObject("C");
> ((List) boss.eGet(employeeEmployeesFeature)).add(C);
>
> ((List) boss.eGet(employeeEmployeesFeature)).remove(0);
>
> try {
> ((EDataGraph)
> graph).getDataGraphResource().save(System.out, null);
> } catch (IOException e1) {
> // TODO Auto-generated catch block
> e1.printStackTrace();
> }
>
> try {
> saveUpdate(graph);
> } catch (Exception e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> }
>
> // I make a new beginLogging
> graph.getChangeSummary().beginLogging();
>
>
> //I remove employee C
> ((List) boss.eGet(employeeEmployeesFeature)).remove(1);
>
> try {
> ((EDataGraph)
> graph).getDataGraphResource().save(System.out, null);
> } catch (IOException e1) {
> // TODO Auto-generated catch block
> e1.printStackTrace();
> }
>
> try {
> saveUpdate(graph);
> } catch (Exception e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> }
>
>
> }
>
> public static void main(String[] args) {
>
> TestGetOldValues test = new TestGetOldValues();
>
> test.testChanges();
>
> }
>
> }
>
> //////////////////////////////////////////////////////////// ///////////
>
Re: Datagraph change summary [message #394809 is a reply to message #394790] Thu, 04 August 2005 01:41 Go to previous messageGo to next message
Marcelo Paternostro is currently offline Marcelo Paternostro
Messages: 602
Registered: July 2009
Senior Member
Hi Nicolas,

I believe this is a bug. The cachedSDOObjectChanges should probably be
cleared when you begin recording and when the changes are consolidated.

Can you please open a bugzilla?

Cheers,
Marcelo

Ed Merks wrote:
> Nicolas,
>
> Marcelo will look into the problem. Thanks for the test case!
>
>
> Nicolas Tanghe wrote:
>
>> Hello Ed,
>>
>> I give you a complete class that illustrates my problem with an
>> another example... This class works locally, you can simply make a cut
>> and paste.
>>
>> Initially, I have a employee (Boss) wich have two employees (A and B).
>> I begin the logging and I add a employee C and I remove the employee A.
>>
>> My datagraph is :
>>
>> <?xml version="1.0" encoding="UTF-8"?>
>> <sdo:datagraph xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>> xmlns:company="http://com.example.company.ecore"
>> xmlns:sdo="commonj.sdo"
>> xmlns:sdo_1="http://www.eclipse.org/emf/2003/SDO">
>> <changeSummary xmlns="">
>> <objectChanges key="#//@eRootObject">
>> <value xsi:type="sdo_1:EChangeSummarySetting"
>> featureName="employees">
>> <listChanges index="0"
>> referenceValues="#//@eChangeSummary/@objectsToAttach.0"/>
>> <listChanges kind="REMOVE" index="2"/>
>> </value>
>> </objectChanges>
>> <objectsToAttach xsi:type="company:Employee" name="A"/>
>> </changeSummary>
>> <company:Employee name="Boss">
>> <employees name="B"/>
>> <employees name="C"/>
>> </company:Employee>
>> </sdo:datagraph>
>>
>> TO UPDATE:
>> Property employees: Old value Name: A
>> Name: B
>> => New value Name: B
>> Name: C
>>
>> Ok, It's works fine !! Now, I begin the logging and I remove the
>> employee C
>>
>> My datagraph is :
>>
>> <?xml version="1.0" encoding="UTF-8"?>
>> <sdo:datagraph xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>> xmlns:company="http://com.example.company.ecore"
>> xmlns:sdo="commonj.sdo"
>> xmlns:sdo_1="http://www.eclipse.org/emf/2003/SDO">
>> <changeSummary xmlns="">
>> <objectChanges key="#//@eRootObject">
>> <value xsi:type="sdo_1:EChangeSummarySetting"
>> featureName="employees">
>> <listChanges index="1"
>> referenceValues="#//@eChangeSummary/@objectsToAttach.0"/>
>> </value>
>> </objectChanges>
>> <objectsToAttach xsi:type="company:Employee" name="C"/>
>> </changeSummary>
>> <company:Employee name="Boss">
>> <employees name="B"/>
>> </company:Employee>
>> </sdo:datagraph>
>>
>> TO UPDATE:
>> Property employees: Old value Name: A
>> Name: B
>> => New value Name: B
>>
>>
>> And there, it's not good, my old value is A B and this must be B C !
>> (but the change summary seem good ).
>> If I change the call to summary.getOldValues(element) by
>> summary.getObjectChanges().get(element) (wich is the body of the
>> method getOldValues in a older version of EMF, in the latest version
>> this function use also a cache), it's works fine, my Old value is B C...
>>
>> Bug ?
>>
>> Thanks,
>> Nicolas
>>
>>
>>
>> //////////////////////////////////////////////////////////// ///////////////
>>
>>
>> public class TestGetOldValues {
>>
>> protected EClass employeeClass;
>>
>> protected EAttribute employeeNameFeature;
>>
>> protected EReference employeeEmployeesFeature;
>>
>> public TestGetOldValues() {
>> initializeEmployeeDataGraphModel();
>> }
>>
>> protected void initializeEmployeeDataGraphModel() {
>> EcoreFactory ecoreFactory = EcoreFactory.eINSTANCE;
>> EcorePackage ecorePackage = EcorePackage.eINSTANCE;
>>
>> employeeClass = ecoreFactory.createEClass();
>> employeeClass.setName("Employee");
>>
>> // name
>> employeeNameFeature = ecoreFactory.createEAttribute();
>> employeeNameFeature.setName("name");
>> employeeNameFeature.setEType(ecorePackage.getEString());
>> employeeClass.getEStructuralFeatures().add(employeeNameFeatu re);
>>
>> // employees (that the employee manages)
>> employeeEmployeesFeature = ecoreFactory.createEReference();
>> employeeEmployeesFeature.setName("employees");
>> employeeEmployeesFeature.setEType(employeeClass);
>> employeeEmployeesFeature
>>
>> .setUpperBound(EStructuralFeature.UNBOUNDED_MULTIPLICITY);
>> employeeEmployeesFeature.setContainment(true); // must be true
>> so that
>> // nested employees will
>> // be in the graph
>>
>> employeeClass.getEStructuralFeatures().add(employeeEmployees Feature);
>>
>> EPackage employeePackage = ecoreFactory.createEPackage();
>> employeePackage.setName("company");
>> employeePackage.setNsPrefix("company");
>> employeePackage.setNsURI("http://com.example.company.ecore");
>> employeePackage.getEClassifiers().add(employeeClass);
>>
>> // Have the factory for this package build SDO Objects
>> employeePackage
>> .setEFactoryInstance(new
>> DynamicEDataObjectImpl.FactoryImpl());
>> }
>>
>> public EObject createDataObject(String name) {
>> EObject eObject = EcoreUtil.create(employeeClass);
>> // Note: we could cast the object to DataObject, but chose to use
>> // EObject APIs instead.
>> eObject.eSet(employeeNameFeature, name);
>> return eObject;
>> }
>>
>> // Give a dataGraph with a Employee (Boss) wich have two employees
>> (A and B)
>> // and begin the logging
>>
>> public DataGraph getInitDataGraph() {
>>
>> initializeEmployeeDataGraphModel();
>>
>> EDataGraph employeeGraph =
>> SDOFactory.eINSTANCE.createEDataGraph();
>>
>> EObject rootObject = null;
>>
>> EObject boss = createDataObject("Boss");
>> EObject A = createDataObject("A");
>> ((List) boss.eGet(employeeEmployeesFeature)).add(A);
>> EObject B = createDataObject("B");
>> ((List) boss.eGet(employeeEmployeesFeature)).add(B);
>>
>> rootObject = boss;
>>
>> if (rootObject != null) {
>> employeeGraph.setERootObject(rootObject);
>> }
>>
>> // Call beginLogging() so that the Change Summary is populated
>> when
>> // changes are made to the Data Graph.
>> // The DMS should call beginLogging() and endLogging(), not
>> the client.
>> employeeGraph.getChangeSummary().beginLogging();
>>
>> return employeeGraph;
>> }
>>
>> public DataGraph saveUpdate(DataGraph datagraph) throws Exception {
>>
>> EChangeSummary summary = (EChangeSummary) ((DataGraph) datagraph)
>> .getChangeSummary();
>>
>> if (summary.isLogging()) {
>> summary.endLogging();
>> }
>>
>> System.out.println("\nTO UPDATE:");
>>
>> for (Iterator iter =
>> summary.getObjectChanges().entrySet().iterator(); iter
>> .hasNext();) {
>>
>> Map.Entry entry = (Map.Entry) iter.next();
>> DataObject element = (DataObject) entry.getKey();
>>
>> if (summary.isCreated(element)) {
>> System.out.println("created: " + element);
>> System.out.println("\n");
>>
>> } else if (summary.isDeleted(element)) {
>> System.out.println("deleted: " + element);
>> System.out.println("\n");
>> } else {
>>
>> List oldValues = summary.getOldValues(element);
>> //List oldValues = (List)
>> summary.getObjectChanges().get(element);
>>
>> for (Iterator iterator = oldValues.iterator(); iterator
>> .hasNext();) {
>>
>> ChangeSummary.Setting change =
>> (ChangeSummary.Setting) iterator
>> .next();
>> Property p = change.getProperty();
>>
>> // We wath the list of employee
>> if (p.getName().equals("employees")) {
>> System.out.println("\tProperty " + p.getName()
>> + ": ");
>> // System.out.println(change.getValue());
>> System.out.println("Old value ");
>> for (Iterator iterator2 = ((List)
>> change.getValue())
>> .iterator(); iterator2.hasNext();) {
>> DataObject empl = (DataObject)
>> iterator2.next();
>> System.out.println("Name: "
>> + empl.getString("name"));
>>
>> }
>> System.out.println(" => ");
>> System.out.println("New
>> value ");
>> for (Iterator iterator3 = ((List) element.get(p))
>> .iterator(); iterator3.hasNext();) {
>> DataObject empl = (DataObject)
>> iterator3.next();
>> System.out.println("Name: "
>> + empl.getString("name"));
>>
>> }
>>
>> }
>>
>> }
>>
>> }
>>
>> }
>>
>> return datagraph;
>>
>> }
>>
>> public void testChanges() {
>>
>> DataGraph graph = getInitDataGraph();
>>
>> EObject boss = (EObject) graph.getRootObject();
>>
>> // add a employee C and remove employee A
>> EObject C = createDataObject("C");
>> ((List) boss.eGet(employeeEmployeesFeature)).add(C);
>>
>> ((List) boss.eGet(employeeEmployeesFeature)).remove(0);
>>
>> try {
>> ((EDataGraph)
>> graph).getDataGraphResource().save(System.out, null);
>> } catch (IOException e1) {
>> // TODO Auto-generated catch block
>> e1.printStackTrace();
>> }
>>
>> try {
>> saveUpdate(graph);
>> } catch (Exception e) {
>> // TODO Auto-generated catch block
>> e.printStackTrace();
>> }
>> // I make a new beginLogging
>> graph.getChangeSummary().beginLogging();
>> //I remove employee C
>> ((List) boss.eGet(employeeEmployeesFeature)).remove(1);
>> try {
>> ((EDataGraph)
>> graph).getDataGraphResource().save(System.out, null);
>> } catch (IOException e1) {
>> // TODO Auto-generated catch block
>> e1.printStackTrace();
>> }
>>
>> try {
>> saveUpdate(graph);
>> } catch (Exception e) {
>> // TODO Auto-generated catch block
>> e.printStackTrace();
>> }
>>
>> }
>>
>> public static void main(String[] args) {
>>
>> TestGetOldValues test = new TestGetOldValues();
>>
>> test.testChanges();
>>
>> }
>>
>> }
>>
>> //////////////////////////////////////////////////////////// ///////////
>>
Re: Datagraph change summary [message #394829 is a reply to message #394809] Thu, 04 August 2005 10:23 Go to previous message
Nicolas Tanghe is currently offline Nicolas Tanghe
Messages: 19
Registered: July 2009
Junior Member
Hi Marcelo,

A bugzilla is open...

Cheers,

Nicolas
Previous Topic:Generate the error code from EMF project
Next Topic:Validator
Goto Forum:
  


Current Time: Wed Jul 30 11:19:37 EDT 2014

Powered by FUDForum. Page generated in 0.06755 seconds