Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure ColdFusion's ORM for multiple session scope DSNs?

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 = {}; 
}
like image 253
Micah Avatar asked Nov 18 '11 05:11

Micah


2 Answers

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'{
    ...
}
like image 132
Andreas Schuldhaus Avatar answered Oct 10 '22 20:10

Andreas Schuldhaus


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.

like image 32
Micah Avatar answered Oct 10 '22 20:10

Micah