List of usage examples for com.amazonaws.services.simpledb.model GetAttributesResult getAttributes
public java.util.List<Attribute> getAttributes()
From source file:com.aipo.aws.simpledb.ResultItem.java
License:Open Source License
protected void assign(String itemName, GetAttributesResult result) { this.itemName = itemName; List<Attribute> attributes = result.getAttributes(); for (Attribute attr : attributes) { put(attr.getName(), attr.getValue()); }/* w w w . j a v a 2 s. c o m*/ }
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.ja v a 2s . 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:com.amazon.aws.demo.anonymous.sdb.SimpleDB.java
License:Open Source License
public static HashMap<String, String> getAttributesForItem(String domainName, String itemName) { GetAttributesRequest getRequest = new GetAttributesRequest(domainName, itemName).withConsistentRead(true); GetAttributesResult getResult = getInstance().getAttributes(getRequest); HashMap<String, String> attributes = new HashMap<String, String>(30); for (Object attribute : getResult.getAttributes()) { String name = ((Attribute) attribute).getName(); String value = ((Attribute) attribute).getValue(); attributes.put(name, value);/*from ww w. ja va2 s .com*/ } return attributes; }
From source file:com.dateofrock.simpledbmapper.SimpleDBMapper.java
License:Apache License
/** * SimpleDB????/*from www . java 2s. c o m*/ * * @param object * {@link SimpleDBDomain}????POJO * {@link SimpleDBVersionAttribute} * ??????????????<a href= * "http://docs.amazonwebservices.com/AmazonSimpleDB/latest/DeveloperGuide/ConditionalDelete.html" * >Conditional Delete</a>???? */ public void delete(Object object) { String domainName = this.reflector.getDomainName(object.getClass()); Field itemNameField = this.reflector.findItemNameField(object.getClass()); String itemName = this.reflector.encodeItemNameAsSimpleDBFormat(object, itemNameField); // S3 Blob GetAttributesResult results = this.sdb.getAttributes(new GetAttributesRequest(domainName, itemName)); List<Attribute> sdbAllAttrs = results.getAttributes(); Set<Field> blobFields = this.reflector.findBlobFields(object.getClass()); List<S3TaskResult> s3TaskResults = new ArrayList<S3TaskResult>(); for (Field field : blobFields) { SimpleDBBlob blobAnnon = field.getAnnotation(SimpleDBBlob.class); String attributeName = blobAnnon.attributeName(); for (Attribute attr : sdbAllAttrs) { if (attr.getName().equals(attributeName)) { S3TaskResult taskResult = new S3TaskResult(Operation.DELETE, attributeName, null, null); taskResult.setSimpleDBAttributeValue(attr.getValue()); s3TaskResults.add(taskResult); } } } DeleteAttributesRequest req = new DeleteAttributesRequest(domainName, itemName); // version?????Conditional Delete Field versionField = this.reflector.findVersionAttributeField(object.getClass()); if (versionField != null) { try { Object versionObject = versionField.get(object); String versionAttributeName = versionField.getAnnotation(SimpleDBVersionAttribute.class) .attributeName(); if (versionObject != null) { if (versionObject instanceof Long) { Long currentVersion = (Long) versionObject; UpdateCondition expected = new UpdateCondition(); expected.setName(versionAttributeName); expected.setValue(currentVersion.toString()); req.setExpected(expected); } else { throw new SimpleDBMapperException( "version?Long???????" + versionField); } } } catch (Exception e) { throw new SimpleDBMapperException("object?version??: " + object, e); } } this.sdb.deleteAttributes(req); // S3 for (S3TaskResult s3TaskResult : s3TaskResults) { this.s3.deleteObject(s3TaskResult.getBucketName(), s3TaskResult.getKey()); } }
From source file:com.duboisproject.rushhour.database.SdbInterface.java
License:Open Source License
public int timeLimit(String id) throws RequestException { GetAttributesRequest request = GetRequestDetails.TIMELIMIT.toAttributesRequest(); request.setItemName(id);//from w ww . j a v a 2 s. com GetAttributesResult result; try { result = client.getAttributes(request); } catch (AmazonClientException e) { throw new RequestException(REQUEST_FAILED_MESSAGE); } List<Attribute> attributesList = result.getAttributes(); if (attributesList.size() == 0) { throw new IllegalArgumentException("Internal error #1 timeLimit SdbInterface.java"); } Map<String, String> attributes = mapify(attributesList); return Integer.parseInt(attributes.get(TIME_LIMIT)); }
From source file:com.duboisproject.rushhour.database.SdbInterface.java
License:Open Source License
public Mathlete fetchMathlete(String id) throws RequestException { GetAttributesRequest request = GetRequestDetails.MATHLETE_ID.toAttributesRequest(); request.setItemName(id);/*from w ww . j av a2s .co m*/ GetAttributesResult result; try { result = client.getAttributes(request); } catch (AmazonClientException e) { throw new RequestException(REQUEST_FAILED_MESSAGE); } List<Attribute> attributesList = result.getAttributes(); if (attributesList.size() == 0) { throw new IllegalArgumentException("No such mathlete in database"); } Map<String, String> attributes = mapify(attributesList); return new Mathlete(id, attributes.get(MATHLETE_NAME), attributes.get(MATHLETE_LAST_NAME)); }
From source file:com.duboisproject.rushhour.database.SdbInterface.java
License:Open Source License
public Coach fetchCoach(String id) throws RequestException { GetAttributesRequest request = GetRequestDetails.COACH_ID.toAttributesRequest(); request.setItemName(id);/*ww w . ja v a 2 s . c o m*/ GetAttributesResult result; try { result = client.getAttributes(request); } catch (AmazonClientException e) { throw new RequestException(REQUEST_FAILED_MESSAGE); } List<Attribute> attributesList = result.getAttributes(); if (attributesList.size() == 0) { throw new IllegalArgumentException("No such coach in database"); } Map<String, String> attributes = mapify(attributesList); lastCoachScan = SystemClock.elapsedRealtime(); max_time_between_coach_scans = timeLimit("1"); return new Coach(id, attributes.get(COACH_NAME)); }
From source file:com.duboisproject.rushhour.database.SdbInterface.java
License:Open Source License
/** * Get the map for the specified level ID, and construct a board. *//* w ww . ja va 2 s.com*/ public Board fetchBoard(int id) throws RequestException { GetAttributesRequest request = GetRequestDetails.MAP_FETCH.toAttributesRequest(); request.setItemName(Integer.toString(id)); GetAttributesResult result; try { result = client.getAttributes(request); } catch (AmazonClientException e) { throw new RequestException(REQUEST_FAILED_MESSAGE); } List<Attribute> attributesList = result.getAttributes(); if (attributesList.isEmpty()) { throw new IllegalArgumentException("No such level in database"); } Map<String, String> attributes = mapify(attributesList); String map = attributes.get(LEVEL_MAP); Board board = BoardLoader.loadBoard(new StringReader(map)); board.id = id; return board; }
From source file:com.duboisproject.rushhour.database.SdbInterface.java
License:Open Source License
/** * Get the difficulty of the specified level ID. *//* ww w. ja v a 2s. c o m*/ public int fetchDifficulty(int id) throws RequestException { GetAttributesRequest request = GetRequestDetails.DIFFICULTY_FETCH.toAttributesRequest(); request.setItemName(Integer.toString(id)); GetAttributesResult result; try { result = client.getAttributes(request); } catch (AmazonClientException e) { throw new RequestException(REQUEST_FAILED_MESSAGE); } List<Attribute> attributesList = result.getAttributes(); if (attributesList.isEmpty()) { throw new IllegalArgumentException("No such level in database"); } Map<String, String> attributes = mapify(attributesList); return Integer.parseInt(attributes.get(LEVEL_DIFFICULTY)); }
From source file:com.threepillar.labs.quartz.simpledb.SimpleDbJobStore.java
License:Apache License
/** * <p>/*from w w w . j ava 2 s. c o m*/ * Retrieve the <code>{@link org.quartz.JobDetail}</code> for the given * <code>{@link org.quartz.Job}</code>. * </p> * * @param jobName The name of the <code>Job</code> to be retrieved. * @param groupName The group name of the <code>Job</code> to be retrieved. * @return The desired <code>Job</code>, or null if there is no match. */ @Override public JobDetail retrieveJob(SchedulingContext ctxt, String jobName, String groupName) { logDebug("Retrieving Job: ", groupName, ".", jobName); String key = JobWrapper.getJobNameKey(jobName, groupName); GetAttributesResult result = amazonSimpleDb .getAttributes(new GetAttributesRequest(jobDomain, key).withConsistentRead(Boolean.TRUE)); try { return jobDetailFromAttributes(result.getAttributes()); } catch (IOException e) { log.error("Could not retrieve Job: " + groupName + "." + jobName, e); return null; } }