Databases Reference
In-Depth Information
return myData;
}
}
SimpleDBExample.java
The example in Listing 11-2 assumes that you specify the AWS credentials in a fi le named
aws_credentials.properties . The contents of aws_credentials.properties are as follows:
accessKey =
secretKey =
The example so far demonstrates the usage of the API from a standalone Java program. If the
program were more complex than a simple standalone program, you are likely to leverage standard
Java idioms including the Java Persistence API (JPA). A few open-source options exist for using JPA
to persist to SimpleDB. SimpleJPA is one such project. SimpleJPA covers a subset of JPA, relevant in
the context of SimpleDB.
Using SimpleDB with Ruby and Python
Rails is the choice web development in the Ruby community. If you would like to use SimpleDB
with your Rails application, you wouldn't be able to simply plug SimpleDB in place of your relational
database like MySQL without any external help. However, SimpleRecord can solve much of your
problem. SimpleRecord implemented via an open-source project by the same name is available at
https://github.com/appoxy/simple_record/ . SimpleRecord is an ActiveRecord replacement for
Rails applications that would like to use Amazon SimpleDB as their persistent store.
Using SimpleRecord is easy. Installing SimpleRecord is a single-line effort:
gem install simple_record
The assumption is that you have Ruby, RubyGems, and Rails already installed and set up. The
simplest example could be as follows:
require 'simple_record'
class MyModel < SimpleRecord::Base
has_strings :key1
has_ints :key2
end
As always is the case with AWS, confi gure the AWS credentials so that you are ready to persist your
model to SimpleDB. You can confi gure AWS credentials like so:
AWS_ACCESS_KEY_ID='<aws_access_key_id>'
AWS_SECRET_ACCESS_KEY='<aws_secret_access_key>'
SimpleRecord.establish_connection(AWS_ACCESS_KEY_ID,AWS_SECRET_ACCESS_KEY)
Search WWH ::




Custom Search