-
Notifications
You must be signed in to change notification settings - Fork 5
/
ModuleConfig.cfc
158 lines (136 loc) · 3.97 KB
/
ModuleConfig.cfc
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
/**
*
* <strong>CFMongoDB Module Configuration</strong>
*
* <p>An Active Entity Module for MongoDB</p>
*
* @author Jon Clausen <[email protected]>
*
* @link https://github.com/jclausen/cbmongodb
*/
component {
// Module Properties
this.title = "CBMongoDB";
this.author = "Jon Clausen<[email protected]>";
this.webURL = "https://github.com/jclausen/cbmongodb";
this.description = "Coldbox SDK and Virtual Entity Service for MongoDB";
// If true, looks for views in the parent first, if not found, then in the module. Else vice-versa
this.viewParentLookup = false;
// If true, looks for layouts in the parent first, if not found, then in module. Else vice-versa
this.layoutParentLookup = false;
// Module Entry Point
this.entryPoint = "cbmongodb";
// Model Namespace to use
this.modelNamespace = "cbmongodb";
// Auto Map Models Directory
this.autoMapModels = false;
// CF Mapping to register
this.cfmapping = "cbmongodb";
// Module Dependencies to be loaded in order
this.dependencies = [ "cbjavaloader" ];
function configure(){
settings = {
//The default hosts
hosts = [
{
serverName:'127.0.0.1',
serverPort:'27017'
}
],
//the default client options
clientOptions = {
//The connection timeout in ms (if omitted, the timeout is 30000ms)
"connectTimeout":2000
},
//The default database
db = "test",
//whether to permit viewing of the API documentation
permitDocs = true,
//whether to permit unit tests to run
permitTests = true,
//whether to permit generic API access (future implementation)
permitAPI = true,
//GridFS settings - this key is omitted by default
GridFS = {
"imagestorage":{
//whether to store the cfimage metadata
"metadata":true,
//the max allowed width of images in the GridFS store
"maxwidth":1000,
//the max allowed height of images in the GridFS store
"maxheight":1000,
//The path within the site root with trailing slash to use for resizing images (required if maxheight or max width are specified)
"tmpDirectory":"/cbmongodb/tmp/"
}
}
}
// Custom Declared Interceptors
interceptors = [
{ "class" : "cbmongodb.interceptors.MongoDB" }
];
// Custom Declared Points
interceptorSettings = {
customInterceptionPoints : [
"MongoDBPostLoad",
"MongoDBPreInsert",
"MongoDBPreSave",
"MongoDBPostSave"
]
};
}
/**
* Fired when the module is registered and activated.
*/
function onLoad(){
//ensure cbjavaloader is an activated module
if(!Wirebox.getColdbox().getModuleService().isModuleActive('cbjavaloader')){
Wirebox.getColdbox().getModuleService().reload('cbjavaloader');
}
// load MongoDB jars
wirebox.getInstance("loader@cbjavaloader").appendPaths(expandPath("/cbmongodb") & "/lib");
/**
* Main Configuration Object Singleton
**/
binder.map("MongoConfig@cbmongodb")
.to('#moduleMapping#.models.Mongo.Config')
.initWith(configStruct=variables.settings)
.threadSafe()
.asSingleton();
/**
* Utility Classes
**/
//models.Mongo.Util
binder.map("MongoUtil@cbmongodb")
.to("#moduleMapping#.models.Mongo.Util")
.asSingleton();
//indexer
binder.map("MongoIndexer@cbmongodb")
.to("#moduleMapping#.models.Mongo.Indexer")
.asSingleton();
/**
* Manual Instantiation Instances
**/
//models.Mongo.Collection
binder.map("MongoCollection@cbmongodb")
.to('#moduleMapping#.models.Mongo.Collection')
.noInit();
//models.Mongo.GridFS
binder.map("GridFS@cbmongodb")
.to('#moduleMapping#.models.Mongo.GridFS');
/**
* The Mongo Client Singleton
**/
binder.map( "MongoClient@cbmongodb" )
.to( "#moduleMapping#.models.Mongo.Client" )
.threadSafe()
.asSingleton();
}
/**
* Fired when the module is unregistered and unloaded
*/
function onUnload(){
if(Wirebox.containsInstance("MongoClient@cbmongodb")){
Wirebox.getInstance("MongoClient@cbmongodb").close();
}
}
}