-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathModuleConfig.cfc
More file actions
166 lines (150 loc) · 6.02 KB
/
Copy pathModuleConfig.cfc
File metadata and controls
166 lines (150 loc) · 6.02 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
component {
this.name = "quick";
this.author = "Eric Peterson";
this.webUrl = "https://github.com/coldbox-modules/quick";
this.dependencies = [ "qb", "str", "mementifier" ];
this.cfmapping = "quick";
function configure() {
settings = {
"defaultGrammar" : "AutoDiscover@qb",
"defaultQueryOptions" : {},
"parallelEagerLoading" : false,
"parallelEagerLoadingExecutor" : "",
"parallelEagerLoadingMaxThreads" : 4,
"parallelEagerLoadingTimeout" : 60000,
"preventDuplicateJoins" : true,
"preventLazyLoading" : false,
"automaticTimestamps" : true,
"refreshOnSaveFallback" : true,
"lazyLoadingViolationCallback" : ( entity, relationName ) => {
throw(
type = "QuickLazyLoadingException",
message = "Attempted to lazy load the [#arguments.relationName#] relationship on the entity [#arguments.entity.mappingName()#] but lazy loading is disabled. This is usually caused by the N+1 problem and is a sign that you are missing an eager load."
);
},
"metadataCache" : {
"name" : "quickMeta",
"provider" : "coldbox.system.cache.providers.CacheBoxColdBoxProvider",
"properties" : {
"objectDefaultTimeout" : 0, // no timeout
"useLastAccessTimeouts" : false, // no last access timeout
"maxObjects" : 300,
"objectStore" : "ConcurrentStore"
}
}
};
interceptorSettings = {
customInterceptionPoints : [
"quickInstanceReady",
"quickPreLoad",
"quickPostLoad",
"quickPostReplicate",
"quickPreSave",
"quickPostSave",
"quickPreInsert",
"quickPostInsert",
"quickPreUpdate",
"quickPostUpdate",
"quickPreDelete",
"quickPostDelete",
"quickRelationshipLoaded"
]
};
binder.map( "quick.models.BaseEntity" ).to( "#moduleMapping#.models.BaseEntity" );
binder
.map( "EntityDefinitionRegistry@quick" )
.to( "#moduleMapping#.models.EntityDefinitionRegistry" )
.asSingleton();
binder.getInjector().registerDSL( "quickService", "#moduleMapping#.dsl.QuickServiceDSL" );
}
function onLoad() {
variables.ownsParallelEagerLoadExecutor = false;
if ( settings.parallelEagerLoading ) {
configureParallelEagerLoading();
}
binder
.map( alias = "QuickQB@quick", force = true )
.to( "#moduleMapping#.models.QuickQB" )
.initArg( name = "grammar", dsl = settings.defaultGrammar )
.initArg( name = "preventDuplicateJoins", value = settings.preventDuplicateJoins )
.initArg( name = "defaultOptions", value = settings.defaultQueryOptions )
.initArg( name = "utils", dsl = "QueryUtils@qb" )
.initArg( name = "returnFormatterRegistry", ref = "ReturnFormatterRegistry@qb" )
.initArg(
name = "validateDuplicateSelectColumns",
dsl = "coldbox:moduleSettings:qb:validateDuplicateSelectColumns"
)
.initArg(
name = "validateQueryExecuteReturnType",
dsl = "coldbox:moduleSettings:qb:validateQueryExecuteReturnType"
)
.initArg( name = "collectQueryLog", dsl = "coldbox:moduleSettings:qb:collectQueryLog" )
.initArg( name = "sqlCommenter", ref = "ColdBoxSQLCommenter@qb" )
.initArg( name = "returnFormat", value = "array" );
if ( isSimpleValue( settings.metadataCache ) ) {
settings.metadataCache = { "name" : settings.metadataCache };
}
if ( settings.metadataCache.name != "quickMeta" ) {
binder.map( "cachebox:quickMeta" ).toDSL( "cachebox:#settings.metadataCache.name#" );
} else {
wirebox.getCachebox().createCache( argumentCollection = settings.metadataCache );
}
}
private void function configureParallelEagerLoading() {
var asyncManager = wirebox.getInstance( "AsyncManager@coldbox" );
if ( trim( settings.parallelEagerLoadingExecutor ) == "" ) {
settings.parallelEagerLoadingExecutor = "quick-parallel-eager-loading";
if ( !asyncManager.hasExecutor( settings.parallelEagerLoadingExecutor ) ) {
asyncManager.newExecutor(
name = "quick-parallel-eager-loading",
type = "fixed",
threads = max( 1, int( settings.parallelEagerLoadingMaxThreads ) ),
loadAppContext = true
);
variables.ownsParallelEagerLoadExecutor = true;
}
} else if ( !asyncManager.hasExecutor( settings.parallelEagerLoadingExecutor ) ) {
throw(
type = "QuickParallelEagerLoadingExecutorNotFound",
message = "The configured parallel eager-loading executor [#settings.parallelEagerLoadingExecutor#] is not registered with ColdBox's AsyncManager."
);
}
var parallelExecutorMaxThreads = asyncManager
.getExecutor( settings.parallelEagerLoadingExecutor )
.getMaximumPoolSize();
if ( parallelExecutorMaxThreads <= 0 || parallelExecutorMaxThreads >= 2147483647 ) {
throw(
type = "QuickParallelEagerLoadingExecutorNotBounded",
message = "The configured parallel eager-loading executor [#settings.parallelEagerLoadingExecutor#] must have a bounded maximum pool size."
);
}
}
function onUnload() {
if ( wirebox.containsInstance( "EntityDefinitionRegistry@quick" ) ) {
wirebox.getInstance( "EntityDefinitionRegistry@quick" ).clear();
}
if ( variables.ownsParallelEagerLoadExecutor ) {
var asyncManager = wirebox.getInstance( "AsyncManager@coldbox" );
if ( asyncManager.hasExecutor( settings.parallelEagerLoadingExecutor ) ) {
asyncManager.deleteExecutor( settings.parallelEagerLoadingExecutor );
}
}
var cacheBox = wirebox.getCachebox();
if ( cacheBox.cacheExists( settings.metadataCache.name ) ) {
cacheBox.getCache( settings.metadataCache.name ).clearAll();
}
}
/**
* This interceptor ensures that the `_mapping` property for a Quick entity
* is correctly set to the mapping used in WireBox.
*
* @event The current request context
* @interceptData The intercept data for `afterInstanceAutowire`.
* { mapping, target, targetID, injector }
*/
function beforeInstanceAutowire( event, interceptData ) {
if ( structKeyExists( interceptData.target, "isQuickEntity" ) ) {
interceptData.target.set_mapping( interceptData.targetID );
}
}
}