You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Jan Lendholt <jl...@hotmail.com> on 2007/07/31 15:26:51 UTC

Prevent of commit

Hey Folks,

another question:

I created an object via context.newObject(Service.class);

Before I do a context.commitChanges() I check if there are any input errors 
in the input fields that should be set to the object. If we encounter an 
exception, we abort the creation / editing of the current object.

Now, in the meantime, I take another window to create another object, like 
context.newObject(Person.class) and call the context.commitChanges().

Now, the old object, at which the check of the data failed, ist committed as 
well.

Is there any method that prevents the commit of an object?
I just found context.unregisterObjects... is this the only possibility to 
prevent a commit?

Background:

We have a swing-app using the objects and passing them in constructor calls. 
If we encounter any problems upon editing this passed object and commit 
changes on another object, all party changed things will be committed as 
well, which is unliked by us.

I hope I could explain clearly.

Bye, Jan

_________________________________________________________________
Haben Spinnen Ohren? Finden Sie es heraus – mit dem MSN Suche Superquiz via  
http://www.msn-superquiz.de  Jetzt mitmachen und gewinnen!


Re: Prevent of commit

Posted by Aristedes Maniatis <ar...@maniatis.org>.
On 31/07/2007, at 11:26 PM, Jan Lendholt wrote:

> I created an object via context.newObject(Service.class);
>
> Before I do a context.commitChanges() I check if there are any  
> input errors in the input fields that should be set to the object.  
> If we encounter an exception, we abort the creation / editing of  
> the current object.
>
> Now, in the meantime, I take another window to create another  
> object, like context.newObject(Person.class) and call the  
> context.commitChanges().
>
> Now, the old object, at which the check of the data failed, ist  
> committed as well.

Just to add to Michael's useful comments, what we do is have one  
'shared' context which is used to display lots of read only data.  
These usually represent records in some sort of list (which you  
double click to edit). This is shared between all open windows and  
other processes and is only read from. Then each editable window  
creates its own editing context as needed. This gives a good balance  
between caching of data (in the big shared context) and small  
flexible contexts for editing.

In the notes above it appears you might be missing the concept of  
validation in Cayenne. You don't need to validate data before you  
populate the object. Better to put the data directly into your object  
entity and then try to commit it. Any validation exceptions can then  
be properly dealt with by your code and GUI.

Ari Maniatis






-------------------------->
Aristedes Maniatis
phone +61 2 9660 9700
PGP fingerprint 08 57 20 4B 80 69 59 E2  A9 BF 2D 48 C2 20 0C C8



Re: Prevent of commit

Posted by Jan Lendholt <jl...@hotmail.com>.
Hey Michael,
that's exatcly the clue we needed. Now it works like a charme.
The only annoying thing is to put the object from context a to context b.
I would prefer something like "detach" object from commit. But that's not 
such a clean way like another context...

Wow.,.. that was a hard day.

Thanks a lot to you guys, you were a great help :-)
Thereofore I'll try to submit the MaxDB Database Adapter to the dev-list 
ASAP.

Bye.


>From: "Michael Gentry" <bl...@gmail.com>
>Reply-To: user@cayenne.apache.org
>To: user@cayenne.apache.org
>Subject: Re: Prevent of commit
>Date: Tue, 31 Jul 2007 12:09:15 -0400
>
>On 7/31/07, Jan Lendholt <jl...@hotmail.com> wrote:
> > Hi Michael, Hi Aristedes,
> >
> > thank you very much for your help.
> >
> > But, still I've got a conceptual problem:
> >
> > I get an object from the "root" DataContext and pass this object to 
>another,
> > e.g. method, to use.
> > Now the object is already registered in the "root" context and I would 
>like
> > to transer it to a child DataContext. That sounds to me a bit intensive 
>on
> > the working time spent to create an object and transfer it directly to
> > another context.
>
>Can you not just fetch the object you need into the nested context
>directly?  You could always use the localObject() method to pull it
>into your nested context:
>
>http://cayenne.apache.org/doc20/moving-objects-between-contexts.html
>
>Something like:
>
>nestedContext.localObject(objectToPullIntoNestedContext.getObjectId(), 
>null)
>
> > Aaaand If i get the object form Context A and put it in nestedContext B, 
>do
> > a commit - where is the Object then? Is it belonging to Context A, B or
> > both? And if I want to reuse the object of context A which has 
>temporarily
> > been moved to context B to be commited separately, is it synchroniously
> > updated in context A while it was modified in context B?
>
>It would be in A and B.  And the object in A isn't temporarily moved
>to B, it exists in A and B at the same time, but you want to make
>changes to the one in B.  When you nestedContext.commitChanges() it'll
>update the object in A and in the database, too, unless you call
>nestedContext.commitChangesToParent(), which only pushes the changes
>into A and skips updating the database.
>
> > For me it's some kind of hard for I really don't know how to handle the
> > different contexts separetaly but keeping the application data 
>consistent.
>
>You typically create a nested DC when you need to do something that
>you might want to abandon -- a classic example would be a multi-page
>wizard-type process.  At any point in the wizard steps the user can be
>entering data and going to the next page.  This can all be stored in
>the nested DC.  If they cancel, you discard the nested DC -- which
>means your parent DC doesn't get any of the "dirty" objects/changes
>from the nested DC and you don't have to clean anything up or unwind.
>If they finish/save/etc, you commit the changes and the parent DC is
>updated and the database changes are committed.
>
>/dev/mrg

_________________________________________________________________
Sie suchen E-Mails, Dokumente oder Fotos? Die neue MSN Suche Toolbar mit 
Windows-Desktopsuche liefert in sekundenschnelle Ergebnisse. Jetzt neu! 
http://desktop.msn.de/ Jetzt gratis downloaden!


Re: Distinct

Posted by Andrus Adamchik <an...@objectstyle.org>.
Cayenne strips DISTINCT if the ResultSet contains one of the  
following columns (since most databases will not tolerate combination  
of DISTINCT and those types) : Types.BLOB, Types.CLOB,  
Types.LONGVARBINARY, Types.LONGVARCHAR


> Or is there a memory-based distinction?

Absolutely right - if DISTINCT was requested, but Cayenne had to  
strip it from the generated SQL, it would do an in memory removal of  
duplicates based on ObjectId comparison:

http://svn.apache.org/repos/asf/cayenne/main/trunk/framework/cayenne- 
jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/util/ 
DistinctResultIterator.java

Andrus



On Aug 2, 2007, at 6:17 PM, Jan Lendholt wrote:
> Hey all, it's me again.
>
> i tried to set up a statement like this:
>
> SelectQuery q_catering = new SelectQuery 
> (ServiceKundeLocation.class, ExpressionFactory.matchExp 
> (ServiceKundeLocation.LID_PROPERTY, buchung.getToEvent().getLid()));
> q_catering.setDistinct(true);
>
> List caterings = Application.getApp().getContext().performQuery 
> (q_catering);
>
> Instead of getting a DISTINCT operator in the executed sql it is  
> msssing.
>
> Is there a special trick to activate the distinct clause? Or is  
> there a memory-based distinction?
>
> Thanks in advance,
>
> Jan

Distinct

Posted by Jan Lendholt <jl...@hotmail.com>.
Hey all, it's me again.

i tried to set up a statement like this:

SelectQuery q_catering = new SelectQuery(ServiceKundeLocation.class, 
ExpressionFactory.matchExp(ServiceKundeLocation.LID_PROPERTY, 
buchung.getToEvent().getLid()));
q_catering.setDistinct(true);

List caterings = Application.getApp().getContext().performQuery(q_catering);

Instead of getting a DISTINCT operator in the executed sql it is msssing.

Is there a special trick to activate the distinct clause? Or is there a 
memory-based distinction?

Thanks in advance,

Jan

_________________________________________________________________
Sie suchen E-Mails, Dokumente oder Fotos? Die neue MSN Suche Toolbar mit 
Windows-Desktopsuche liefert in sekundenschnelle Ergebnisse. Jetzt neu! 
http://desktop.msn.de/ Jetzt gratis downloaden!


Re: Open interface

Posted by Andrus Adamchik <an...@objectstyle.org>.
I see two ways to go about it.

1. First, quick and dirty, is to not use ROP. Just create your own  
web service with specific query methods, and serialize the results to  
XML via Cayenne XML package (or some other way).

2. Second is what Ari just described. Objective C client is using  
Hessian protocol (just as Java). You may use that or try to build  
upon the ROP-WSDL done as a part of Summer of Code 2006 by a student:

    http://svn.apache.org/repos/asf/cayenne/soc/trunk/cayenne-ropwsdl/

This exposes ROP server as a WSDL, so this is sort of a standard  
extension protocol and it may (or may not?) be easier to get the  
client going.


First option should work for most apps, as long as the client logic  
is not too complex and you do not need to commit object graphs from  
the client. The second option provides maximum client power, but  
would also require some serious dedication to implement.

Andrus





On Aug 1, 2007, at 1:27 PM, Aristedes Maniatis wrote:
>
> On 01/08/2007, at 6:34 PM, Jan Lendholt wrote:
>
>> I read about the Remote funcitonality in cayenne but I guess it is  
>> not possible to connect this service to .Net.
>
> Someone has already done some work to write a ROP Cayenne client in  
> Objective C, and Cayenne has as a design goal that other clients  
> are certainly possible. The place to start would be to look at  
> Hessian and dig up one of the many implementations of it for  
> different platforms. That is the serialisation layer and is needed  
> to get the http data stream back into objects at the remote end.
>
> After that, you'll need to examine what Cayenne ROP does (or dig up  
> that Objective C implementation) and implement that for your chosen  
> platform. IMO such a project would be welcomed by a great many  
> people and offers great promise for remote rich GUI applications.
>
> Ari Maniatis
>
>
> -------------------------->
> Aristedes Maniatis
> phone +61 2 9660 9700
> PGP fingerprint 08 57 20 4B 80 69 59 E2  A9 BF 2D 48 C2 20 0C C8
>
>


Re: Open interface

Posted by Aristedes Maniatis <ar...@maniatis.org>.
On 01/08/2007, at 6:34 PM, Jan Lendholt wrote:

> I read about the Remote funcitonality in cayenne but I guess it is  
> not possible to connect this service to .Net.

Someone has already done some work to write a ROP Cayenne client in  
Objective C, and Cayenne has as a design goal that other clients are  
certainly possible. The place to start would be to look at Hessian  
and dig up one of the many implementations of it for different  
platforms. That is the serialisation layer and is needed to get the  
http data stream back into objects at the remote end.

After that, you'll need to examine what Cayenne ROP does (or dig up  
that Objective C implementation) and implement that for your chosen  
platform. IMO such a project would be welcomed by a great many people  
and offers great promise for remote rich GUI applications.

Ari Maniatis


-------------------------->
Aristedes Maniatis
phone +61 2 9660 9700
PGP fingerprint 08 57 20 4B 80 69 59 E2  A9 BF 2D 48 C2 20 0C C8



Open interface

Posted by Jan Lendholt <jl...@hotmail.com>.
Hey Folks, it's me again with yet another question.

I've got a Windows CE 5 mobile device. There's no discussion about getting 
other devices being able to run java apps.
So I have to deal with VB .Net / C# .NET.

I would like to do some synchronisation stuff between the mobile device and 
my cayenne app. Herefore I would like to write a web service delivering on 
demand  data to the client.
I read about the Remote funcitonality in cayenne but I guess it is not 
possible to connect this service to .Net.

Is there any open xml interface or stuff like that so I cann access the 
objects cayenne would deliver me?
Or do I have to write the protocol on my own?

Thanks again,

Jan

_________________________________________________________________
Sie suchen E-Mails, Dokumente oder Fotos? Die neue MSN Suche Toolbar mit 
Windows-Desktopsuche liefert in sekundenschnelle Ergebnisse. Jetzt neu! 
http://desktop.msn.de/ Jetzt gratis downloaden!


Re: Prevent of commit

Posted by Michael Gentry <bl...@gmail.com>.
On 7/31/07, Jan Lendholt <jl...@hotmail.com> wrote:
> Hi Michael, Hi Aristedes,
>
> thank you very much for your help.
>
> But, still I've got a conceptual problem:
>
> I get an object from the "root" DataContext and pass this object to another,
> e.g. method, to use.
> Now the object is already registered in the "root" context and I would like
> to transer it to a child DataContext. That sounds to me a bit intensive on
> the working time spent to create an object and transfer it directly to
> another context.

