Repository navigation
Expand file tree
/
Copy pathModuleConfig.bx
More file actions
117 lines (107 loc) · 3.54 KB
/
Copy pathModuleConfig.bx
File metadata and controls
117 lines (107 loc) · 3.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/**
* Copyright Since 2005 ColdBox Framework by Luis Majano and Ortus Solutions, Corp
* www.ortussolutions.com
* ---
* cborm: ColdBox ORM extensions for BoxLang, built on the bx-orm module (Hibernate 7).
*/
class {
// Module Properties
this.title = "cborm";
this.author = "Ortus Solutions";
this.webURL = "https://www.ortussolutions.com";
this.description = "ColdBox ORM extensions for BoxLang and the bx-orm module";
this.modelNamespace = "cborm";
this.cfmapping = "cborm";
this.dependencies = [ "cbvalidation", "mementifier" ];
// The criteria events bx-orm announces on the BoxLang runtime, re-announced to ColdBox interceptors
variables.CRITERIA_EVENTS = [
"onCriteriaBuilderAddition",
"beforeCriteriaBuilderList",
"afterCriteriaBuilderList",
"beforeCriteriaBuilderCount",
"afterCriteriaBuilderCount",
"beforeCriteriaBuilderGet",
"afterCriteriaBuilderGet"
];
variables.SETTING_DEFAULTS = {
// Resource Settings
resources : {
// Enable the ORM Resource Event Loader
eventLoader : false,
// Prefix to use on all the registered pre/post{Entity}{Action} events
eventPrefix : "",
// Pagination max rows
maxRows : 25,
// Pagination max row limit: 0 = no limit
maxRowsLimit : 500
},
// WireBox Injection Bridge
injection : { enabled : true, include : "", exclude : "" }
};
/**
* Configure the module: settings, the entityService WireBox DSL and the custom interception points.
*/
function configure(){
// cborm Settings
variables.settings = structCopy( variables.SETTING_DEFAULTS );
// Register Custom DSL, don't map it because it is too late, mapping DSLs are only good by the parent app
variables.controller.getWireBox().registerDSL(
namespace = "entityService",
path = "#moduleMapping#.dsl.OrmDsl"
);
// Custom Declared Points
variables.interceptorSettings = {
customInterceptionPoints : duplicate( variables.CRITERIA_EVENTS ).append( [
// ORM Service Events
"beforeOrmExecuteQuery",
"afterOrmExecuteQuery",
// ORM Bridge Events
"ORMPostNew",
"ORMPreLoad",
"ORMPostLoad",
"ORMPostDelete",
"ORMPreDelete",
"ORMPreUpdate",
"ORMPostUpdate",
"ORMPreInsert",
"ORMPostInsert",
"ORMPreSave",
"ORMPostSave",
"ORMPostCommit",
"ORMPostFlush",
"ORMPreFlush"
], true )
};
// Custom Declared Interceptors
variables.interceptors = [];
}
/**
* Fired when the module is registered and activated: settings defaults, the resource event loader, and the bridge
* that re-announces bx-orm's criteria events to ColdBox interceptors.
*/
function onLoad(){
// Prepare setting defaults
variables.settings.resources.append( variables.SETTING_DEFAULTS.resources, false );
variables.settings.injection.append( variables.SETTING_DEFAULTS.injection, false );
// Are we loading the event loader
if (
variables
.settings
.resources
.eventLoader
) {
variables.wirebox.getInstance( "ResourceEventLoader@cborm" ).loadEvents();
}
// Bridge bx-orm criteria events (announced on the BoxLang runtime) to ColdBox
variables.criteriaEventBridge = new cborm.models.CriteriaEventBridge( variables.controller );
boxRegisterInterceptor( variables.criteriaEventBridge, variables.CRITERIA_EVENTS.toList() );
}
/**
* Fired when the module is unregistered and unloaded: removes the criteria event bridge.
*/
function onUnload(){
if ( !isNull( variables.criteriaEventBridge ) ) {
boxUnregisterInterceptor( variables.criteriaEventBridge, variables.CRITERIA_EVENTS.toList() );
}
}
}