Skip to content

Instantly share code, notes, and snippets.

@jsteinshouer
Last active September 11, 2017 02:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jsteinshouer/784e8ab5a6ef8bd8dcc99816fa55057f to your computer and use it in GitHub Desktop.
Save jsteinshouer/784e8ab5a6ef8bd8dcc99816fa55057f to your computer and use it in GitHub Desktop.
To-Do legacy application refactor Application.cfc with Coldbox
/**
* Copyright 2005-2007 ColdBox Framework by Luis Majano and Ortus Solutions, Corp
* www.ortussolutions.com
* ---
*/
component{
// Application properties
this.name = hash( getCurrentTemplatePath() );
this.sessionManagement = true;
this.sessionTimeout = createTimeSpan(0,0,30,0);
this.setClientCookies = true;
this.datasources[ "todo" ] = {
class: 'org.h2.Driver',
connectionString: 'jdbc:h2:./db/todo;MODE=MySQL'
};
this.datasource = "todo";
// COLDBOX STATIC PROPERTY, DO NOT CHANGE UNLESS THIS IS NOT THE ROOT OF YOUR COLDBOX APP
COLDBOX_APP_ROOT_PATH = getDirectoryFromPath( getCurrentTemplatePath() );
// The web server mapping to this application. Used for remote purposes or static purposes
COLDBOX_APP_MAPPING = "";
// COLDBOX PROPERTIES
COLDBOX_CONFIG_FILE = "";
// COLDBOX APPLICATION KEY OVERRIDE
COLDBOX_APP_KEY = "";
// application start
public boolean function onApplicationStart(){
queryExecute("
CREATE TABLE IF NOT EXISTS ToDo (
p_todo_id bigint IDENTITY(1,1),
description VARCHAR(150) NOT NULL,
completed_date datetime NULL,
PRIMARY KEY (p_todo_id)
);
");
application.cbBootstrap = new coldbox.system.Bootstrap( COLDBOX_CONFIG_FILE, COLDBOX_APP_ROOT_PATH, COLDBOX_APP_KEY, COLDBOX_APP_MAPPING );
application.cbBootstrap.loadColdbox();
return true;
}
// application end
public boolean function onApplicationEnd( struct appScope ){
arguments.appScope.cbBootstrap.onApplicationEnd( arguments.appScope );
}
// request start
public boolean function onRequestStart( string targetPage ){
// Process ColdBox Request
application.cbBootstrap.onRequestStart( arguments.targetPage );
return true;
}
public void function onSessionStart(){
application.cbBootStrap.onSessionStart();
}
public void function onSessionEnd( struct sessionScope, struct appScope ){
arguments.appScope.cbBootStrap.onSessionEnd( argumentCollection=arguments );
}
public boolean function onMissingTemplate( template ){
return application.cbBootstrap.onMissingTemplate( argumentCollection=arguments );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment