Re: two databases from one application
Re: two databases from one application
- Subject: Re: two databases from one application
- From: "Pierce T. Wetter III" <email@hidden>
- Date: Wed, 10 May 2006 13:33:40 -0700
On May 10, 2006, at 10:34 AM, Anjo Krank wrote:
WO application I am working on was pretty simple up to
this point: one apache webserver and one database
server serving data to it. The things turned more
complicated now: In addition to the first database, we
now want to add access to another database. Both of
these databases have identical schema, and the tables
in question are identical. Think of the second
database as a backup.
You simply can't do that in an easy way.
Yeah the problem is that EOF associates specific classes with
specific tables in specific databases.
However, I think you can work around that if you make a duplicate
EOModel called "Backup", and then have every entity in that model
_subclass_ from the primary model. (Remember to mark the
relationships in the subclasses to point at the new subclass as well.
So that would work around the EOF association of specific classes
with specific databases. EOF would know that the subclass lived in
your new database. Copying over the primary keys and such to the new
database will be tedious if its important to have the same values,
and the relationship recursion can get complicated if you have any
trees in your relationship.
But you'll have to manually create/store the new subclasses,
there's no way to change the class of an EOF object on the fly.
So in psuedo code:
1. Fetch the entities you want to copy into the ec.
2. for each object:
copy over the attributes of the old object into an instance
of the new class. (you can loop over self.entity.attributes)
recurse through the relationships and do the same thing...
3. ec.saveChanges()
Though I'm wondering what problem you're trying to solve where you
want to delete records from the first database while making copies in
the second database? I'm guessing an audit trail? There are easier
ways to do that...
Also, your code won't work because "localInstanceOfObject" doesn't
really make a copy, it makes a fault for the original object. When
you then touch that object, it causes EOF to clone the original
object into the new editing context based on the snapshot stored when
the object was fetched, but without any of the changes from the first
editing context.
Pierce
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden