List of usage examples for com.amazonaws.services.simpledb.model SelectResult getNextToken
public String getNextToken()
MaxNumberOfItems
were matched, the response size exceeded 1 megabyte, or the execution time exceeded 5 seconds. From source file:assign1.simpledb.java
License:Open Source License
public List<record> query(String word) throws Exception { /*//from w ww .j a va2s . co m * Important: Be sure to fill in your AWS access credentials in the * AwsCredentials.properties file before you try to run this * sample. * http://aws.amazon.com/security-credentials*/ ArrayList<record> result = new ArrayList<record>(); AWSCredentials credentials = null; try { credentials = new PropertiesCredentials( simpledb.class.getResourceAsStream("AwsCredentials.properties")); } catch (Exception e) { throw new AmazonClientException("Cannot load the credentials from the credential profiles file. " + "Please make sure that your credentials file is at the correct " + "location (/Users/huanglin/.aws/credentials), and is in valid format.", e); } AmazonSimpleDB sdb = new AmazonSimpleDBClient(credentials); System.out.println("==========================================="); System.out.println("Getting Started with Amazon SimpleDB"); System.out.println("===========================================\n"); String myDomain = "MyStore"; String filter = word; String nextToken = null; SelectResult selectResult = null; do { String selectExpression = ""; if (word.equals("all")) selectExpression = "select * from MyStore LIMIT 2500"; else selectExpression = "select * from " + myDomain + " where content like '%" + filter + "%' LIMIT 2500"; System.out.println("Selecting: " + selectExpression + "\n"); SelectRequest selectRequest = new SelectRequest(selectExpression); selectRequest.setNextToken(nextToken); selectResult = sdb.select(selectRequest); nextToken = selectResult.getNextToken(); List<Item> list = selectResult.getItems(); for (Item item : list) { System.out.println(" itemIndex: " + item.getName()); List<Attribute> attributeTmp = new ArrayList<Attribute>(); attributeTmp = item.getAttributes(); record tmp = new record(); for (int i = 0; i < 5; i++) { if (attributeTmp.get(i).getName().equals("content")) tmp.content = attributeTmp.get(i).getValue(); else if (attributeTmp.get(i).getName().equals("geoLat")) tmp.x = Double.parseDouble(attributeTmp.get(i).getValue()); else if (attributeTmp.get(i).getName().equals("Username")) tmp.username = attributeTmp.get(i).getValue(); else if (attributeTmp.get(i).getName().equals("Location")) tmp.location = attributeTmp.get(i).getValue(); else tmp.y = Double.parseDouble(attributeTmp.get(i).getValue()); } result.add(tmp); } } while (nextToken != null); return result; }
From source file:assign1.simpledb1.java
License:Open Source License
public List<record> query(String word) throws Exception { /*/*from w w w. j a v a 2 s. co m*/ * Important: Be sure to fill in your AWS access credentials in the * AwsCredentials.properties file before you try to run this * sample. * http://aws.amazon.com/security-credentials*/ ArrayList<record> result = new ArrayList<record>(); AWSCredentials credentials = null; try { credentials = new PropertiesCredentials( simpledb.class.getResourceAsStream("AwsCredentials.properties")); } catch (Exception e) { throw new AmazonClientException("Cannot load the credentials from the credential profiles file. " + "Please make sure that your credentials file is at the correct " + "location (/Users/huanglin/.aws/credentials), and is in valid format.", e); } AmazonSimpleDB sdb = new AmazonSimpleDBClient(credentials); System.out.println("==========================================="); System.out.println("Getting Started with Amazon SimpleDB"); System.out.println("===========================================\n"); String myDomain = "Twitter"; String filter = word; String nextToken = null; SelectResult selectResult = null; do { String selectExpression = ""; if (word.equals("all")) selectExpression = "select * from MyStore LIMIT 2500"; else selectExpression = "select * from " + myDomain + " where content like '%" + filter + "%' LIMIT 2500"; System.out.println("Selecting: " + selectExpression + "\n"); SelectRequest selectRequest = new SelectRequest(selectExpression); selectRequest.setNextToken(nextToken); selectResult = sdb.select(selectRequest); nextToken = selectResult.getNextToken(); List<Item> list = selectResult.getItems(); for (Item item : list) { System.out.println(" itemIndex: " + item.getName()); List<Attribute> attributeTmp = new ArrayList<Attribute>(); attributeTmp = item.getAttributes(); record tmp = new record(); for (int i = 0; i < 5; i++) { if (attributeTmp.get(i).getName().equals("content")) tmp.content = attributeTmp.get(i).getValue(); else if (attributeTmp.get(i).getName().equals("geoLat")) tmp.x = Double.parseDouble(attributeTmp.get(i).getValue()); else if (attributeTmp.get(i).getName().equals("Username")) tmp.username = attributeTmp.get(i).getValue(); else if (attributeTmp.get(i).getName().equals("Location")) tmp.location = attributeTmp.get(i).getValue(); else tmp.y = Double.parseDouble(attributeTmp.get(i).getValue()); } result.add(tmp); } } while (nextToken != null); return result; }
From source file:br.com.ingenieux.mojo.simpledb.cmd.DumpDomainCommand.java
License:Apache License
public boolean execute(DumpDomainContext context) throws Exception { SelectRequest selectRequest = new SelectRequest(String.format("SELECT * FROM %s", context.getDomain())); SelectResult selectResult = service.select(selectRequest); ArrayNode rootNode = mapper.createArrayNode(); while (!selectResult.getItems().isEmpty()) { for (Item item : selectResult.getItems()) appendResult(rootNode, item); if (isBlank(selectResult.getNextToken())) break; selectResult = service.select(selectRequest.withNextToken(selectResult.getNextToken())); }/*from w w w.j a v a2 s . co m*/ FileWriter writer = new FileWriter(context.getOutputFile()); writeData(rootNode, writer); IOUtil.close(writer); return false; }
From source file:c3.ops.priam.aws.SDBInstanceData.java
License:Apache License
/** * Get the set of all nodes in the cluster * * @param app Cluster name//from ww w.java2s. co m * @return the set of all instances in the given {@code app} */ public Set<PriamInstance> getAllIds(String app) { AmazonSimpleDBClient simpleDBClient = getSimpleDBClient(); Set<PriamInstance> inslist = new HashSet<PriamInstance>(); String nextToken = null; do { SelectRequest request = new SelectRequest(String.format(ALL_QUERY, app)); request.setNextToken(nextToken); SelectResult result = simpleDBClient.select(request); nextToken = result.getNextToken(); Iterator<Item> itemiter = result.getItems().iterator(); while (itemiter.hasNext()) { inslist.add(transform(itemiter.next())); } } while (nextToken != null); return inslist; }
From source file:com.aipo.aws.simpledb.SimpleDB.java
License:Open Source License
/** * //from www .j a va2 s . c om * @param <M> * @param client * @param rootClass * @param sql * @param nextToken * @return */ public static <M> ResultList<M> select(AmazonSimpleDB client, Class<M> rootClass, String sql, String nextToken) { try { SelectRequest request = new SelectRequest(sql.toString()).withConsistentRead(true); if (nextToken != null) { request.setNextToken(nextToken); } SelectResult select = client.select(request); List<Item> items = select.getItems(); ResultList<M> result = new ResultList<M>(); for (Item item : items) { M model = rootClass.newInstance(); if (model instanceof ResultItem) { ResultItem resultItem = (ResultItem) model; resultItem.assign(item); result.add(model); } } result.setNextToken(select.getNextToken()); return result; } catch (InstantiationException e) { // } catch (IllegalAccessException e) { // } return new ResultList<M>(); }
From source file:com.brighttag.agathon.dao.sdb.SdbCassandraInstanceDao.java
License:Apache License
@Override public ImmutableSet<CassandraInstance> findAll(String ring) { List<CassandraInstance> instances = Lists.newArrayList(); String nextToken = null;//from w w w .j a va 2s. c o m do { SelectRequest request = new SelectRequest(String.format(ALL_QUERY, domain(ring))) .withNextToken(nextToken); SelectResult result = client.select(request); for (Item item : result.getItems()) { instances.add(transform(item)); } nextToken = result.getNextToken(); } while (nextToken != null); return ImmutableSet.copyOf(instances); }
From source file:com.dateofrock.simpledbmapper.SimpleDBMapper.java
License:Apache License
private <T> List<T> fetch(Class<T> clazz, String query) { SelectRequest selectRequest = new SelectRequest(query.toString(), this.config.isConsistentRead()); if (this.selectNextToken != null) { selectRequest.setNextToken(this.selectNextToken); this.selectNextToken = null; }//ww w. j a v a2 s . c om SelectResult result = this.sdb.select(selectRequest); List<Item> items = result.getItems(); if (items.isEmpty()) { return Collections.emptyList(); } this.selectNextToken = result.getNextToken(); List<T> objects = new ArrayList<T>(); Field itemNameField = this.reflector.findItemNameField(clazz); try { // SDB?item? for (Item item : items) { T instance; instance = clazz.newInstance(); // ItemName? Class<?> type = itemNameField.getType(); String itemName = item.getName(); itemNameField.set(instance, this.reflector.decodeItemNameFromSimpleDBFormat(type, itemName)); // item?attributes? List<Attribute> attrs = item.getAttributes(); for (Attribute attr : attrs) { String attributeName = attr.getName(); Field attrField = this.reflector.findFieldByAttributeName(clazz, attributeName); if (attrField == null) { continue; } // Blob???LazyFetch? SimpleDBBlob blobAnno = attrField.getAnnotation(SimpleDBBlob.class); if (blobAnno != null) { String fieldName = attrField.getName(); if (this.blobEagerFetchList.contains(fieldName)) { // this.reflector.setFieldValueFromAttribute(this.s3, clazz, instance, attr); } else { FetchType fetchType = blobAnno.fetch(); if (fetchType == FetchType.EAGER) { // this.reflector.setFieldValueFromAttribute(this.s3, clazz, instance, attr); } } } else { this.reflector.setFieldValueFromAttribute(this.s3, clazz, instance, attr); } } // objects.add(instance); } } catch (Exception e) { throw new SimpleDBMapperException(e); } return objects; }
From source file:com.davidgildeh.hadoop.input.simpledb.SimpleDBDAO.java
License:Apache License
/** * Get the count for a Select query// ww w . j a v a 2 s. co m * * @param query WHERE Clause to select on, null if none * @return Count of results */ public long getCount() { String countQuery = createQuery(true, -1); long count = 0; // Run Count Query, iterate over tokens if multiple tokens returned SelectResult results = doQuery(countQuery, null); count += getCountValue(results); while (results.getNextToken() != null) { count += getCountValue(results); // Get next results results = doQuery(countQuery, results.getNextToken()); } // Return 0 by default return count; }
From source file:com.davidgildeh.hadoop.input.simpledb.SimpleDBDAO.java
License:Apache License
/** * Runs a count LIMIT query for LIMIT = offset to get the nextToken from * that row onwards//from www.j av a 2s. com * * @param offset Row to get nextToken for * @return The nextToken to get data after the offset row */ public String getSplitToken(long page, long limit) { String nextToken = null; // Run Count Query, iterate over tokens if multiple tokens returned SelectResult result = null; long totalCount = 0; while (totalCount < (page * limit)) { String countQuery = createQuery(true, limit); if (result != null) { result = doQuery(countQuery, result.getNextToken()); } else { result = doQuery(countQuery, null); } nextToken = result.getNextToken(); totalCount += getCountValue(result); } return nextToken; }
From source file:com.davidgildeh.hadoop.input.simpledb.SimpleDBDAO.java
License:Apache License
/** * Gets the next item from the Domain. Needs to iterate through the results * until we reach the limit for number of items * /*from w ww. ja v a2 s .c o m*/ * @param nextToken The token to get the next Item * @param limit The size of items to fetch * @return Returns the SelectResult with the Item */ public List<Item> getItems(String nextToken, int limit) { List<Item> items = new ArrayList<Item>(); // Count of total items int totalItems = 0; String currentToken = nextToken; while (totalItems < limit) { SelectResult results = doQuery(createQuery(false, MAX_SELECT_LIMIT), currentToken); for (Item item : results.getItems()) { if (totalItems < limit) { items.add(item); totalItems++; } } currentToken = results.getNextToken(); // If currentToken is null, means there's no more data if (currentToken == null) { break; } } return items; }