Resources



Sample Code and Libraries

Small and Simple, SimpleDB Java Library [updated July 23, 2009]

Click for a printer friendly version of this document Printer Friendly Save to del.icio.us
 

Very simple, easy to follow and modify Java code for SimpleDB. Does not depend on any third party libraries.

Submitted By: ianschumacher  
AWS Products Used: Amazon SimpleDB
Language(s): Java
License: Apache License 2.0

Earlier I had written a very small single Java file for accessing and querying SimpleDB. This is an update to that. This version updates the signing mechanism to latest spec, parses and processes the XML. The code assumes a single value per key model, which allows it to use standard maps to represent tuples and tables, simplifying usage.

Example:

SDB sdb = new SDB("YOUR KEY HERE", "YOUR SECRET HERE");
sdb.createDomain("test");
System.out.println(Arr.toString(sdb.listDomains()));
TreeMap map = new TreeMap();
map.put("id", "item1");
map.put("a", "av");
map.put("b", "bv");
sdb.putAttributes("test", map);
System.out.println(sdb.getAttributes("test", "item1"));
System.out.println(Arr.toString(sdb.select("select * from test")));
map = new TreeMap();
map.put("id", "item1");
sdb.deleteAttributes("test", map);
System.out.println(sdb.getAttributes("test", "item1"));
sdb.deleteDomain("test");
System.out.println(Arr.toString(sdb.listDomains()));


This results in the output:
{test}
{a=av, b=bv, id=item1}
{{a=av, b=bv, id=item1}}
{id=item1}
{}

Discussion

The 5 most recent discussion messages. View full discussion.

Macro books
Posts: 7
Registered: 9/28/07
'Simple' SimpleDB code in single Java file/class (240 lines)
Posted: Mar 29, 2008 3:54 AM PDT
 
  Click to reply to this thread Reply

Interesting, do you have any use cases, thanks in advance,

A. R. Williamson
RealName(TM)
Posts: 20
Registered: 2/8/06
Re: 'Simple' SimpleDB code in single Java file/class (240 lines)
Posted: Jun 26, 2008 2:08 AM PDT   in response to: Macro books
 
  Click to reply to this thread Reply

This is a great class, and illustrates the power that Amazon can offer and how you can really utilise this power without over complicating the problem.

I love the simplicity of this class and I applaud the author for illustrating how easy it is to use.

I have since added to this class, with some helper methods you can access here:

http://alan.blog-city.com/simpleclass_amazondb.htm


A. R. Williamson
RealName(TM)
Posts: 20
Registered: 2/8/06
Re: 'Simple' SimpleDB code in single Java file/class (240 lines)
Posted: Oct 7, 2008 4:21 AM PDT   in response to: A. R. Williamson
 
  Click to reply to this thread Reply

Carrying on the tradition of this wonderfully simple class, i have made some further updates to include more of the SimpleDB API.

It includes a very simple in-class XML parser that will convert the strings into something useful. Does not use SAX or DOM.

In the same spirit, this class requires no external dependencies or even an XML parser!

http://alan.blog-city.com/simpleclass_amazondb_oct2008.htm


Reviews
Create Review Write a Review
Be the first to review this.
Welcome, Guest Help
Login Login