Skip to content

Commit dc507ec

Browse files
committed
boxlang prime switches
1 parent f5a9bc9 commit dc507ec

2 files changed

Lines changed: 169 additions & 1 deletion

File tree

test-harness/config/ApplicationMixins.cfm

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,12 @@
2323
flushAtRequestEnd = false,
2424
autoManageSession = false,
2525
eventHandling = true,
26-
eventHandler = "cbtestharness.models.entities.EventHandler",
2726
dialect = 'MySQL'
2827
};
28+
if( server.keyExists( "boxlang" ) ){
29+
this.ormSettings.eventHandler = "cbtestharness.models.entities.BoxLangEventHandler";
30+
} else {
31+
this.ormSettings.eventHandler = "cbtestharness.models.entities.EventHandler";
32+
}
2933
3034
</cfscript>
Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
/**
2+
* Copyright Since 2005 ColdBox Framework by Luis Majano and Ortus Solutions, Corp
3+
* www.ortussolutions.com
4+
* ---
5+
* Generic Hibernate Event Handler that ties to the ColdBox proxy for ColdBox Operations.
6+
* This is just a base class you can inherit from to give you access to your ColdBox
7+
* Application and the CF9 ORM event handler methods. Then you just need to
8+
* use a la carte.
9+
*
10+
* We also execute interception points that match the ORM events so you can eaisly
11+
* chain ORM interceptions.
12+
*
13+
*/
14+
component extends="coldbox.system.remote.ColdboxProxy" implements="orm.IEventHandler" {
15+
16+
/**
17+
* preLoad called by hibernate which in turn announces a coldbox interception: ORMPreLoad
18+
*/
19+
public void function preLoad( any entity ){
20+
announce( "ORMPreLoad", { entity : arguments.entity } );
21+
}
22+
23+
/**
24+
* postLoad called by hibernate which in turn announces a coldbox interception: ORMPostLoad
25+
*/
26+
public void function postLoad( any entity ){
27+
var sTime = getTickCount();
28+
29+
var args = { entity : arguments.entity, entityName : "" };
30+
31+
// Short-cut discovery via ActiveEntity
32+
if ( structKeyExists( arguments.entity, "getEntityName" ) ) {
33+
args.entityName = arguments.entity.getEntityName();
34+
} else {
35+
// it must be in session.
36+
args.entityName = ormGetSession().getEntityName( arguments.entity );
37+
}
38+
39+
processEntityInjection( args.entityName, args.entity );
40+
41+
announce( "ORMPostLoad", args );
42+
43+
//systemOutput( "==> orm:postLoad:#getTickCount() - sTime#", true );
44+
}
45+
46+
/**
47+
* postDelete called by hibernate which in turn announces a coldbox interception: ORMPostDelete
48+
*/
49+
public void function postDelete( any entity ){
50+
announce( "ORMPostDelete", { entity : arguments.entity } );
51+
}
52+
53+
/**
54+
* preDelete called by hibernate which in turn announces a coldbox interception: ORMPreDelete
55+
*/
56+
public void function preDelete( any entity ){
57+
announce( "ORMPreDelete", { entity : arguments.entity } );
58+
}
59+
60+
/**
61+
* preUpdate called by hibernate which in turn announces a coldbox interception: ORMPreUpdate
62+
*/
63+
public void function preUpdate( any entity, Struct oldData = {} ){
64+
announce( "ORMPreUpdate", { entity : arguments.entity, oldData : arguments.oldData } );
65+
}
66+
67+
/**
68+
* postUpdate called by hibernate which in turn announces a coldbox interception: ORMPostUpdate
69+
*/
70+
public void function postUpdate( any entity ){
71+
announce( "ORMPostUpdate", { entity : arguments.entity } );
72+
}
73+
74+
/**
75+
* preInsert called by hibernate which in turn announces a coldbox interception: ORMPreInsert
76+
*/
77+
public void function preInsert( any entity ){
78+
announce( "ORMPreInsert", { entity : arguments.entity } );
79+
}
80+
81+
/**
82+
* postInsert called by hibernate which in turn announces a coldbox interception: ORMPostInsert
83+
*/
84+
public void function postInsert( any entity ){
85+
announce( "ORMPostInsert", { entity : arguments.entity } );
86+
}
87+
88+
/**
89+
* preSave called by ColdBox Base service before save() calls
90+
*/
91+
public void function preSave( any entity ){
92+
announce( "ORMPreSave", { entity : arguments.entity } );
93+
}
94+
95+
/**
96+
* postSave called by ColdBox Base service after transaction commit or rollback via the save() method
97+
*/
98+
public void function postSave( any entity ){
99+
announce( "ORMPostSave", { entity : arguments.entity } );
100+
}
101+
102+
/**
103+
* Called before the session is flushed.
104+
*/
105+
public void function preFlush( any entities ){
106+
announce( "ORMPreFlush", { entities : arguments.entities } );
107+
}
108+
109+
/**
110+
* Called after the session is flushed.
111+
*/
112+
public void function postFlush( any entities ){
113+
announce( "ORMPostFlush", { entities : arguments.entities } );
114+
}
115+
116+
/**
117+
* postNew called by ColdBox which in turn announces a coldbox interception: ORMPostNew
118+
*/
119+
public void function postNew( any entity, any entityName ){
120+
var args = { entity : arguments.entity, entityName : "" };
121+
122+
// Do we have an incoming name
123+
if ( !isNull( arguments.entityName ) && len( arguments.entityName ) ) {
124+
args.entityName = arguments.entityName;
125+
}
126+
127+
// If we don't have the entity name, then look it up
128+
if ( !len( args.entityName ) ) {
129+
// Short-cut discovery via ActiveEntity
130+
if ( structKeyExists( arguments.entity, "getEntityName" ) ) {
131+
args.entityName = arguments.entity.getEntityName();
132+
} else {
133+
// Long Discovery
134+
var md = getMetadata( arguments.entity );
135+
args.entityName = ( md.keyExists( "entityName" ) ? md.entityName : listLast( md.name, "." ) );
136+
}
137+
}
138+
139+
// Process the announcement
140+
announce( "ORMPostNew", args );
141+
}
142+
143+
/**
144+
* Get the system Event Manager
145+
*/
146+
public any function getEventManager(){
147+
return getWireBox().getEventManager();
148+
}
149+
150+
/**
151+
* process entity injection
152+
*
153+
* @entityName the entity to process, we use hash codes to identify builders
154+
* @entity The entity object
155+
*
156+
* @return The processed entity
157+
*/
158+
public function processEntityInjection( required entityName, required entity ){
159+
// Process DI
160+
getWireBox().autowire( target = arguments.entity, targetID = "ORMEntity-#arguments.entityName#" );
161+
return arguments.entity;
162+
}
163+
164+
}

0 commit comments

Comments
 (0)