这里有一些帮助在 java 中列出域、创建域、添加属性、删除属性和列出项目。
public boolean checkSubscriptionToAmazonSimpleDB(String accessKey, String secretKey) {
try {
basicAWSCredentials = new BasicAWSCredentials(accessKey, secretKey);
amazonSimpleDBClient = new AmazonSimpleDBClient(basicAWSCredentials);
String sNextToken = "";
boolean bDomainExist = false;
do {
ListDomainsRequest listDomainsRequest = new ListDomainsRequest();
listDomainsRequest.setMaxNumberOfDomains(100);
listDomainsRequest.setNextToken(sNextToken);
ListDomainsResult listDomainsResult = amazonSimpleDBClient.listDomains(listDomainsRequest);
sNextToken = listDomainsResult.getNextToken();
List<String> list = listDomainsResult.getDomainNames();
for (String domain : list) {
System.out.println(domain);
}
} while (sNextToken != null && bDomainExist == false);
} catch (Throwable ex) {
System.out.println(ex.toString());
return false;
}
return true;
}
public void createDomain(String domain) {
CreateDomainRequest createDomainRequest = new CreateDomainRequest(domain);
amazonSimpleDBClient.createDomain(createDomainRequest);
}
private boolean addItem(String domain, String itemName) {
try {
PutAttributesRequest putAttributesRequest = new PutAttributesRequest();
putAttributesRequest.setDomainName(domain);
putAttributesRequest.setItemName(itemName);
List<ReplaceableAttribute> list = new ArrayList<ReplaceableAttribute>();
list.add(new ReplaceableAttribute("A", "a", true));
list.add(new ReplaceableAttribute("B", "c", true));
list.add(new ReplaceableAttribute("C", "b", true));
putAttributesRequest.setAttributes(list);
amazonSimpleDBClient.putAttributes(putAttributesRequest);
} catch (Throwable ex) {
System.out.println(ex.toString());
return false;
}
return true;
}
private boolean deleteItem(String domain, String itemName) {
try {
DeleteAttributesRequest deleteAttributesRequest = new DeleteAttributesRequest();
deleteAttributesRequest.setDomainName(domain);
deleteAttributesRequest.setItemName(itemName);
amazonSimpleDBClient.deleteAttributes(deleteAttributesRequest);
} catch (Throwable ex) {
System.out.println(ex.toString());
return false;
}
return true;
}
public void getListOfArchived(String domainname, String pagesize, String nextToken) {
SelectResult selectResult = null;
String sNextToken = null;
String query = null;
do {
query = "select * from " + domainname;
SelectRequest selectRequest = new SelectRequest(query);
selectRequest.setNextToken(nextToken);
selectResult = amazonSimpleDBClient.select(selectRequest);
sNextToken = selectResult.getNextToken();
List<Item> list = selectResult.getItems();
for(Item item: list){
item.getName(); // itemName
List<Attribute> listAttribute = item.getAttributes();
for(Attribute attribute:listAttribute){
attribute.getName(); // Attribute Name
attribute.getValue(); // Attribute value;
}
}
} while (sNextToken != null);
}