I've gone ahead with this design. A main DataContext
that loads the DataObjects needed at runtime. I create
a new temporary DataContext whenever I need to do an
update.
This works fine, except when I want to create a new
DataObject. I can't create it in my temporary
DataContext as it will not allow me to create any
relationships to objects in my main context.
How should I implement this? I wanted a read-only-main
context, and temporary contexts doing all
inserts/updates/deletes. Is it possible?
Dave
--- Mike Kienenberger <mkienen..laska.net> wrote:
> If you want to have a master "read-only-access"
> copy, and then only spin off
> separate contexts to do updates, that seems like a
> reasonable design to me.
> In that case, you don't have to worry about
> non-persisted values, and you
> can store them in the subclasses. You'd only copy
> those objects at the time
> of update, so you don't need to worry about the
> non-persisted values. When
> the changes were committed, the updated persisted
> values would automatically
> propagate back into your master copy.
>
> I don't think there's any need to unregister the
> objects when you're done.
> Just dereference the data context and the objects
> and they should all go
> away in garbage collection.
>
> If you feel the need to do locking, you can do it in
> a non-persisted
> attribute at the application level, but I don't see
> any benefits for doing
> so from what you've described unless you've got
> concerns about players
> overwriting each other's changes.
>
> The one nice thing about Cayenne is that you should
> be able to scale this
> application pretty easily. You can use the remote
> notification stuff to
> have parallel servers running once the user base
> grows to require it.
>
> -Mike
>
>
> Dave <sanxion200..ahoo.com> wrote:
> > Dave wrote:
> > > Are DataObject instances copied in
> > > the DataContext.localObjects() method?
> > > I'm worried about any custom fields not
> > > part of the values Map.
> >
> > Mike wrote
> > > Yes, it will create a new data object pointing
> at
> > the same database record.
> > > What sort of fields do you have that you're not
> > persisting?
> >
> > Non persistant fields that only are relevant to
> the
> > ongoing session. E.g. if the Player has joined a
> > ChatRoom, any movements, moods and so on.
> > They add up to become quite a few. From what I
> > understand there are several possibilities. Let me
> see
> > if I understand them.
> >
> > POSSIBILITY 1
> > Mike wrote:
> > "you might create a server object that internally
> > delegates to a cayenne object for persisted
> values"
> >
> > I'm not sure I understand how this would solve the
> > problem with copies? I need a Context in the main
> > thread that loads the game, all cities, houses,
> rooms
> > and furniture.
> > To safely update them, as we've discussed, I need
> to
> > move them to a seperate context with
> localObjects().
> > Hm. Is there something I'm missing?
> >
> >
> > POSSIBILITY 2
> > Mike wrote:
> > "Another possiblity is to create your own
> > localObjects() method that calls the cayenne
> method,
> > then calls your custom code to copy over your
> > non-persisted values afterward."
> >
> > I guess the main Context should keep track of ALL
> the
> > loaded instances of Player, City, House, Room and
> > Furniture. Any other contexts, residing in Player,
> > should only be used for updating rows. In that
> case
> > I'm not sure I need my non-persitant fields
> copied.
> > I could create a copy of the object I wish to
> update
> > using localObjects() in the player Context. Change
> > persistant fields. Commit changes. Probably
> unregister
> > the object in the player context, as it was
> temporary
> > anyway. Is this a way to go?
> >
> > POSSIBILITY 3
> > Dave wrote:
> > "use the extended class generated by cayenne for
> my
> > custom fields and methods"
> >
> > I'd really like to do this. Perhaps this works
> with
> > what is described above? Are there any other
> options
> > we've overlooked? Or am I ready to charge ahead?
>
__________________________________
Do you Yahoo!?
Yahoo! Mail - Easier than ever with enhanced search. Learn more.
http://info.mail.yahoo.com/mail_250
This archive was generated by hypermail 2.0.0 : Wed Dec 29 2004 - 06:29:15 EST