70 lines
3.0 KiB
Plaintext
70 lines
3.0 KiB
Plaintext
<cfcomponent displayname="Application" output="true">
|
|
|
|
<cfset this.Name = "nubes-crud-demo" />
|
|
<cfset this.sessionmanagement = "Yes" />
|
|
<cfset this.datasource = "testds" />
|
|
|
|
<cfset getDS(this.datasource) />
|
|
|
|
<cffunction name="getDS" access="private" returntype="void">
|
|
<cfargument name="dsname" type="string" required="true"/>
|
|
<cfset var system = createObject("java", "java.lang.System")/>
|
|
<cfset var ds = {} />
|
|
<cfloop list="class,connectionString,database,driver,host,port,type,url,username,password,bundleName,bundleVersion,connectionLimit,liveTimeout,validate" item="field">
|
|
<cfset var envVal = system.getEnv("#arguments.dsname#_#field#") />
|
|
<cfif isDefined("envVal") AND len(envVal)>
|
|
<cfset ds[field] = envVal />
|
|
</cfif>
|
|
</cfloop>
|
|
<cfset this.datasources[arguments.dsname] = ds />
|
|
</cffunction>
|
|
|
|
<cffunction name="OnRequest" access="public" returntype="void" output="true">
|
|
<cfargument name="template" type="string" required="true" />
|
|
|
|
<cfset request.DS = this.datasource />
|
|
<cfset setEncoding("FORM", "UTF-8")>
|
|
<cfset setEncoding("URL", "UTF-8")>
|
|
|
|
<cfif structKeyExists(form, "crud_action")>
|
|
<cftry>
|
|
<cfswitch expression="#form.crud_action#">
|
|
<cfcase value="insert">
|
|
<cfquery datasource="#request.DS#">
|
|
INSERT INTO nubes_test_table (test_data)
|
|
VALUES (<cfqueryparam value="#form.txt_content#" cfsqltype="cf_sql_varchar">)
|
|
</cfquery>
|
|
</cfcase>
|
|
<cfcase value="update">
|
|
<cfquery datasource="#request.DS#">
|
|
UPDATE nubes_test_table
|
|
SET test_data = <cfqueryparam value="#form.txt_content#" cfsqltype="cf_sql_varchar">
|
|
WHERE id = <cfqueryparam value="#form.id#" cfsqltype="cf_sql_integer">
|
|
</cfquery>
|
|
</cfcase>
|
|
<cfcase value="delete">
|
|
<cfquery datasource="#request.DS#">
|
|
DELETE FROM nubes_test_table
|
|
WHERE id = <cfqueryparam value="#form.id#" cfsqltype="cf_sql_integer">
|
|
</cfquery>
|
|
</cfcase>
|
|
</cfswitch>
|
|
<cfcatch><cfset request.db_error = cfcatch.message /></cfcatch>
|
|
</cftry>
|
|
</cfif>
|
|
|
|
<cftry>
|
|
<cfquery datasource="#request.DS#">
|
|
CREATE TABLE IF NOT EXISTS nubes_test_table (
|
|
id SERIAL PRIMARY KEY,
|
|
test_data TEXT,
|
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
|
);
|
|
</cfquery>
|
|
<cfcatch><cfset request.db_error = cfcatch.message /></cfcatch>
|
|
</cftry>
|
|
|
|
<cfinclude template="#arguments.template#" />
|
|
</cffunction>
|
|
|
|
</cfcomponent> |