Created
January 21, 2010 17:01
-
-
Save shin1ogawa/282950 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static List<Entity> asyncQuery(List<Query> queries, FetchOptions fetchOptions) | |
throws InterruptedException, ExecutionException { | |
@SuppressWarnings("unchecked") | |
Delegate<Environment> delegate = ApiProxy.getDelegate(); | |
Environment env = ApiProxy.getCurrentEnvironment(); | |
ApiConfig config = new ApiProxy.ApiConfig(); | |
config.setDeadlineInSeconds(5.0); | |
List<Future<byte[]>> futures = new ArrayList<Future<byte[]>>(queries.size()); | |
for (Query query : queries) { | |
futures.add(delegate.makeAsyncCall(env, "datastore_v3", "RunQuery", PbUtil | |
.toQueryRequestPb(query, fetchOptions).toByteArray(), config)); | |
} | |
List<List<Entity>> lists = new ArrayList<List<Entity>>(); | |
for (Future<byte[]> future : futures) { | |
DatastorePb.QueryResult rPb = new DatastorePb.QueryResult(); | |
rPb.mergeFrom(future.get()); | |
Iterator<EntityProto> it = rPb.resultIterator(); | |
List<Entity> entities = new ArrayList<Entity>(); | |
while (it.hasNext()) { | |
entities.add(EntityTranslator.createFromPb(it.next())); | |
} | |
lists.add(entities); | |
} | |
Map<Key, Entity> map = new HashMap<Key, Entity>(); | |
for (List<Entity> list : lists) { | |
for (Entity entity : list) { | |
if (map.containsKey(entity.getKey()) == false) { | |
map.put(entity.getKey(), entity); | |
} | |
} | |
} | |
return new ArrayList<Entity>(map.values()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment