This commit is contained in:
msyu
2025-09-19 10:30:16 +03:00
parent 036fa7b227
commit bcc8fa22ed
+28 -23
View File
@@ -29,11 +29,14 @@
<cfset request.language="">
<!--- кажется, нужно инициализировать датасорцы в псевдоконструкторе - onRequest не получается --->
<!--- *** проверить, что есть - если есть, не создавать --->
<!--- но так не работает --->
<!--- не тут-то было: так не работает --->
<!--- <cfif NOT structKeyExists(this.datasources,this.datasource)>
<cfset this.datasources["#this.datasource#"]=getDS("#this.datasource#","ds_#this.datasource#")/>
</cfif> --->
<!--- это работает с административно заданным датасорцем, хотя, казалось бы, не должно
(без окружения фунекция вернет пустую структуру). Видимо, административный датасорц обнаруживается раньше.
Проверять на пустоту не хочется, чтобы не плодить в псевдоконструкторе переменные --->
<cfset this.datasources["#this.datasource#"]=getDS("#this.datasource#","ds_#this.datasource#")/>
<!--- <cfdump var=#variables#/> --->
@@ -76,7 +79,7 @@
<!--- global settings --->
<cfset request.RECORDS_PER_PAGE=500/>
<cfset request.APP_VERSION="0.00.005"/>
<cfset request.APP_VERSION="0.00.006"/>
<cfset request.STAND=getStand()/>
<!--- application constants --->
@@ -350,33 +353,35 @@
select 1;
</cfquery>
<cfcatch type="database">
<cfcatch type="any">
<cfset system = createObject("java", "java.lang.System")/>
<cfloop list="class,connectionString,database,driver,dbdriver,host,port,type,url,username,password,bundleName,bundleVersion,connectionLimit,liveTimeout,validate" item="field"><!--- driver vs dbdriver --->
<cfset var value=system.getEnv("#arguments.prefix#_#field#")/>
<cfif isDefined("value") AND len(value)>
<cfset structInsert(ds,field,value)/>
</cfif>
</cfloop>
<cfif structIsEmpty(ds)>
<cfthrow type="application" message="Datasource not configured" detail="Datasource not defined in the environment. Expected prefix is #arguments.prefix#"/>
<cfloop list="class,connectionString,database,driver,dbdriver,host,port,type,url,username,password,bundleName,bundleVersion,connectionLimit,liveTimeout,validate" item="field"><!--- driver vs dbdriver --->
<cfset var value=system.getEnv("#arguments.prefix#_#field#")/>
<cfif isDefined("value") AND len(value)>
<cfset structInsert(ds,field,value)/>
</cfif>
</cfcatch>
</cftry>
</cfloop>
<cfif structIsEmpty(ds)>
<cfthrow type="application" message="Datasource not configured" detail="Datasource not defined in the environment. Expected prefix is #arguments.prefix#"/>
</cfif>
<!--- test datasource (just to get exception if invalid) --->
<cftry>
<cfquery name="qTestDs" datasource=#ds#>
select 1;
</cfquery>
<!--- test datasource (just to get exception if invalid) --->
<cftry>
<cfquery name="qTestDs" datasource=#ds#>
select 1;
</cfquery>
<cfcatch type="any">
<!--- <cfdump var=#ds#/><cfabort/> --->
<cfrethrow/>
<cfcatch type="any">
<!--- <cfdump var=#ds#/><cfabort/> --->
<cfdump var=#arguments#/>
<cfdump var=#ds#/>
<cfrethrow/>
</cfcatch>
</cftry>
</cfcatch>
</cftry>
<cfdump var=#ds#/>
<cfreturn ds/>
</cffunction>