List of usage examples for com.amazonaws.services.simpledb.model GetAttributesRequest setItemName
public void setItemName(String itemName)
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 . j av a2 s. co m*/ 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.duboisproject.rushhour.database.SdbInterface.java
License:Open Source License
public int timeLimit(String id) throws RequestException { GetAttributesRequest request = GetRequestDetails.TIMELIMIT.toAttributesRequest(); request.setItemName(id); GetAttributesResult result;//from w w w . j ava2 s . com 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); GetAttributesResult result;//from w ww.ja v a 2 s. com 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); GetAttributesResult result;/* ww w . j a va 2 s . co m*/ 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. *//* ww w. j av a 2s . c o m*/ 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. *///w ww. j av a 2 s.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)); }