Skip to content

Commit 6a24dcb

Browse files
committed
Switch to bx-only event handler for boxlang prime support
1 parent cffd227 commit 6a24dcb

File tree

4 files changed

+195
-6
lines changed

4 files changed

+195
-6
lines changed

models/ACFEventHandler.cfc

Lines changed: 0 additions & 4 deletions
This file was deleted.

models/BXEventHandler.bx

Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
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+
class extends="coldbox.system.remote.ColdboxProxy" {
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 args = {
28+
"entity" : arguments.entity,
29+
"entityName" : getOrm().getEntityGivenName( arguments.entity )
30+
};
31+
processEntityInjection( args.entityName, args.entity );
32+
announce( "ORMPostLoad", args );
33+
}
34+
35+
/**
36+
* postDelete called by hibernate which in turn announces a coldbox interception: ORMPostDelete
37+
*/
38+
public void function postDelete( any entity ){
39+
announce( "ORMPostDelete", { "entity" : arguments.entity } );
40+
}
41+
42+
/**
43+
* preDelete called by hibernate which in turn announces a coldbox interception: ORMPreDelete
44+
*/
45+
public void function preDelete( any entity ){
46+
announce( "ORMPreDelete", { "entity" : arguments.entity } );
47+
}
48+
49+
/**
50+
* preUpdate called by hibernate which in turn announces a coldbox interception: ORMPreUpdate
51+
*/
52+
public void function preUpdate( any entity, Struct oldData = {} ){
53+
announce(
54+
"ORMPreUpdate",
55+
{
56+
"entity" : arguments.entity,
57+
"oldData" : arguments.oldData
58+
}
59+
);
60+
}
61+
62+
/**
63+
* postUpdate called by hibernate which in turn announces a coldbox interception: ORMPostUpdate
64+
*/
65+
public void function postUpdate( any entity ){
66+
announce( "ORMPostUpdate", { "entity" : arguments.entity } );
67+
}
68+
69+
/**
70+
* preInsert called by hibernate which in turn announces a coldbox interception: ORMPreInsert
71+
*/
72+
public void function preInsert( any entity ){
73+
announce( "ORMPreInsert", { "entity" : arguments.entity } );
74+
}
75+
76+
/**
77+
* postInsert called by hibernate which in turn announces a coldbox interception: ORMPostInsert
78+
*/
79+
public void function postInsert( any entity ){
80+
announce( "ORMPostInsert", { "entity" : arguments.entity } );
81+
}
82+
83+
/**
84+
* preSave called by ColdBox Base service before save() calls
85+
*/
86+
public void function preSave( any entity ){
87+
announce( "ORMPreSave", { "entity" : arguments.entity } );
88+
}
89+
90+
/**
91+
* postSave called by ColdBox Base service after transaction commit or rollback via the save() method
92+
*/
93+
public void function postSave( any entity ){
94+
announce( "ORMPostSave", { "entity" : arguments.entity } );
95+
}
96+
97+
/**
98+
* Called before the session is flushed.
99+
*/
100+
public void function preFlush( any entities ){
101+
announce( "ORMPreFlush", { "entities" : arguments.entities } );
102+
}
103+
104+
/**
105+
* Called after the session is flushed.
106+
*/
107+
public void function postFlush( any entities ){
108+
announce( "ORMPostFlush", { "entities" : arguments.entities } );
109+
}
110+
111+
/**
112+
* postNew called by ColdBox which in turn announces a coldbox interception: ORMPostNew
113+
*/
114+
public void function postNew( any entity, any entityName ){
115+
var args = { "entity" : arguments.entity, "entityName" : "" };
116+
117+
// Do we have an incoming name
118+
if ( !isNull( arguments.entityName ) && len( arguments.entityName ) ) {
119+
args.entityName = arguments.entityName;
120+
}
121+
122+
// If we don't have the entity name, then look it up
123+
if ( !len( args.entityName ) ) {
124+
// Short-cut discovery via ActiveEntity
125+
if ( structKeyExists( arguments.entity, "getEntityName" ) ) {
126+
args.entityName = arguments.entity.getEntityName();
127+
} else {
128+
// Long Discovery
129+
var md = getMetadata( arguments.entity );
130+
var annotations = md.keyExists( "annotations" ) ? md.annotations : md;
131+
args.entityName = (
132+
annotations.keyExists( "entityName" ) ? annotations.entityName : listLast( md.name, "." )
133+
);
134+
}
135+
}
136+
137+
// Process the announcement
138+
announce( "ORMPostNew", args );
139+
}
140+
141+
/**
142+
* Get the system Event Manager
143+
*/
144+
public any function getEventManager(){
145+
return getWireBox().getEventManager();
146+
}
147+
148+
/**
149+
* process entity injection
150+
*
151+
* @entityName the entity to process, we use hash codes to identify builders
152+
* @entity The entity object
153+
*
154+
* @return The processed entity
155+
*/
156+
public function processEntityInjection( required entityName, required entity ){
157+
var ormSettings = getController().getConfigSettings().modules[ "cborm" ].settings;
158+
var injectorInclude = ormSettings.injection.include;
159+
var injectorExclude = ormSettings.injection.exclude;
160+
161+
// Enabled?
162+
if ( NOT ormSettings.injection.enabled ) {
163+
return arguments.entity;
164+
}
165+
166+
// Include,Exclude?
167+
if (
168+
( len( injectorInclude ) AND listContainsNoCase( injectorInclude, arguments.entityName ) )
169+
OR
170+
( len( injectorExclude ) AND NOT listContainsNoCase( injectorExclude, arguments.entityName ) )
171+
OR
172+
( NOT len( injectorInclude ) AND NOT len( injectorExclude ) )
173+
) {
174+
// Process DI
175+
getWireBox().autowire( target = arguments.entity, targetID = "ORMEntity-#arguments.entityName#" );
176+
}
177+
178+
return arguments.entity;
179+
}
180+
181+
/**
182+
* Lazy loading of the ORM utility according to the CFML engine you are on
183+
*
184+
* @return cborm.models.util.IORMUtil
185+
*/
186+
private function getOrm(){
187+
if ( isNull( variables.orm ) ) {
188+
variables.orm = new cborm.models.util.ORMUtilFactory().getORMUtil();
189+
}
190+
return variables.orm;
191+
}
192+
193+
}

test-harness/Application.cfc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ component {
6969
automanageSession : false,
7070
flushAtRequestEnd : false,
7171
eventhandling : true,
72-
eventHandler : server.keyExists( "coldfusion" ) ? "cborm.models.ACFEventHandler" : "cborm.models.EventHandler",
72+
eventHandler : server.keyExists( "boxlang" ) ? "cborm.models.BXEventHandler" : "cborm.models.EventHandler",
7373
skipcfcWithError : false
7474
};
7575

test-harness/tests/Application.cfc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
cacheProvider : "ConcurrentHashMap",
4343
flushAtRequestEnd : false,
4444
eventhandling : true,
45-
eventHandler : server.keyExists( "coldfusion" ) ? "cborm.models.ACFEventHandler" : "cborm.models.EventHandler",
45+
eventHandler : server.keyExists( "boxlang" ) ? "cborm.models.BXEventHandler" : "cborm.models.EventHandler",
4646
skipcfcWithError : false,
4747
saveMapping : false,
4848
// BoxLang Config Keys - The aliases above are only handled by the cfml compat module

0 commit comments

Comments
 (0)