Can you not just fetch the object you need into the nested context
directly?  You could always use the localObject() method to pull it
into your nested context:

http://cayenne.apache.org/doc20/moving-objects-between-contexts.html

Something like:

nestedContext.localObject(objectToPullIntoNestedContext.getObjectId(), null)

> Aaaand If i get the object form Context A and put it in nestedContext B, do
> a commit - where is the Object then? Is it belonging to Context A, B or
> both? And if I want to reuse the object of context A which has temporarily
> been moved to context B to be commited separately, is it synchroniously
> updated in context A while it was modified in context B?

It would be in A and B.  And the object in A isn't temporarily moved
to B, it exists in A and B at the same time, but you want to make
changes to the one in B.  When you nestedContext.commitChanges() it'll
update the object in A and in the database, too, unless you call
nestedContext.commitChangesToParent(), which only pushes the changes
into A and skips updating the database.

> For me it's some kind of hard for I really don't know how to handle the
> different contexts separetaly but keeping the application data consistent.

You typically create a nested DC when you need to do something that
you might want to abandon -- a classic example would be a multi-page
wizard-type process.  At any point in the wizard steps the user can be
entering data and going to the next page.  This can all be stored in
the nested DC.  If they cancel, you discard the nested DC -- which
means your parent DC doesn't get any of the "dirty" objects/changes
from the nested DC and you don't have to clean anything up or unwind.
If they finish/save/etc, you commit the changes and the parent DC is
updated and the database changes are committed.

/dev/mrg

Re: Prevent of commit

Posted by Jan Lendholt <jl...@hotmail.com>.
Hi Michael, Hi Aristedes,

thank you very much for your help.

But, still I've got a conceptual problem:

I get an object from the "root" DataContext and pass this object to another, 
e.g. method, to use.
Now the object is already registered in the "root" context and I would like 
to transer it to a child DataContext. That sounds to me a bit intensive on 
the working time spent to create an object and transfer it directly to 
another context.

Aaaand If i get the object form Context A and put it in nestedContext B, do 
a commit - where is the Object then? Is it belonging to Context A, B or 
both? And if I want to reuse the object of context A which has temporarily 
been moved to context B to be commited separately, is it synchroniously 
updated in context A while it was modified in context B?

For me it's some kind of hard for I really don't know how to handle the 
different contexts separetaly but keeping the application data consistent.

Bye, Jan



>From: "Michael Gentry" <bl...@gmail.com>
>Reply-To: user@cayenne.apache.org
>To: user@cayenne.apache.org
>Subject: Re: Prevent of commit
>Date: Tue, 31 Jul 2007 10:09:32 -0400
>
>On 7/31/07, Jan Lendholt <jl...@hotmail.com> wrote:
> > Just one thing: How do we unset/destroy/throw away an unused DataContext 
>/
> > ChildContext?
>
>context = null;
>
>That should be all you need.
>
>/dev/mrg

_________________________________________________________________
Sie suchen E-Mails, Dokumente oder Fotos? Die neue MSN Suche Toolbar mit 
Windows-Desktopsuche liefert in sekundenschnelle Ergebnisse. Jetzt neu! 
http://desktop.msn.de/ Jetzt gratis downloaden!


Re: Prevent of commit

Posted by Michael Gentry <bl...@gmail.com>.
On 7/31/07, Jan Lendholt <jl...@hotmail.com> wrote:
> Just one thing: How do we unset/destroy/throw away an unused DataContext /
> ChildContext?

context = null;

That should be all you need.

/dev/mrg

Re: Prevent of commit

Posted by Michael Gentry <bl...@gmail.com>.
I should have included this link on nested DataContexts, in case you
want to explore that option:

http://cayenne.apache.org/doc20/nested-datacontexts.html

/dev/mrg

Re: Prevent of commit

Posted by Jan Lendholt <jl...@hotmail.com>.
Hey Michael,

thanks for your answer - we just tried out the nested DataContext's and 
that's exactly what we needed. This seems to be the solution. And your 
documentation-link was already found by one of my developer.

Just one thing: How do we unset/destroy/throw away an unused DataContext / 
ChildContext?

Thanks in advance!

Jan


