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

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.

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;
}

}On Wednesday, 8 July 2015 09:29:47 UTC+1, Simon Hooker wrote:

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.

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 http://lucee.org/On 7/8/2015 5:06 AM, Simon Hooker wrote:

Following chatting with Micha, the following solved my issue

|

component {

publicbooleanfunctiononRequestStart(
    required stringtargetPage
){
    setupDatasources();




    QueryExecute(sql=" ... ");   // Errors because second_dsn

(default ) is not defined

    returntrue;
}




publicvoidfunctionsetupDatasources(){

Application
action =‘update’
datasources ={
‘first_dsn’:{/* valid dsn /},
‘second_dsn’:{/
valid dsn */}
},
defaultDatasource =‘second_dsn’,
sessionStorage =‘first_dsn’
sessionCluster =true;
}

}
|

On Wednesday, 8 July 2015 09:29:47 UTC+1, Simon Hooker wrote:

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';
   
    publicbooleanfunctiononRequestStart(
        required stringtargetPage
    ){
        setupSecondDatasource();


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


    publicvoidfunctionsetupSecondDatasource(){
        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';
   
    publicbooleanfunctiononRequestStart(
        required stringtargetPage
    ){
        setupSecondDatasource();


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


    publicvoidfunctionsetupSecondDatasource(){
        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.


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+unsubscribe@googlegroups.com
mailto:lucee+unsubscribe@googlegroups.com.
To post to this group, send email to lucee@googlegroups.com
mailto:lucee@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/lucee/89121714-6862-44c2-b3af-ac9f4f63adc3%40googlegroups.com
https://groups.google.com/d/msgid/lucee/89121714-6862-44c2-b3af-ac9f4f63adc3%40googlegroups.com?utm_medium=email&utm_source=footer.
For more options, visit https://groups.google.com/d/optout.