-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SimpleDB.cfc
306 lines (258 loc) · 8.18 KB
/
SimpleDB.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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
/**
*
* @file /f/dev/amazon/SimpleDB.cfc
* @author Manuel H. Mueller [ Onko ] mueller.m.h@gmail.com
* @description
*
*/
component output="true" displayname="SimpleDB" extends="Connector" {
property name="endpoint";
property name="awsAccessKeyID";
property name="awsAccessSecret";
property name="requestMethod";
property name="version";
public function init(
required string awsAccessKeyId,
required string awsAccessSecret,
string endpoint='sdb.amazonaws.com'
){
this.awsAccessKeyId=awsAccessKeyId;
this.awsAccessSecret=awsAccessSecret;
this.endpoint=endpoint;
this.requestMethod='no-header';
this.version='2009-04-15';
return this;
}
public array function ListDomains(
numeric MaxNumberOfDomains=0,
string NextToken=''
)
{
var body = "Action=ListDomains";
if(val(MaxNumberOfDomains))
body &='&MaxNumberOfDomains=#trim(MaxNumberOfDomains)#';
if(len(trim(NextToken)))
body &='&NextToken=#NextToken#';
var result = makeRequest (
endpoint=this.endpoint,
awsAccessKeyID=this.awsAccessKeyID,
awsAccessSecret=this.awsAccessSecret,
body=body,
requestMethod=this.requestMethod,
version=this.version
);
var returnArray=[];
var SearchResult = getResultNode(result.content,'DomainName');
for(item in SearchResult)
{
ArrayAppend(returnArray,item.XmlText);
}
return returnArray;
}
public boolean function CreateDomain(required string DomainName )
{
var body = "Action=CreateDomain&DomainName=" & trim(DomainName);
var result = makeRequest (
endpoint=this.endpoint,
awsAccessKeyID=this.awsAccessKeyID,
awsAccessSecret=this.awsAccessSecret,
body=body,
requestMethod=this.requestMethod,
version=this.version
);
if(result.status == 200)
return true;
return false;
}
public boolean function DeleteDomain(required string DomainName )
{
var body = "Action=DeleteDomain&DomainName=" & trim(DomainName);
var result = makeRequest (
endpoint=this.endpoint,
awsAccessKeyID=this.awsAccessKeyID,
awsAccessSecret=this.awsAccessSecret,
body=body,
requestMethod=this.requestMethod,
version=this.version
);
if(result.status == 200)
return true;
return false;
}
public struct function DomainMetadata(required string DomainName )
{
var body = "Action=DomainMetadata&DomainName=" & trim(DomainName);
var result = makeRequest (
endpoint=this.endpoint,
awsAccessKeyID=this.awsAccessKeyID,
awsAccessSecret=this.awsAccessSecret,
body=body,
requestMethod=this.requestMethod,
version=this.version
);
if(result.status == 200)
return {
itemCount: getResultNodeValue(result.content,'ItemCount'),
ItemNamesSizeBytes: getResultNodeValue(result.content,'ItemNamesSizeBytes'),
AttributeNameCount: getResultNodeValue(result.content,'AttributeNameCount'),
AttributeNamesSizeBytes: getResultNodeValue(result.content,'AttributeNamesSizeBytes'),
AttributeValueCount: getResultNodeValue(result.content,'AttributeValueCount'),
AttributeValuesSizeBytes: getResultNodeValue(result.content,'AttributeValuesSizeBytes'),
Timestamp: getResultNodeValue(result.content,'Timestamp')
}
return {};
}
public string function PutAttributes(required string DomainName, required string itemName, required array attr)
{
var body = "Action=PutAttributes&DomainName=" & trim(DomainName) & "&ItemName=" & itemName ;
loop from="1" to="#arrayLen(attr)#" index="i"
{
body &= "&Attribute." & i & ".Name=" & trim(attr[i].name);
body &= "&Attribute." & i & ".Value=" & trim(attr[i].value);
body &= "&Attribute." & i & ".Replace=true";
}
var result = makeRequest (
endpoint=this.endpoint,
awsAccessKeyID=this.awsAccessKeyID,
awsAccessSecret=this.awsAccessSecret,
body=body,
requestMethod=this.requestMethod,
version=this.version
);
sleep(4);
if(result.status == 200)
return getResultNodeValue(result.content,'RequestId');
return '';
}
public string function BatchPutAttributes(required string DomainName, required array items)
{
var body = "Action=BatchPutAttributes&DomainName=" & trim(DomainName);
loop from="1" to="#arrayLen(items)#" index="i"
{
body &= "&Item." & i & ".ItemName=" & trim(items[i].name);
loop from="1" to="#arrayLen(items.attr)#" index="iattr"
{
body &= "&Attribute." & iattr & ".Name=" & trim(items.attr[iattr].name);
body &= "&Attribute." & iattr & ".Value=" & trim(items.attr[iattr].value);
body &= "&Attribute." & iattr & ".Replace=true";
}
}
var result = makeRequest (
endpoint=this.endpoint,
awsAccessKeyID=this.awsAccessKeyID,
awsAccessSecret=this.awsAccessSecret,
body=body,
requestMethod=this.requestMethod,
version=this.version
);
if(result.status == 200)
return getResultNodeValue(result.content,'RequestId');
return '';
}
public struct function GetAttributes( required string DomainName, required string ItemName, string AttributeName='', boolean ConsistentRead=false)
{
var body = "Action=GetAttributes&DomainName=" & DomainName & "&ItemName=" & itemName ;
if(len(AttributeName))
body &= '&AttributeName=' & trim(AttributeName);
if(ConsistentRead)
body &= '&ConsistentRead=true';
var result = makeRequest (
endpoint=this.endpoint,
awsAccessKeyID=this.awsAccessKeyID,
awsAccessSecret=this.awsAccessSecret,
body=body,
requestMethod=this.requestMethod,
version=this.version
);
var resultArray = getResultNode(result.content,'GetAttributesResult');
stItem = {};
for(item in resultArray)
{
stItem['itemName']=ItemName;
for(attr in item.xmlChildren)
{
if(attr.xmlName == 'Attribute')
stItem[attr.name.xmlText]=attr.value.xmlText;
}
}
return stItem;
}
public array function Select( required string QueryString, string NextToken='', boolean ConsistentRead=false)
{
var body = "Action=Select&SelectExpression=" & trim(QueryString);
if(len(NextToken))
body &= '&NextToken=' & trim(NextToken);
if(ConsistentRead)
body &= '&ConsistentRead=true';
var result = makeRequest (
endpoint=this.endpoint,
awsAccessKeyID=this.awsAccessKeyID,
awsAccessSecret=this.awsAccessSecret,
body=body,
requestMethod=this.requestMethod,
version=this.version
);
var resultArray = getResultNode(result.content,'Item');
var returnArray = []
for(item in resultArray)
{
stItem = {};
stItem['itemName']=item.xmlText;
for(attr in item.xmlChildren)
{
if(attr.xmlName == 'Attribute')
stItem[attr.name.xmlText]=attr.value.xmlText;
if(attr.xmlName == 'Name')
stItem['itemName']=attr.xmlText;
}
ArrayAppend(returnArray,stItem);
}
return returnArray;
}
public boolean function DeleteAttributes(required DomainName, string ItemName, array attr=[])
{
var body = "Action=DeleteAttributes&DomainName=" & trim(DomainName) & "&ItemName=" & trim(ItemName) ;
loop from="1" to="#arrayLen(attr)#" index="i"
{
body &= "&Attribute." & i & ".Name=" & trim(attr[i].name);
body &= "&Attribute." & i & ".Value=" & trim(attr[i].value);
body &= "&Attribute." & i & ".Replace=true";
}
var result = makeRequest (
endpoint=this.endpoint,
awsAccessKeyID=this.awsAccessKeyID,
awsAccessSecret=this.awsAccessSecret,
body=body,
requestMethod=this.requestMethod,
version=this.version
);
if(result.status == 200)
return true;
return false;
}
public boolean function BatchDeleteAttributes(required string DomainName, required array items)
{
var body = "Action=BatchDeleteAttributes&DomainName=" & trim(DomainName);
loop from="1" to="#arrayLen(items)#" index="i"
{
body &= "&Item." & i & ".ItemName=" & trim(items[i].name);
loop from="1" to="#arrayLen(items.attr)#" index="iattr"
{
body &= "&Attribute." & iattr & ".Name=" & trim(items.attr[iattr].name);
body &= "&Attribute." & iattr & ".Value=" & trim(items.attr[iattr].value);
body &= "&Attribute." & iattr & ".Replace=true";
}
}
var result = makeRequest (
endpoint=this.endpoint,
awsAccessKeyID=this.awsAccessKeyID,
awsAccessSecret=this.awsAccessSecret,
body=body,
requestMethod=this.requestMethod,
version=this.version
);
if(result.status == 200)
return true;
return false;
}
}