@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; }
/** * 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(); }
/** * 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)); }
/** * 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 void initialize(final String asgName, final String region) { super.initialize(asgName, region); // End point is us-east-1 AmazonSimpleDB simpleDBClient = AmazonSimpleDBClient.builder() .withCredentials(provider.getAwsCredentialProvider()) .build(); String nextToken = null; String appid = asgName.lastIndexOf('-') > 0 ? asgName.substring(0, asgName.indexOf('-')) : asgName; logger.info("appid used to fetch properties is: {}", appid); do { String ALL_QUERY = "select * from " + DOMAIN + " where " + Attributes.APP_ID + "='%s'"; SelectRequest request = new SelectRequest(String.format(ALL_QUERY, appid)); request.setNextToken(nextToken); SelectResult result = simpleDBClient.select(request); nextToken = result.getNextToken(); for (Item item : result.getItems()) addProperty(item); } while (nextToken != null); }
/** * 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; }
@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; }
/** * Returns a string representation of this object; useful for testing and * debugging. * * @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: " + getItems() + ","); if (getNextToken() != null) sb.append("NextToken: " + getNextToken() ); sb.append("}"); return sb.toString(); }
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; } } } }
/** * 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 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; }
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; }
protected void executeDirect(String sql, String next) throws TranslatorException { SelectResult result = connection.performSelect(sql, next); this.nextToken = result.getNextToken(); this.listIterator = result.getItems().iterator(); }
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 List<Item> getItems(){ AmazonSimpleDBClient client = new AmazonSimpleDBClient(...); List<Item> items = new ArrayList<>(); String nextToken = null; do { final SelectRequest request = new SelectRequest(); request.setSelectExpression("MY SELECT QUERY"); // SimpleDB can paginate the result. For paginated result NextToken value will be not null request.setNextToken(nextToken); nextToken = null; SelectResult result = client.select(request); if (result != null) { nextToken = (result.getNextToken() != null) ? result.getNextToken() : null; items.addAll(result.getItems()); } } while (nextToken != null); return items; }
private SearchResult convert(SelectResult result) { return new SearchResult( Lists.map(result.getItems(), new SearchItemMapper()), result.getNextToken() ); }