There are many ways to integrate an Android app with an Amazon Web Services database. This presentation explores some of those possibilities and the choices I made for my app using the AWS SimpleDB NoSQL cloud database.
6. Whoa… Non – Relational ??? From WikiMedia Commons
7.
8. Android to Amazon Database Model Android Phone For UI and Display Amazon SimpleDB Cloud For Database Heavy Lifting Data Request Data Response Each Does What It Does Best ! Images From HTC and WikiMedia
12. Drilling For Oil Amount of Data Generated Depends On How Deep the Well is Drilled A B C D
13. Example NoSQL Row For Geologic Formation Names and Depths Item Key “ 05-10123”, “BLAINE”, “1464”,”ATOKA”,”4744”,”MORROW”,”4854” Name3 Name2 Name1 Value1 Value2 Value3
14. Coding the Connection From Android Image From http://www.vpnchoice.com/blog/wp-content/uploads/2011/06/android-vpn-300x187.jpg
15. Connecting to Amazon SimpleDB private static AmazonSimpleDB sdb = null; public static AmazonSimpleDB getInstance() { if ( sdb == null ) { // pass in the authenication credentials sdb = new AmazonSimpleDBClient( AWSDemo.credentials ); // set the node we want to use sdb.setEndpoint("sdb.us-west-1.amazonaws.com"); } return sdb; }
16. Creating SimpleDB Domains From Android public void createDomain(String domainName) { sdb.createDomain( new CreateDomainRequest(domainName)); }
17. Inserting Records From Android // each row is keyed with a “replaceable” item id followed by // attributes i.e. name / value pairs // construct a list of items to be inserted List<ReplaceableItem> dataList = new ArrayList<ReplaceableItem>(); // populate the list using the item id and the attribute name / value pairs dataList.add( new ReplaceableItem(“05-123”).withAttributes( new ReplaceableAttribute(DBFields. STATE , “CO”, true ), new ReplaceableAttribute(DBFields. COUNTY , “Weld”, true ), new ReplaceableAttribute(DBFields. DRILLING_DATE , “05-11-2011”, true )); // batch insert the list into the SimpleDB database sdb.batchPutAttributes( new BatchPutAttributesRequest( “my_domain” , dataList ));
18. Retrieving Data From Amazon // build your SQL select statement String selectExpression = "select * from " + domain + " where itemName() = '“05-123’”; // construct a select request SelectRequest selectRequest = new SelectRequest(selectExpression); // retrieve a list of matching items (records) List<Item> itemList = sdb.select(selectRequest).getItems(); // loop through each record and extract the attributes from each item for ( int i = 0; i < itemList.size(); i++) { Item item = (Item) itemList.get(i); ArrayList<Attribute> attributeList = (ArrayList<Attribute>) item.getAttributes(); }
19. Question: Since Android Devices Can Use the Internal SQLite Database… When I Would I Use the Internal Database and When Would I Use the Amazon Cloud Database ?