List of usage examples for com.amazonaws.services.simpledb AmazonSimpleDB getAttributes
GetAttributesResult getAttributes(GetAttributesRequest getAttributesRequest);
Returns all of the attributes associated with the specified item.
From source file:com.aipo.aws.simpledb.SimpleDB.java
License:Open Source License
/** * //from w w w .ja v a2 s. c o m * @param <M> * @param client * @param rootClass * @param domain * @param itemName * @return */ public static <M> M get(AmazonSimpleDB client, Class<M> rootClass, String domain, String itemName) { try { M model = rootClass.newInstance(); if (model instanceof ResultItem) { GetAttributesResult result = client .getAttributes(new GetAttributesRequest(domain, itemName).withConsistentRead(true)); ResultItem item = (ResultItem) model; item.assign(itemName, result); } return model; } catch (InstantiationException e) { // } catch (IllegalAccessException e) { // } return null; }
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;/*w w w . java 2 s.com*/ 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; }
From source file:squash.booking.lambdas.core.OptimisticPersister.java
License:Apache License
@Override public ImmutablePair<Optional<Integer>, Set<Attribute>> get(String itemName) { if (!initialised) { throw new IllegalStateException("The optimistic persister has not been initialised"); }/*from w w w .j av a2s .co m*/ logger.log("About to get all active attributes from simpledb item: " + itemName); AmazonSimpleDB client = getSimpleDBClient(); // Do a consistent read - to ensure we get correct version number GetAttributesRequest simpleDBRequest = new GetAttributesRequest(simpleDbDomainName, itemName); logger.log("Using simpleDB domain: " + simpleDbDomainName); simpleDBRequest.setConsistentRead(true); GetAttributesResult result = client.getAttributes(simpleDBRequest); List<Attribute> attributes = result.getAttributes(); // Get the version number and other attributes. Optional<Integer> version = Optional.empty(); Set<Attribute> nonVersionAttributes = new HashSet<>(); if (attributes.size() > 0) { // If we have any attributes, we'll always have a version number Attribute versionNumberAttribute = attributes.stream() .filter(attribute -> attribute.getName().equals(versionAttributeName)).findFirst().get(); version = Optional.of(Integer.parseInt(versionNumberAttribute.getValue())); logger.log("Retrieved version number: " + versionNumberAttribute.getValue()); attributes.remove(versionNumberAttribute); // Add all active attributes (i.e. those not pending deletion) nonVersionAttributes.addAll(attributes.stream() .filter(attribute -> !attribute.getValue().startsWith("Inactive")).collect(Collectors.toSet())); } logger.log("Got all attributes from simpledb"); return new ImmutablePair<>(version, nonVersionAttributes); }