List of usage examples for com.amazonaws.services.simpledb AmazonSimpleDB setRegion
@Deprecated
void setRegion(Region region);
From source file:SimpleDBExample.java
License:Open Source License
public static void main(String[] args) throws Exception { /*/*from ww w. ja v a2s . c om*/ * This credentials provider implementation loads your AWS credentials * from a properties file at the root of your classpath. * * Important: Be sure to fill in your AWS access credentials in the * AwsCredentials.properties file before you try to run this * sample. * http://aws.amazon.com/security-credentials */ AmazonSimpleDB sdb = new AmazonSimpleDBClient(new ClasspathPropertiesFileCredentialsProvider()); Region usWest2 = Region.getRegion(Regions.US_WEST_2); sdb.setRegion(usWest2); System.out.println("==========================================="); System.out.println("Getting Started with Amazon SimpleDB"); System.out.println("===========================================\n"); try { // Create a domain String myDomain = "MyStore"; System.out.println("Creating domain called " + myDomain + ".\n"); sdb.createDomain(new CreateDomainRequest(myDomain)); // List domains System.out.println("Listing all domains in your account:\n"); for (String domainName : sdb.listDomains().getDomainNames()) { System.out.println(" " + domainName); } System.out.println(); // Put data into a domain System.out.println("Putting data into " + myDomain + " domain.\n"); sdb.batchPutAttributes(new BatchPutAttributesRequest(myDomain, createSampleData())); // Select data from a domain // Notice the use of backticks around the domain name in our select expression. String selectExpression = "select * from `" + myDomain + "` where Category = 'Clothes'"; System.out.println("Selecting: " + selectExpression + "\n"); SelectRequest selectRequest = new SelectRequest(selectExpression); for (Item item : sdb.select(selectRequest).getItems()) { System.out.println(" Item"); System.out.println(" Name: " + item.getName()); for (Attribute attribute : item.getAttributes()) { System.out.println(" Attribute"); System.out.println(" Name: " + attribute.getName()); System.out.println(" Value: " + attribute.getValue()); } } System.out.println(); // Delete values from an attribute System.out.println("Deleting Blue attributes in Item_O3.\n"); Attribute deleteValueAttribute = new Attribute("Color", "Blue"); sdb.deleteAttributes( new DeleteAttributesRequest(myDomain, "Item_03").withAttributes(deleteValueAttribute)); // Delete an attribute and all of its values System.out.println("Deleting attribute Year in Item_O3.\n"); sdb.deleteAttributes(new DeleteAttributesRequest(myDomain, "Item_03") .withAttributes(new Attribute().withName("Year"))); // Replace an attribute System.out.println("Replacing Size of Item_03 with Medium.\n"); List<ReplaceableAttribute> replaceableAttributes = new ArrayList<ReplaceableAttribute>(); replaceableAttributes.add(new ReplaceableAttribute("Size", "Medium", true)); sdb.putAttributes(new PutAttributesRequest(myDomain, "Item_03", replaceableAttributes)); // Delete an item and all of its attributes System.out.println("Deleting Item_03.\n"); sdb.deleteAttributes(new DeleteAttributesRequest(myDomain, "Item_03")); // Delete a domain System.out.println("Deleting " + myDomain + " domain.\n"); sdb.deleteDomain(new DeleteDomainRequest(myDomain)); } catch (AmazonServiceException ase) { System.out.println("Caught an AmazonServiceException, which means your request made it " + "to Amazon SimpleDB, but was rejected with an error response for some reason."); System.out.println("Error Message: " + ase.getMessage()); System.out.println("HTTP Status Code: " + ase.getStatusCode()); System.out.println("AWS Error Code: " + ase.getErrorCode()); System.out.println("Error Type: " + ase.getErrorType()); System.out.println("Request ID: " + ase.getRequestId()); } catch (AmazonClientException ace) { System.out.println("Caught an AmazonClientException, which means the client encountered " + "a serious internal problem while trying to communicate with SimpleDB, " + "such as not being able to access the network."); System.out.println("Error Message: " + ace.getMessage()); } }
From source file:SimpleDBWrite.java
License:Open Source License
public static void run(String searchItem) throws Exception { /*/*ww w . ja va 2 s.c om*/ * This credentials provider implementation loads your AWS credentials * from a properties file at the root of your classpath. * * Important: Be sure to fill in your AWS access credentials in the * AwsCredentials.properties file before you try to run this * sample. * http://aws.amazon.com/security-credentials */ AmazonSimpleDB sdb = new AmazonSimpleDBClient(new ClasspathPropertiesFileCredentialsProvider()); Region usWest2 = Region.getRegion(Regions.US_WEST_2); sdb.setRegion(usWest2); try { // Create a domain String myDomain = "WanningStore"; sdb.createDomain(new CreateDomainRequest(myDomain)); // List domains // System.out.println("Listing all domains in your account:\n"); // for (String domainName : sdb.listDomains().getDomainNames()) { // System.out.println(" " + domainName); // } // System.out.println(); // Put data into a domain System.out.println("Putting data into " + myDomain + " domain.\n"); sdb.batchPutAttributes(new BatchPutAttributesRequest(myDomain, createData(searchItem))); // // Delete values from an attribute // System.out.println("Deleting Blue attributes in Item_O3.\n"); // Attribute deleteValueAttribute = new Attribute("Color", "Blue"); // sdb.deleteAttributes(new DeleteAttributesRequest(myDomain, "Item_03") // .withAttributes(deleteValueAttribute)); // Delete an attribute and all of its values // System.out.println("Deleting attribute Year in Item_O3.\n"); // sdb.deleteAttributes(new DeleteAttributesRequest(myDomain, "Item_03") // .withAttributes(new Attribute().withName("Year"))); // // // Replace an attribute // System.out.println("Replacing Size of Item_03 with Medium.\n"); // List<ReplaceableAttribute> replaceableAttributes = new ArrayList<ReplaceableAttribute>(); // replaceableAttributes.add(new ReplaceableAttribute("Size", "Medium", true)); // sdb.putAttributes(new PutAttributesRequest(myDomain, "Item_03", replaceableAttributes)); // // // Delete an item and all of its attributes // System.out.println("Deleting Item_03.\n"); // sdb.deleteAttributes(new DeleteAttributesRequest(myDomain, "Item_03")); // // // Delete a domain // System.out.println("Deleting " + myDomain + " domain.\n"); // sdb.deleteDomain(new DeleteDomainRequest(myDomain)); } catch (AmazonServiceException ase) { System.out.println("Caught an AmazonServiceException, which means your request made it " + "to Amazon SimpleDB, but was rejected with an error response for some reason."); System.out.println("Error Message: " + ase.getMessage()); System.out.println("HTTP Status Code: " + ase.getStatusCode()); System.out.println("AWS Error Code: " + ase.getErrorCode()); System.out.println("Error Type: " + ase.getErrorType()); System.out.println("Request ID: " + ase.getRequestId()); } catch (AmazonClientException ace) { System.out.println("Caught an AmazonClientException, which means the client encountered " + "a serious internal problem while trying to communicate with SimpleDB, " + "such as not being able to access the network."); System.out.println("Error Message: " + ace.getMessage()); } }