>From: "Michael Gentry" <bl...@gmail.com>
>Reply-To: user@cayenne.apache.org
>To: user@cayenne.apache.org
>Subject: Re: Prevent of commit
>Date: Tue, 31 Jul 2007 09:34:31 -0400
>
>Two options that immediately come to my mind are:
>
>1) Use separate DataContext instances.  You could have one DataContext
>per window (or even more if it made sense).  Creating a DataContext
>isn't a very CPU-intensive activity, so you won't incur a large cost
>making many of them.  Of course, you can throw away contexts you don't
>want, too.
>
>2) Use a nested DataContext.  In your first window where you are
>checking for input errors, do that work in a nested DataContext.  If
>you encounter errors and want to abandon it, again just throw away the
>nested context without committing changes to the parent.
>
>You could still unregister, but the above two options might be easier
>to implement.
>
>/dev/mrg
>
>
>On 7/31/07, Jan Lendholt <jl...@hotmail.com> wrote:
> > Hey Folks,
> >
> > another question:
> >
> > I created an object via context.newObject(Service.class);
> >
> > Before I do a context.commitChanges() I check if there are any input 
>errors
> > in the input fields that should be set to the object. If we encounter an
> > exception, we abort the creation / editing of the current object.
> >
> > Now, in the meantime, I take another window to create another object, 
>like
> > context.newObject(Person.class) and call the context.commitChanges().
> >
> > Now, the old object, at which the check of the data failed, ist 
>committed as
> > well.
> >
> > Is there any method that prevents the commit of an object?
> > I just found context.unregisterObjects... is this the only possibility 
>to
> > prevent a commit?
> >
> > Background:
> >
> > We have a swing-app using the objects and passing them in constructor 
>calls.
> > If we encounter any problems upon editing this passed object and commit
> > changes on another object, all party changed things will be committed as
> > well, which is unliked by us.
> >
> > I hope I could explain clearly.
> >
> > Bye, Jan
> >
> > _________________________________________________________________
> > Haben Spinnen Ohren? Finden Sie es heraus – mit dem MSN Suche Superquiz 
>via
> > http://www.msn-superquiz.de  Jetzt mitmachen und gewinnen!
> >
> >

_________________________________________________________________
Haben Spinnen Ohren? Finden Sie es heraus – mit dem MSN Suche Superquiz via  
http://www.msn-superquiz.de  Jetzt mitmachen und gewinnen!


Re: Prevent of commit

Posted by Michael Gentry <bl...@gmail.com>.
Two options that immediately come to my mind are:

1) Use separate DataContext instances.  You could have one DataContext
per window (or even more if it made sense).  Creating a DataContext
isn't a very CPU-intensive activity, so you won't incur a large cost
making many of them.  Of course, you can throw away contexts you don't
want, too.

2) Use a nested DataContext.  In your first window where you are
checking for input errors, do that work in a nested DataContext.  If
you encounter errors and want to abandon it, again just throw away the
nested context without committing changes to the parent.

You could still unregister, but the above two options might be easier
to implement.

/dev/mrg


On 7/31/07, Jan Lendholt <jl...@hotmail.com> wrote:
> Hey Folks,
>
> another question:
>
> I created an object via context.newObject(Service.class);
>
> Before I do a context.commitChanges() I check if there are any input errors
> in the input fields that should be set to the object. If we encounter an
> exception, we abort the creation / editing of the current object.
>
> Now, in the meantime, I take another window to create another object, like
> context.newObject(Person.class) and call the context.commitChanges().
>
> Now, the old object, at which the check of the data failed, ist committed as
> well.
>
> Is there any method that prevents the commit of an object?
> I just found context.unregisterObjects... is this the only possibility to
> prevent a commit?
>
> Background:
>
> We have a swing-app using the objects and passing them in constructor calls.
> If we encounter any problems upon editing this passed object and commit
> changes on another object, all party changed things will be committed as
> well, which is unliked by us.
>
> I hope I could explain clearly.
>
> Bye, Jan
>
> _________________________________________________________________
> Haben Spinnen Ohren? Finden Sie es heraus – mit dem MSN Suche Superquiz via
> http://www.msn-superquiz.de  Jetzt mitmachen und gewinnen!
>
>