Created
September 19, 2012 17:56
-
-
Save adamcameron/3751114 to your computer and use it in GitHub Desktop.
An Application.cfc to test what happens when this.datasource is set by a conditional using a CGI variable
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
component { | |
this.name = "testPseudoConstructor"; | |
this.applicationTimeout = createTimeSpan(0,0,1,0); | |
this.sessionManagement = true; | |
this.sessionTimeout = createTimeSpan(0,0,0,30); | |
if (CGI.server_name == "localhost"){ | |
this.datasource = "dsn1"; | |
}else if (CGI.server_name == "testing.local"){ | |
this.datasource = "dsn2"; | |
}else{ | |
// yer out of luck, mate | |
} | |
function onApplicationStart(){ | |
logIt("onApplicationStart [#CGI.server_name#]"); | |
} | |
function onSessionStart(){ | |
logIt("onSessionStart [#CGI.server_name#]"); | |
} | |
function onRequestStart(){ | |
logIt("onRequestStart [#CGI.server_name#]"); | |
} | |
function onRequest(){ | |
include arguments[1]; | |
} | |
function onSessionEnd(){ | |
logIt("onSessionEnd [#CGI.server_name#]"); | |
} | |
function onApplicationEnd(){ | |
logIt("onApplicationEnd [#CGI.server_name#]"); | |
} | |
function logIt(required string message){ | |
param name="this.dataSource" default="NOT_SET"; | |
writeLog(file=this.name, text="Start of logIt(). #message# [#this.dataSource#]"); | |
try { | |
new Query( | |
sql = " | |
INSERT INTO t_test ( | |
tst_data | |
) VALUES ( | |
'#message#' | |
) | |
" | |
).execute(); | |
} | |
catch (any e){ | |
writeLog(file=this.name, text="CATCH in logIt(). #message# [#this.dataSource#] [#e.message#] [#e.detail#]"); | |
rethrow; | |
} | |
writeLog(file=this.name, text="End of logIt(). #message# [#this.dataSource#]"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment