FAQ
Hi,

I just started my second cayenne related project and found that I am
doing
the same "workaround" that I did on the first one. Now I wonder if
there is
a better way to do it:

My apps usually have a shopping basket BASKET with a simple relation
to i.e.
BOOKS (via BASKET.isbn -> BOOKS.isbn). Now, I want customers to be
able to add
to the basket without being logged in and so my basket rows might not be
committed to the database unless the user logs in. At that point my
session
which holds all uncommitted basket rows will load in existing basket
rows from
the db and commit.

All this only works if I add the following overwrite to my super
Basket class.
Not a very nice way but proven and stable. Is there a less manual way
to do this?

/Andreas Pardeike



public class Basket extends _Basket
{
// we need to fetch the Book relation manually otherwise transient
baskets
// will fail to resolve getBook()

@Override
public void setISBN(String isbn)
{
super.setISBN(isbn);

Books book = DataObjectUtils.objectForPK(getObjectContext(),
Books.class, isbn);
if(book != null)
setBook(book);
}
}



and here's how I add a basket row:

Basket row = _context.newObject(Basket.class);
row.setISBN(newISBN);
row.setLogin(_login == null ? "" : _login);
...
if(_login != null)
_context.commitChanges();

Search Discussions

Discussion Posts

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 1 of 3 | next ›
Discussion Overview
groupuser @
categoriescayenne
postedMar 20, '08 at 8:56a
activeMar 20, '08 at 9:34a
posts3
users2
websitecayenne.apache.org

People

Translate

site design / logo © 2021 Grokbase