@Override public int hashCode() { final int prime = 31; int hashCode = 1; hashCode = prime * hashCode + ((getItems() == null) ? 0 : getItems().hashCode()); hashCode = prime * hashCode + ((getNextToken() == null) ? 0 : getNextToken().hashCode()); return hashCode; }
public SelectResult unmarshall(StaxUnmarshallerContext context) throws Exception { SelectResult selectResult = new SelectResult(); int originalDepth = context.getCurrentDepth(); int targetDepth = originalDepth + 1; if (context.isStartOfDocument()) targetDepth += 2; while (true) { XMLEvent xmlEvent = context.nextEvent(); if (xmlEvent.isEndDocument()) return selectResult; if (xmlEvent.isAttribute() || xmlEvent.isStartElement()) { if (context.testExpression("Item", targetDepth)) { selectResult.withItems(ItemStaxUnmarshaller.getInstance().unmarshall(context)); continue; } if (context.testExpression("NextToken", targetDepth)) { selectResult.setNextToken(StringStaxUnmarshaller.getInstance().unmarshall(context)); continue; } } else if (xmlEvent.isEndElement()) { if (context.getCurrentDepth() < originalDepth) { return selectResult; } } } }
/** * A list of items that match the select expression. * * @param items * A list of items that match the select expression. * @return Returns a reference to this object so that method calls can be chained together. */ public SelectResult withItems(java.util.Collection<Item> items) { setItems(items); return this; }
/** * Get the instance details from SimpleDB * * @param app Cluster name * @param id Node ID * @return the node with the given {@code id}, or {@code null} if no such node exists */ public PriamInstance getInstance(String app, String dc, int id) { AmazonSimpleDB simpleDBClient = getSimpleDBClient(); SelectRequest request = new SelectRequest(String.format(INSTANCE_QUERY, app, dc, id)); SelectResult result = simpleDBClient.select(request); if (result.getItems().size() == 0) return null; return transform(result.getItems().get(0)); }
/** * A utility method for loading up all the items in a domain. * * @param db * @param domainName * @param consistentRead true to read consistently, false to use eventual consistency * @return * @throws AmazonClientException */ public static List<Item> listAllItems(AmazonSimpleDB db, String domainName, boolean consistentRead) throws AmazonClientException { SelectResult results = new SelectResult(); List<Item> items = new ArrayList<Item>(); do { results = db.select(new SelectRequest() .withConsistentRead(consistentRead) .withSelectExpression("select * from `" + domainName + "`") .withNextToken(results.getNextToken())); items.addAll(results.getItems()); } while(results.getNextToken() != null); return items; }
/** * A list of items that match the select expression. * <p> * Returns a reference to this object so that method calls can be chained together. * * @param items A list of items that match the select expression. * * @return A reference to this updated object so that method calls can be chained * together. */ public SelectResult withItems(Item... items) { if (getItems() == null) setItems(new java.util.ArrayList<Item>(items.length)); for (Item value : items) { getItems().add(value); } return this; }
public SelectResult unmarshall(StaxUnmarshallerContext context) throws Exception { SelectResult selectResult = new SelectResult(); int originalDepth = context.getCurrentDepth(); int targetDepth = originalDepth + 1; if (context.isStartOfDocument()) targetDepth += 2; while (true) { int xmlEvent = context.nextEvent(); if (xmlEvent == XmlPullParser.END_DOCUMENT) return selectResult; if (xmlEvent == XmlPullParser.START_TAG) { if (context.testExpression("Item", targetDepth)) { selectResult.getItems().add(ItemStaxUnmarshaller.getInstance().unmarshall(context)); continue; } if (context.testExpression("NextToken", targetDepth)) { selectResult.setNextToken(StringStaxUnmarshaller.getInstance().unmarshall(context)); continue; } } else if (xmlEvent == XmlPullParser.END_TAG) { if (context.getCurrentDepth() < originalDepth) { return selectResult; } } } }
//1. Creating a SimpleDB Client AWSCredentials credentials = new BasicAWSCredentials( ACCESS_KEY, SECRET_KEY ); AmazonSimpleDBClient sdbClient = new AmazonSimpleDBClient( credentials); sdbClient.setEndpoint("sdb.us-west-1.amazonaws.com"); // to define Data Center Region //2. Select String nextToken = null; SelectRequest selectRequest = new SelectRequest( "select * from myDomain" ).withConsistentRead( true ); selectRequest.setNextToken( nextToken ); SelectResult response = sdbClient.select( selectRequest ); nextToken = response.getNextToken();
/** * An opaque token indicating that more items than <code>MaxNumberOfItems</code> were matched, the response size * exceeded 1 megabyte, or the execution time exceeded 5 seconds. * * @param nextToken * An opaque token indicating that more items than <code>MaxNumberOfItems</code> were matched, the response * size exceeded 1 megabyte, or the execution time exceeded 5 seconds. * @return Returns a reference to this object so that method calls can be chained together. */ public SelectResult withNextToken(String nextToken) { setNextToken(nextToken); return this; }
private Set<SimpleDBAttribute> getAttributeNamesFromSelectResult(SelectResult selectResult, int attributesCount) { Set<SimpleDBAttribute> attributes = new LinkedHashSet<SimpleDBAttribute>(); Iterator<Item> itemsIterator = selectResult.getItems().iterator(); while (attributes.size() < attributesCount) { Item item = itemsIterator.next(); Map<String, List<String>> valueMap = createAttributeMap(item.getAttributes()); for (String attributeName : valueMap.keySet()) { List<String> values = valueMap.get(attributeName); attributes.add(new SimpleDBAttribute(attributeName, values.size() > 1)); } } return attributes; }
/** * An opaque token indicating that more items than <code>MaxNumberOfItems</code> were matched, the response size * exceeded 1 megabyte, or the execution time exceeded 5 seconds. * * @param nextToken * An opaque token indicating that more items than <code>MaxNumberOfItems</code> were matched, the response * size exceeded 1 megabyte, or the execution time exceeded 5 seconds. * @return Returns a reference to this object so that method calls can be chained together. */ public SelectResult withNextToken(String nextToken) { setNextToken(nextToken); return this; }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (obj instanceof SelectResult == false) return false; SelectResult other = (SelectResult) obj; if (other.getItems() == null ^ this.getItems() == null) return false; if (other.getItems() != null && other.getItems().equals(this.getItems()) == false) return false; if (other.getNextToken() == null ^ this.getNextToken() == null) return false; if (other.getNextToken() != null && other.getNextToken().equals(this.getNextToken()) == false) return false; return true; }
public static List<ItemAndAttributes> test(EntityManagerSimpleJPA em, String domainName) throws AmazonClientException, ExecutionException, InterruptedException { AmazonSimpleDB db = em.getSimpleDb(); SelectResult result = DomainHelper.selectItems(db, "select * from `" + domainName + "`", null); List<SdbItem> list = new ArrayList<SdbItem>(); for (Item item : result.getItems()) { list.add(new SdbItemImpl2(item)); } return getAttributesFromSdb(list, em.getExecutor(), em); }
public SelectResult unmarshall(StaxUnmarshallerContext context) throws Exception { SelectResult selectResult = new SelectResult(); int originalDepth = context.getCurrentDepth(); int targetDepth = originalDepth + 1; if (context.isStartOfDocument()) targetDepth += 2; while (true) { XMLEvent xmlEvent = context.nextEvent(); if (xmlEvent.isEndDocument()) return selectResult; if (xmlEvent.isAttribute() || xmlEvent.isStartElement()) { if (context.testExpression("Item", targetDepth)) { selectResult.withItems(ItemStaxUnmarshaller.getInstance().unmarshall(context)); continue; } if (context.testExpression("NextToken", targetDepth)) { selectResult.setNextToken(StringStaxUnmarshaller.getInstance().unmarshall(context)); continue; } } else if (xmlEvent.isEndElement()) { if (context.getCurrentDepth() < originalDepth) { return selectResult; } } } }
/** * A list of items that match the select expression. * <p> * <b>NOTE:</b> This method appends the values to the existing list (if any). Use * {@link #setItems(java.util.Collection)} or {@link #withItems(java.util.Collection)} if you want to override the * existing values. * </p> * * @param items * A list of items that match the select expression. * @return Returns a reference to this object so that method calls can be chained together. */ public SelectResult withItems(Item... items) { if (this.items == null) { setItems(new com.amazonaws.internal.SdkInternalList<Item>(items.length)); } for (Item ele : items) { this.items.add(ele); } return this; }
/** * Returns a string representation of this object. This is useful for testing and debugging. Sensitive data will be * redacted from this string using a placeholder value. * * @return A string representation of this object. * * @see java.lang.Object#toString() */ @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("{"); if (getItems() != null) sb.append("Items: ").append(getItems()).append(","); if (getNextToken() != null) sb.append("NextToken: ").append(getNextToken()); sb.append("}"); return sb.toString(); }
@Override public Collection<ExpectedSlotStatus> getAllExpectedStates() { List<ExpectedSlotStatus> slots = newArrayList(); if (isDomainCreated()) { try { String query = String.format("select itemName, state, binary, config from `%s`", domainName); SelectResult select = simpleDb.select(new SelectRequest(query, true)); for (Item item : select.getItems()) { ExpectedSlotStatus expectedSlotStatus = loadSlotStatus(item); if (expectedSlotStatus != null) { slots.add(expectedSlotStatus); } } expectedStateStoreUp(); } catch (Exception e) { expectedStateStoreDown(e); } } return slots; }
/** * A list of items that match the select expression. * * @param items * A list of items that match the select expression. * @return Returns a reference to this object so that method calls can be chained together. */ public SelectResult withItems(java.util.Collection<Item> items) { setItems(items); return this; }
/** * Get the set of all nodes in the cluster * * @param app Cluster name * @return the set of all instances in the given {@code app} */ public Set<PriamInstance> getAllIds(String app) { AmazonSimpleDB simpleDBClient = getSimpleDBClient(); Set<PriamInstance> inslist = new HashSet<>(); String nextToken = null; do { SelectRequest request = new SelectRequest(String.format(ALL_QUERY, app)); request.setNextToken(nextToken); SelectResult result = simpleDBClient.select(request); nextToken = result.getNextToken(); for (Item item : result.getItems()) { inslist.add(transform(item)); } } while (nextToken != null); return inslist; }
@Override public Collection<ExpectedSlotStatus> getAllExpectedStates() { List<ExpectedSlotStatus> slots = newArrayList(); if (isDomainCreated()) { try { String query = String.format("select itemName, state, binary, config from `%s`", domainName); SelectResult select = simpleDb.select(new SelectRequest(query, true)); for (Item item : select.getItems()) { ExpectedSlotStatus expectedSlotStatus = loadSlotStatus(item); if (expectedSlotStatus != null) { slots.add(expectedSlotStatus); } } expectedStateStoreUp(); } catch (Exception e) { expectedStateStoreDown(e); } } return slots; }