Hello,
I am making an evaluation of Cayenne and other frameworks.
One of my test is the following :
begin a set of operations
make a select * on one table
insert new element in that table
make another select * on that table (see that new element along with
the previous results)
rollback
make another select * on that table (see that it came back to it's
original state)
I am using the following code :
ObjectContext context1 = DataContext.createDataContext();
SelectQuery querySelectAll = new SelectQuery(Principal.class);
System.out.println("-test pre");
for (Object out : context1.performQuery(querySelectAll)) {
System.out.println(((Principal) out).getName());
}
Principal newPrincipal = context1.newObject(Principal.class);
newPrincipal.setName("toto");
context1.registerNewObject(newPrincipal); //Same with or
without this line
SelectQuery querySelectAll2 = new SelectQuery(Principal.class);
System.out.println("-test post");
System.out.println("--c1");
for (Object out : context1.performQuery(querySelectAll2)) {
System.out.println(((Principal) out).getName());
}
System.out.println("--new context");
for (Object out :
DataContext.createDataContext().performQuery(querySelectAll2)) {
System.out.println(((Principal) out).getName());
}
context1.rollbackChanges();
System.out.println("-test post rollback");
SelectQuery querySelectAll3 = new SelectQuery(Principal.class);
System.out.println("--c1");
for (Object out : context1.performQuery(querySelectAll3)) {
System.out.println(((Principal) out).getName());
}
System.out.println("--new context");
for (Object out :
DataContext.createDataContext().performQuery(querySelectAll3)) {
System.out.println(((Principal) out).getName());
}
And the output is :
-test pre
domain
administrators
admin
-test post
--c1
domain
administrators
admin
--new context
domain
administrators
admin
-test post rollback
--c1
domain
administrators
admin
--new context
domain
administrators
admin
I think I have not understood completely what a context is.
My question is in "test post" "c1" (created new element "toto", not
commited, query done in the new element's context) shouldn't my new
element appear ?
If I do a commit on context1 then my element is visible, but it also
hit the table.
In case that behaviour is normal, how can I do some local changes to
the dataset without having to commit them to the database ?
Thank you,
Tlarhices
This archive was generated by hypermail 2.0.0 : Fri Oct 15 2010 - 06:48:07 UTC