-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfactory.cfc
135 lines (104 loc) · 3.54 KB
/
factory.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
component accessors="true" output="false" {
property struct factoryConfig;
public component function init(struct config={}) {
setFactoryConfig(arguments.config);
validateConfig();
return this;
}
public cfmlDataMapper.model.factory.data function getFactory() {
return getBeanFactory().getBean("DataFactory");
}
public component function getBeanFactory() {
_get_framework_one().onRequestStart("");
return _get_framework_one().getDefaultBeanFactory();
}
private component function _get_framework_one() {
if ( !structKeyExists( request, '_framework_one' ) ) {
request._framework_one = new framework.one(getFrameworkConfig());
}
return request._framework_one;
}
private struct function getConstants() {
var config = getFactoryConfig();
var constants = {
dsn = config.dsn,
dataFactoryConfig = {
serverType = config.serverType
}
};
if ( config.keyExists("constants") ) {
constants.append(config.constants);
}
return constants;
}
private struct function getFactoryConfig() {
return variables.factoryConfig;
}
private struct function getFrameworkConfig() {
return {
applicationKey = 'framework.one',
usingSubsystems = true,
diConfig = {
constants = getConstants()
},
diLocations = getLocations(),
reloadApplicationOnEveryRequest = getFactoryConfig().reloadApplicationOnEveryRequest
};
}
private string function getLocations() {
var locations = "/cfmlDataMapper/model";
locations = listAppend(locations, getFactoryConfig().locations);
return locations;
}
private void function validateConfig() {
var config = getFactoryConfig();
if ( !structKeyExists(config, "dsn") || !len(config.dsn) ) {
throw("The cfmlDataMapper Factory requires the dsn config variable.");
}
if ( !structKeyExists(config, "locations") || !len(config.locations) ) {
throw("The cfmlDataMapper Factory requires the locations config variable.");
}
param name="config.reloadApplicationOnEveryRequest" default="false";
param name="config.serverType" default="";
setFactoryConfig(config);
}
// data mapper function passthroughs
public component function get() {
return getFactory().get( argumentCollection=arguments );
}
public array function getBeanArrayProperties() {
return getFactory().getBeanArrayProperties( argumentCollection=arguments );
}
public struct function getBeanMap() {
return getFactory().getBeanMap( argumentCollection=arguments );
}
public array function getBeansFromQuery() {
return getFactory().getBeansFromQuery( argumentCollection=arguments );
}
public struct function getBeansFromQueryAsStruct() {
return getFactory().getBeansFromQueryAsStruct( argumentCollection=arguments );
}
public array function getBeansFromArray() {
return getFactory().getBeansFromArray( argumentCollection=arguments );
}
public struct function getResultStruct() {
return getBeanFactory().getUtilityService().getResultStruct( argumentCollection=arguments );
}
public boolean function hasBean() {
return getFactory().hasBean( argumentCollection=arguments );
}
public array function list() {
return getFactory().list( argumentCollection=arguments );
}
public array function listWithProperties() {
return getFactory().listWithProperties( argumentCollection=arguments );
}
public void function setFactoryConfig(factoryConfig){
variables.factoryConfig = arguments.factoryConfig;
}
// fw1 functionality to use with beans
public void function populate() {
_get_framework_one().onRequestStart("");
return _get_framework_one().populate( argumentCollection=arguments );
}
}