OK, Look for the ³Oh, yeah...² thread in the Cayenne User list starting at
9/8/2004 by me, and there is a follow-up by Bryan Lewis which might be
(more) useful, too.
I¹m also including the latest version of my code to copy DataMaps. Put it
in a package that makes sense in your environment.
/dev/mrg
import java.util.Collection;
import java.util.Iterator;
import org.objectstyle.cayenne.access.DataDomain;
import org.objectstyle.cayenne.access.DataNode;
import org.objectstyle.cayenne.conf.Configuration;
/**
*..uthor mrg
*
* This package contains utilities for working with Cayenne DataDomains.
*/
public class DataDomainUtilities
{
/**
* Copies a Cayenne DataDomain's DataMap from a source DataDomain to a
target
* DataDomain. Both the source and target must already exist in the
Cayenne
* model. This is useful when using the same map (schema is identical)
across
* different databases. You can define a "shared" map and then copy it to
each
* DataDomain required (which has it's own connection information in the
DataNode).
*
*..aram sourceDataDomainName
*..aram sourceDataMapName
*..aram targetDataDomainName
*/
public static void copyDataDomainDataMap(String sourceDataDomainName,
String sourceDataMapName, String targetDataDomainName)
{
DataDomain sharedDataDomain =
Configuration.getSharedConfiguration().getDomain(sourceDataDomainName);
DataDomain targetDataDomain =
Configuration.getSharedConfiguration().getDomain(targetDataDomainName);
// Add the shared map to the target data domain
targetDataDomain.addMap(sharedDataDomain.getMap(sourceDataMapName));
// Add the shared map to the data node
Collection nodes = targetDataDomain.getDataNodes();
if (nodes.size() != 1)
{
System.out.println("Expected only one DataNode for DataDomain '" +
targetDataDomainName + "' -- this DataDomain is not usable.");
return;
}
Iterator dataNodeIterator = nodes.iterator();
// We are only getting one, though ...
while (dataNodeIterator.hasNext())
{
DataNode node = (DataNode) dataNodeIterator.next();
node.addDataMap(sharedDataDomain.getMap(sourceDataMapName));
}
}
}
From: "Gritsenko Dmitry" <dim..kreative.com>
Date: Wed, 19 Jan 2005 17:04:07 +0200
To: "Michael Gentry (Yes, I'm a Contractor)" <michael_gentr..anniemae.com>
Subject: Re: dynamic switching between 2 DBs
Thank you for your efforts.
Dima.
>
> ----- Original Message -----
>
> From: Michael Gentry (Yes, I'm a Contractor)
> <mailto:michael_gentr..anniemae.com>
>
> To: Gritsenko Dmitry <mailto:dim..kreative.com>
>
> Sent: Wednesday, January 19, 2005 4:59 PM
>
> Subject: Re: dynamic switching between 2 DBs
>
>
> Ah, well you can still use my method for that, too. At runtime, I configure
> (dynamically) which databases I want to talk to. Someone else had another
> method for doing so, too. Let me find that thread for you and I’ll send you
> the information (it’s on the mailing list).
>
> /dev/mrg
>
>
>
> From: "Gritsenko Dmitry" <dim..kreative.com>
> Date: Wed, 19 Jan 2005 16:58:13 +0200
> To: "Gentry, Michael (Contractor)" <michael_gentr..anniemae.com>
> Subject: Re: dynamic switching between 2 DBs
>
> Thank you for your reply.
> What I need is starting application in any of the modes (development, test)
> and corresponding talking to development or test DBs. These are 2 different
> calls, no need for simultanious connection.
>
> Dima.
>
>>
>> ----- Original Message -----
>>
>> From: Gentry, Michael (Contractor) <mailto:michael_gentr..anniemae.com>
>>
>> To: cayenne-use..bjectstyle.org
>>
>> Cc: Gritsenko Dmitry <mailto:dim..kreative.com>
>>
>> Sent: Wednesday, January 19, 2005 4:51 PM
>>
>> Subject: RE: dynamic switching between 2 DBs
>>
>>
>>
>> Are you talking about having the application restart or having two
>> simultaneous connections? If you need to have your application talk to
>> development and test databases at the same time, I have some code I can
>> post here which will help (I actually think I posted it a while back, too).
>>
>>
>>
>> Let me know,
>>
>>
>>
>> /dev/mrg
>>
>>
>>>
>>>
>>> -----Original Message-----
>>> From: Gritsenko Dmitry [mailto:dim..kreative.com]
>>> Sent: Wednesday, January 19, 2005 9:39 AM
>>> To: cayenne-use..bjectstyle.org
>>> Subject: dynamic switching between 2 DBs
>>>
>>>
>>> Hi All,
>>>
>>> What would be the best way to dynamically switch between 2 diff.
>>> databases: development and test in a webapplication?
>>>
>>> Thank you.
>>>
>>>
>
This archive was generated by hypermail 2.0.0 : Wed Jan 19 2005 - 10:44:03 EST