You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Adrian Wiesmann <aw...@somap.org> on 2008/05/18 16:09:54 UTC

Questions about Ordering, Optimistic Locking and QueryTable

Hello list

Instead of writing three separate mails I thought it would make sense to
pack these three questions together:

Ordering
--------
I am having a list of DataObjects where one field represents a human
readable Id. Something like this:

"1.1.1" (as example)

When using the (offline) ordering mechanism of Cayenne to order a list of
DataObjects, things get ugly when I am introducing numbers above 10. Like
the following example:

1.1.1
1.1.2
1.10.1
1.10.2
1.2.1
1.2.2

I would like to have the 1.10.x numbers below the 1.2.x numbers. Which
means I would like to sort mathematically and not alphabetically.

Is there any possibility to tell Cayenne to sort differently? Or would I
need to add a new (virtual) field to the DataObject with a clean sort
number and have Cayenne sort that field instead?


Optimistic Locking
------------------
My DataObjects contain a datetime field and a string field which both are
used for optimistic locking. Basically the fields contain the datetime of
the last change plus the user Id of the user persisting the change.

When using optimistic locking with Derby everything works as expected.
When using the same code and configuration with PostgreSQL (7 and 8) I
receive an optimistic locking failure although nothing has changed on the
database in the meantime.

When I then remove the datetime field only from the optimistic locking
check things work as expected.

Has anybody experienced the same? Is this a known problem or am I missing
something?


QueryTable
----------
We were discussing that on this list before. I am looking for a way to
generate DataObjects without a reference to a table in the database.
Something like a virtual DataObject. 

My usage scenario is it to have a DataObject which can be bound to the UI
but which is only used to prepare data for a query and never should be
persisted to the database.

I remember some discussion about introducing some kind of inheritance to
Cayenne which would support my usage scenario. I just wanted to check back
with you if something already happened there?

Thanks for your help.

Cheers,
Adrian

P.S: Andrus: I remember you talking about being interested in learning
about experiences with Apache Wicket? The Wicket Framework is great and
using it with Cayenne works like a charm. Wicket is really a webframework
done right! 

Re: Questions about Ordering, Optimistic Locking and QueryTable

Posted by Adrian Wiesmann <aw...@somap.org>.
On Mon, 19 May 2008 09:19:26 +1000
Aristedes Maniatis <ar...@ish.com.au> wrote:

> There should be something coming soon with inheritance, but there were  
> no plans to support persistent objects with no database backing at  
> all. There is going to be the opposite concept: abstract classes which  
> have a database table, but which can only be constructed in their  
> subclass.
> 
> Tell us more about why it would be useful to have data objects which  
> cannot be persisted to the database.

I guess my usage scenario is very specific to my environment. But let me
introduce my environment and let you decide.

I have written a UI renderer and data binding engine (Gozer). For that
engine to work I introduced the Domain Model, Table Module and Record Set
patterns and DataObjectKeys to Cayenne (at least to some extent). I did so
with my own code generator which generates datarows, datarowkeys and table
modules to every ObjEntity modeled with the Cayenne modeler.

For the data binding I use then these table modules. Let's say I have a
table with users. I can then bind that table to the UI like that:

<list databinding="@user">
   <list_field databinding="username" />
</list>

My UI engine is interpreting the binding information so that the UI
renders a list of users with the only field in the list containing the
username.

Which means that whenever I display data on the UI, I am using the same
databinding which makes use of my datatable and datarow objects.

Now to the QueryTable problem: Many applications have some form of user
input where a user can enter search criteria and then use that criteria to
filter a list of records or search data in the database. Since my UI
engine knows how to render my table modules and datarows, I would love to
use the same mechanism for query interfaces (a huge time saver).

To extend my example from above: I could introduce a UserQueryTable with a
field UserName. I could then define a view which binds that table. The
user enters a username and when clicking on the search button I could read
the content from the UserQueryTable and construct the query from the
content of that table. Side effect, all my queries would be
"standardised" and whenever I need to search for users in my application
I can use the same interface (UserQueryTable) which is then sent to the
UserQuery Business Object which handles the querying in a central
location (domain model pattern).

Of course I could solve that problem in creating ObjEntity which have
a corresponding table in the database (which is never used). But I find
this to be very ugly...

Hope this explained my scenario.

Cheers,
Adrian

Re: Questions about Ordering, Optimistic Locking and QueryTable

Posted by Aristedes Maniatis <ar...@ish.com.au>.
On 19/05/2008, at 12:09 AM, Adrian Wiesmann wrote:

> We were discussing that on this list before. I am looking for a way to
> generate DataObjects without a reference to a table in the database.
> Something like a virtual DataObject.
>
> My usage scenario is it to have a DataObject which can be bound to  
> the UI
> but which is only used to prepare data for a query and never should be
> persisted to the database.
>
> I remember some discussion about introducing some kind of  
> inheritance to
> Cayenne which would support my usage scenario. I just wanted to  
> check back
> with you if something already happened there?

There should be something coming soon with inheritance, but there were  
no plans to support persistent objects with no database backing at  
all. There is going to be the opposite concept: abstract classes which  
have a database table, but which can only be constructed in their  
subclass.

Tell us more about why it would be useful to have data objects which  
cannot be persisted to the database.

Ari



-------------------------->
ish
http://www.ish.com.au
Level 1, 30 Wilson Street Newtown 2042 Australia
phone +61 2 9550 5001   fax +61 2 9550 4001
GPG fingerprint CBFB 84B4 738D 4E87 5E5C  5EFA EF6A 7D2E 3E49 102A