List of usage examples for com.amazonaws.services.simpledb.model GetAttributesRequest setDomainName
public void setDomainName(String domainName)
From source file:com.aipo.aws.simpledb.SimpleDB.java
License:Open Source License
private static Integer counterJob(String domain) { AmazonSimpleDB client = getClient(); GetAttributesRequest getAttributesRequest = new GetAttributesRequest(); getAttributesRequest.setDomainName(DEFAULT_COUNTER_DOMAIN); getAttributesRequest.setItemName(domain); getAttributesRequest.setConsistentRead(true); Integer count = null;/*from w ww.j a v a 2s . c om*/ try { GetAttributesResult attributes = client.getAttributes(getAttributesRequest); List<Attribute> list = attributes.getAttributes(); for (Attribute item : list) { if ("c".equals(item.getName())) { try { count = Integer.valueOf(item.getValue()); } catch (Throwable ignore) { } } } } catch (Throwable t) { t.printStackTrace(); } if (count == null) { CreateDomainRequest createDomainRequest = new CreateDomainRequest(DEFAULT_COUNTER_DOMAIN); client.createDomain(createDomainRequest); count = 0; } int next = count + 1; PutAttributesRequest putAttributesRequest = new PutAttributesRequest(); putAttributesRequest.setDomainName(DEFAULT_COUNTER_DOMAIN); putAttributesRequest.setItemName(domain); List<ReplaceableAttribute> attr = new ArrayList<ReplaceableAttribute>(); attr.add(new ReplaceableAttribute("c", String.valueOf(next), true)); putAttributesRequest.setAttributes(attr); UpdateCondition updateCondition = new UpdateCondition(); if (next == 1) { updateCondition.setExists(false); updateCondition.setName("c"); } else { updateCondition.setExists(true); updateCondition.setName("c"); updateCondition.setValue(String.valueOf(count)); } putAttributesRequest.setExpected(updateCondition); client.putAttributes(putAttributesRequest); return next; }