Setting datasources in multiple parts of Application.cfc seems to be ignored

186 views
Skip to first unread message

Simon Hooker

unread,
Jul 8, 2015, 4:29:47 AM7/8/15
to lu...@googlegroups.com
Here's a truncated Application.cfc.  When I run this, the 'first_dsn' defined directly seems to work fine, however 'second_dsn' complains that it is not defined.

component {


   
this.datasources[ 'first_dsn' ] = {
       
/* valid datasource definition */
   
};


   
this.sessionCluster     = true;
   
this.sessionStorage     = 'first_dsn';
   
this.defaultDatasource  = 'second_dsn';
   
   
public boolean function onRequestStart(
        required
string targetPage
   
) {
        setupSecondDatasource
();


       
QueryExecute( sql=" ... " );    // Errors because second_dsn (default ) is not defined
       
       
return true;
   
}


   
public void function setupSecondDatasource() {
       
this.datasources[ 'second_dsn' ] = {
           
/* valid datasource definition */
       
};
   
}


}

If instead I do not define 'first_dsn' then 'second_dsn' works fine (see below).  It is as if by defining a datasource in the component body it prevents datasources being defined later.  I have seen similar by defining datasources within the Lucee admin + then being unable to define any OnRequestStart() also.

component {


   
this.defaultDatasource  = 'second_dsn';
   
   
public boolean function onRequestStart(
        required
string targetPage
   
) {
        setupSecondDatasource
();


       
QueryExecute( sql=" ... " );    // Works fine
       
       
return true;
   
}


   
public void function setupSecondDatasource() {
       
this.datasources[ 'second_dsn' ] = {
           
/* valid datasource definition */
       
};
   
}


}

Does anyone have any ideas as to what either I have done wrong, or how I can work around this?   I need 'first_dsn' pretty soon in the boot process due to it being used as a session store however 'second_dsn' is variable based on hostname and so far creating this at OnRequestStart has proved reliable.

Simon Hooker

unread,
Jul 8, 2015, 8:06:17 AM7/8/15
to lu...@googlegroups.com
Following chatting with Micha, the following solved my issue



component
{

   
   
public boolean function onRequestStart(
        required
string targetPage
   
) {

        setupDatasources
();





       
QueryExecute( sql=" ... " );    // Errors because second_dsn (default ) is not defined
       
       
return true;
   
}





   
public void function setupDatasources() {
 
Application
 action
= 'update'
 datasources
= {
               
'first_dsn': { /* valid dsn */ },
               
'second_dsn': { /* valid dsn */ }
           
},
 defaultDatasource
= 'second_dsn',
 sessionStorage
= 'first_dsn'
 sessionCluster
= true;
   
}


}

Igal @ Lucee.org

unread,
Jul 8, 2015, 12:02:54 PM7/8/15
to lu...@googlegroups.com
right.  the issue is that the datasources -- like other settings of the nature of `this.someSetting` in Application.cfc -- must be in the body (pseudo constructor) of the Application.cfc and can not be inside functions.

Igal Sapir
Lucee Core Developer
Lucee.org

--
You received this message because you are subscribed to the Google Groups "Lucee" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lucee+un...@googlegroups.com.
To post to this group, send email to lu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lucee/89121714-6862-44c2-b3af-ac9f4f63adc3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages