My favorites | Sign in
Project Logo
             
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
# = Utilities : Amazon SimpleDB BatchPutAttributes
# Extends the right_aws gem providing support for
# Amazon SimpleDB BatchPutAttributes operation.
#
# The right_aws gem provides basic functionality to interact with Amazon
# SimpleDB, but it doesn't support BatchPutAttributes (as of version 1.10.0),
# severely limiting the upload speed that can be achieved when storing data
# into SimpleDB.
# This module adds basic support for the missing functionality.
#
# == Author
# Riccardo Govoni [battlehorse@gmail.com]
#
# == Copyright
# Copyright(c) 2009 - bayes-swarm project.
# Licensed under the GNU General Public License v2.

require 'right_aws'

module RightAws
class SdbInterface

# Add/Replace item attributes in Batch mode.
# By using Amazon SDB BatchPutAttributes rather than PutAttributes this
# method achieves a 15x-20x speed improvement when storing big quantities
# of attributes.
#
# Params:
# domain_name = DomainName
# items = {
# 'itemname' => {
# 'attributeA' => [valueA1,..., valueAN],
# ...
# 'attributeZ' => [valueZ1,..., valueZN]
# }
# }
# replace = :replace | any other value to skip replacement
#
# Returns a hash: { :box_usage, :request_id } on success or an exception on error.
#
# see: http://docs.amazonwebservices.com/AmazonSimpleDB/2007-11-07/DeveloperGuide/SDB_API_BatchPutAttributes.html
def batch_put_attributes(domain_name, items, replace = false)
params = { 'DomainName' => domain_name }
item_count = 0
items.each_pair do |item_name, attributes|
params["Item.#{item_count}.ItemName"] = item_name
pack_attributes(attributes, replace).each_pair do |attr_key, attr_value|
params["Item.#{item_count}.#{attr_key}"] = attr_value
end
item_count += 1
end
link = generate_request("BatchPutAttributes", params)
request_info( link, QSdbSimpleParser.new )
rescue Exception
on_exception
end
end
end
Show details Hide details

Change log

r480 by battlehorse on May 30, 2009   Diff
Introducing initial support and tests for
Amazon SimpleDB (as a possible alternative
to MySQL). Extension to right_aws gem to
support BatchPutAttributes for better
performance
Go to: 
Project members, sign in to write a code review

Older revisions

All revisions of this file

File info

Size: 2028 bytes, 58 lines
Hosted by Google Code