Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Data displayed on                   mobile deviceData stored in DynamoDB
@DynamoDBTable(tableName = ”UserPreference")public class UserPreference {     @DynamoDBHashKey(attributeName = "userId")  ...
// Create a clientAmazonDynamoDBClient ddb = new AmazonDynamoDBClient(creds);// Create a mapping of valuesHashMap item = n...
// create our client and mapperAmazonDynamoDBClient ddb = new     AmazonDynamoDBClient(credentials);DynamoDBMapper mapper ...
UserPreference@DynamoDBTablepublic class UserPreference {     …}                                          Prefs@DynamoDBTa...
@DynamoDBHashKey(attributeName = ”A")   Apublic int getUserId() {     return userId;}
@DynamoDBAttribute(attributeName = ”B")public String getFirstName() {     return firstName;}@DynamoDBAttribute(attributeNa...
@DynamoDBHashKey(attributeName = "userId")@DynamoDBAutoGeneratedKeypublic int getUserId() {    return userId;}UserPreferen...
A          A   A    SAVEB          B   B1          1   2
A          AB1    SAVE           B           3   !
public class ComplexObject {     @DynamoDBMarshalling(marshallerClass = Conv.class)     public ComplexType getComplex() { ...
A          C   A    SAVEB          D   BC          E   C               D               E
A          C   A    SAVEB          D   BC          E   C
A          C          A    SAVE       LOADB          D          BC          E          C                      C           ...
A          C          A    SAVE       LOADB          D          BC          E          C
PRODUCTION   DEVELOPMENT
What about iOS?
DEMO
Creating AWS Persistence Store// Registers the AWSNSIncrementalStore[NSPersistentStoreCoordinator   registerStoreClass:   ...
Creating an NSManagedObjectCheckin *checkin = (Checkin *) [NSEntityDescription   insertNewObjectForEntityForName:@"Checkin...
Loading NSManagedObject// Create a fetch requestNSFetchRequest *request = [[NSFetchRequest alloc] init];// Specify the ent...
Other Operations[managedObjectContext deleteObject:location];[managedObjectContext refreshObject:location    mergeChanges:...
tableMapper = [NSDictionary dictionaryWithObjectsAndKeys:        @"AWS-Locations", @"Location”, nil];   AWS-Locations
hashKeys = [NSDictionary dictionaryWithObjectsAndKeys:      @"locationId", @"Location”, nil];       locationId
versions = [NSDictionary dictionaryWithObjectsAndKeys:             @"version", @"Location”, nil];         A               ...
http://developer.apple.com/library/ios/#documentation/CoreData/Reference/NSMergePolicy_Class/Reference/Reference.html
[[NSNotificationCenter defaultCenter]  addObserver:self   selector:@selector(mergeDeletedObject:)     name:AWSPersistenceD...
@protocol AWSPersistenceDynamoDBIncrementalStoreDelegate                 <NSObject>@required- (AmazonCredentials *)credent...
https://forums.aws.amazon.com/http://stackoverflow.com/tags/amazon-web-serviceshttps://github.com/amazonwebservices/aws-sd...
http://aws.amazon.com/mobile/  http://aws.amazon.com/articles/3756417425850538  http://aws.amazon.com/articles/44358461315...
We are sincerely eager to hear your feedback on thispresentation and on re:Invent. Please fill out an evaluation   form wh...
MBL301 Data Persistence to Amazon Dynamodb for Mobile Apps - AWS re: Invent 2012
MBL301 Data Persistence to Amazon Dynamodb for Mobile Apps - AWS re: Invent 2012
MBL301 Data Persistence to Amazon Dynamodb for Mobile Apps - AWS re: Invent 2012
MBL301 Data Persistence to Amazon Dynamodb for Mobile Apps - AWS re: Invent 2012
MBL301 Data Persistence to Amazon Dynamodb for Mobile Apps - AWS re: Invent 2012
MBL301 Data Persistence to Amazon Dynamodb for Mobile Apps - AWS re: Invent 2012
MBL301 Data Persistence to Amazon Dynamodb for Mobile Apps - AWS re: Invent 2012
MBL301 Data Persistence to Amazon Dynamodb for Mobile Apps - AWS re: Invent 2012
MBL301 Data Persistence to Amazon Dynamodb for Mobile Apps - AWS re: Invent 2012
Upcoming SlideShare
Loading in …5
×

MBL301 Data Persistence to Amazon Dynamodb for Mobile Apps - AWS re: Invent 2012

1,791 views

Published on

Object modeling is a common practice in mobile applications. We present two methods for modeling objects backed by Amazon DynamoDB, the AWS Persistence Framework for Core Data and DynamoDBMapper. We cover the benefits and limitations of these two solutions and demonstrate sample applications built with both technologies.

  • Be the first to comment

MBL301 Data Persistence to Amazon Dynamodb for Mobile Apps - AWS re: Invent 2012

  1. 1. Data displayed on mobile deviceData stored in DynamoDB
  2. 2. @DynamoDBTable(tableName = ”UserPreference")public class UserPreference { @DynamoDBHashKey(attributeName = "userId") public int getUserId() { return userId; } @DynamoDBAttribute(attributeName = "firstName") public String getFirstName() { return firstName; } @DynamoDBAttribute(attributeName = "lastName") public String getLastName() { return lastName; }
  3. 3. // Create a clientAmazonDynamoDBClient ddb = new AmazonDynamoDBClient(creds);// Create a mapping of valuesHashMap item = new HashMap();AttributeValue userId = new AttributeValue().withN(1337);item.put("userId", userId);AttributeValue firstName = new AttributeValue().withS("Bob");item.put("firstName", firstName);AttributeValue lastName = new AttributeValue().withS("Kinney");item.put("lastName", lastName);// Put the item in DynamoDBPutItemRequest request = new PutItemRequest() .withTableName("Prefs").withItem(item);ddb.putItem(request);
  4. 4. // create our client and mapperAmazonDynamoDBClient ddb = new AmazonDynamoDBClient(credentials);DynamoDBMapper mapper = new DynamoDBMapper(ddb);// create our object, set metadataUserPreference up = new UserPreference();up.setUserId(1337);up.setFirstName(“Bob”);up.setLastName(“Kinney”);// save to Amazon DynamoDBmapper.save(up);// load the object by keyup = mapper.load(UserPreference.class, 1337);
  5. 5. UserPreference@DynamoDBTablepublic class UserPreference { …} Prefs@DynamoDBTable(tableName = ”Prefs")public class UserPreference { …}
  6. 6. @DynamoDBHashKey(attributeName = ”A") Apublic int getUserId() { return userId;}
  7. 7. @DynamoDBAttribute(attributeName = ”B")public String getFirstName() { return firstName;}@DynamoDBAttribute(attributeName = ”C")public String getLastName() { B return lastName;} C@DynamoDBIgnorepublic String getFullName() { return firstName + “ “ + lastName;}
  8. 8. @DynamoDBHashKey(attributeName = "userId")@DynamoDBAutoGeneratedKeypublic int getUserId() { return userId;}UserPreference up = new UserPreference();up.setUserId(1337);up.setFirstName(“Bob”);up.setLastName(“Kinney”);
  9. 9. A A A SAVEB B B1 1 2
  10. 10. A AB1 SAVE B 3 !
  11. 11. public class ComplexObject { @DynamoDBMarshalling(marshallerClass = Conv.class) public ComplexType getComplex() { return complex; }}public class Conv implements DynamoDBMarshaller<ComplexType> { public String marshall(ComplexType value) { … } public ComplexType unmarshall(Class<ComplexType> ct, String value) { … }}
  12. 12. A C A SAVEB D BC E C D E
  13. 13. A C A SAVEB D BC E C
  14. 14. A C A SAVE LOADB D BC E C C D E
  15. 15. A C A SAVE LOADB D BC E C
  16. 16. PRODUCTION DEVELOPMENT
  17. 17. What about iOS?
  18. 18. DEMO
  19. 19. Creating AWS Persistence Store// Registers the AWSNSIncrementalStore[NSPersistentStoreCoordinator registerStoreClass: [AWSPersistenceDynamoDBIncrementalStore class] forStoreType: AWSPersistenceDynamoDBIncrementalStoreType];// Adds the store to the coordinator[persistentStoreCoordinator addPersistentStoreWithType: AWSPersistenceDynamoDBIncrementalStoreType configuration:nil URL:nil options:options error:&error];
  20. 20. Creating an NSManagedObjectCheckin *checkin = (Checkin *) [NSEntityDescription insertNewObjectForEntityForName:@"Checkin” inManagedObjectContext:managedObjectContext];checkin.checkinId = [Utilities getUUID];checkin.checkinTime = [NSDate date];checkin.comment = @”First checkin”;[managedObjectContext save:&error];
  21. 21. Loading NSManagedObject// Create a fetch requestNSFetchRequest *request = [[NSFetchRequest alloc] init];// Specify the entityNSEntityDescription *entity = [NSEntityDescription entityForName:@"Location" inManagedObjectContext:managedObjectContext];[request setEntity:entity];// Execute the fetchNSArray *fetchedResults = [managedObjectContext executeFetchRequest:request error:&error];
  22. 22. Other Operations[managedObjectContext deleteObject:location];[managedObjectContext refreshObject:location mergeChanges:YES];
  23. 23. tableMapper = [NSDictionary dictionaryWithObjectsAndKeys: @"AWS-Locations", @"Location”, nil]; AWS-Locations
  24. 24. hashKeys = [NSDictionary dictionaryWithObjectsAndKeys: @"locationId", @"Location”, nil]; locationId
  25. 25. versions = [NSDictionary dictionaryWithObjectsAndKeys: @"version", @"Location”, nil]; A A B 1 SAVE B 3 ?
  26. 26. http://developer.apple.com/library/ios/#documentation/CoreData/Reference/NSMergePolicy_Class/Reference/Reference.html
  27. 27. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(mergeDeletedObject:) name:AWSPersistenceDynamoDBObjectDeletedNotification object:nil]; A B LOAD !
  28. 28. @protocol AWSPersistenceDynamoDBIncrementalStoreDelegate <NSObject>@required- (AmazonCredentials *)credentials;@optional- (void)handleAuthenticationFailure;@end
  29. 29. https://forums.aws.amazon.com/http://stackoverflow.com/tags/amazon-web-serviceshttps://github.com/amazonwebservices/aws-sdk-for-ioshttps://github.com/amazonwebservices/aws-sdk-for-android
  30. 30. http://aws.amazon.com/mobile/ http://aws.amazon.com/articles/3756417425850538 http://aws.amazon.com/articles/4435846131581972
  31. 31. We are sincerely eager to hear your feedback on thispresentation and on re:Invent. Please fill out an evaluation form when you have a chance.

×