How do you configure ColdFusion 9's ORM to use multiple DSNs if possible?
Is is possible to setup the datasource in the context of a session scope instead of the application scope?
Or how, in CF9, do you configure Hibernate to use multiple DSNs?
Looks like I should be more specific... I'm looking for a solution that allows for specifying a DSN based on the session.
Here's the scenario. We have a single custom built application that uses multiple DSNs which are determined from the sub-domain. So someone accessing from http://abc.domain.com would use the abc DSN where as someone visiting the xyz.domain.com would use the xyz DSN. The name of the DSN is determined when the session is created and it is stored as a session variable.
I'd like to do something like this:
//Artists.cfc
component persistent="true" datasource="#session.dsn#"
{
property name="artistid" generator="increment";
property firstname;
property lastname;
property address;
property city;
property state;
}
// Application.cfc
component output="false" {
THIS.name = "MultipleDsnORMTest";
THIS.applicationTimeout = createTimeSpan(0, 0, 0, 0);
THIS.clientManagement = false;
THIS.datasource = ""; // Leaving black ==> "No data source specified."
// Setting to cfbookclub ==> "ORM is not
// configured for the current application."
// Setting to cfartgallery works but doesn't
// demonstrate use multiple DSNs
THIS.loginStorage = "cookie";
THIS.sessionManagement = true;
THIS.sessionTimeout = createTimeSpan(0, 0, 0, 0);
THIS.ormenabled = true;
THIS.ormsettings = {};
}
Introduced with the ColdFusion 9.0.1 update, you can use multiple data sources with ORM. One at a time per component. Use the "datasource" attribute in your object, to specify which database should be used.
<cfcomponent displayname="firstObject" datasource="dbOne">
<cffunction>
...
</cffunction>
...
</cfcomponent>
or
component datasource = 'dbOne'{
...
}
Although it is possible to configure ColdFusion 9 to use multiple data sources with ORM in the application scope, it is not possible to configure ColdFusion 9's ORM to work with multiple DSNs within the session scope.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With