本文整理汇总了Java中com.google.appengine.api.datastore.PreparedQuery.asIterable方法的典型用法代码示例。如果您正苦于以下问题:Java PreparedQuery.asIterable方法的具体用法?Java PreparedQuery.asIterable怎么用?Java PreparedQuery.asIterable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.appengine.api.datastore.PreparedQuery
的用法示例。
在下文中一共展示了PreparedQuery.asIterable方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getAllSessions
import com.google.appengine.api.datastore.PreparedQuery; //导入方法依赖的package包/类
@Override
public Map<String, SessionData> getAllSessions() {
final String originalNamespace = NamespaceManager.get();
NamespaceManager.set("");
try {
DatastoreService ds = DatastoreServiceFactory.getDatastoreService();
PreparedQuery pq = ds.prepare(new Query(SESSION_ENTITY_TYPE));
Map<String, SessionData> sessions = new HashMap<>();
for (Entity entity : pq.asIterable()) {
sessions.put(entity.getKey().getName(), createSessionFromEntity(entity));
}
return sessions;
} finally {
NamespaceManager.set(originalNamespace);
}
}
示例2: doGet
import com.google.appengine.api.datastore.PreparedQuery; //导入方法依赖的package包/类
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
/* prepare users */
DatastoreService service = DatastoreServiceFactory.getDatastoreService();
Query query = new Query("User");
PreparedQuery pq = service.prepare(query);
ArrayList<User> users = new ArrayList<User>();
for(Entity entity : pq.asIterable()) {
User user = new User(entity);
users.add(user);
}
req.setAttribute("users", users);
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/WEB-INF/backend/users.jsp");
dispatcher.forward(req, resp);
}
示例3: doGet
import com.google.appengine.api.datastore.PreparedQuery; //导入方法依赖的package包/类
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
/* prepare remarks */
UserDomain domain = UserDomain.getInstance();
DatastoreService service = DatastoreServiceFactory.getDatastoreService();
Query query = new Query("Remark");
query.addSort("createdAt", Query.SortDirection.DESCENDING);
PreparedQuery pq = service.prepare(query);
ArrayList<Remark> remarks = new ArrayList<Remark>();
for (Entity entity : pq.asIterable()) {
Remark remark = new Remark(entity);
remarks.add(remark);
}
req.setAttribute("remarks", remarks);
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/WEB-INF/backend/remarks.jsp");
dispatcher.forward(req, resp);
}
示例4: doGet
import com.google.appengine.api.datastore.PreparedQuery; //导入方法依赖的package包/类
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
/* prepare talks */
UserDomain domain = UserDomain.getInstance();
DatastoreService service = DatastoreServiceFactory.getDatastoreService();
Query query = new Query("Talk");
query.addSort("createdAt", Query.SortDirection.DESCENDING);
PreparedQuery pq = service.prepare(query);
ArrayList<Talk> talks = new ArrayList<Talk>();
for (Entity talk : pq.asIterable()) {
Talk talkValue = new Talk(talk);
talks.add(talkValue);
}
req.setAttribute("talks", talks);
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/WEB-INF/backend/talks.jsp");
dispatcher.forward(req, resp);
}
示例5: getPatients
import com.google.appengine.api.datastore.PreparedQuery; //导入方法依赖的package包/类
public List<Patient> getPatients(List<String> patientIdList) {
Query.Filter userIdFilter = new Query.FilterPredicate("userId", Query.FilterOperator.IN, patientIdList);
Query.Filter roleFilter = new Query.FilterPredicate("role", Query.FilterOperator.EQUAL, RoleType.PATIENT.name());
Query query = new Query("User").setFilter(Query.CompositeFilterOperator.and(userIdFilter, roleFilter));
DatastoreService service = DatastoreServiceFactory.getDatastoreService();
PreparedQuery preparedQuery = service.prepare(query);
ArrayList<Patient> patients = new ArrayList<Patient>();
for(Entity entity : preparedQuery.asIterable()) {
User user = new User(entity);
Patient patient = new Patient();
patient.setUserId(user.getUserId());
patient.setFirstName(user.getFirstName());
patient.setLastName(user.getLastName());
patients.add(patient);
}
return patients;
}
示例6: getByDeviceId
import com.google.appengine.api.datastore.PreparedQuery; //导入方法依赖的package包/类
/**
* Gets a not null list of device entities by device id.
*
* @param deviceId the id of the device.
*/
protected List<DeviceEntity> getByDeviceId(String deviceId) {
List<DeviceEntity> result = new ArrayList<DeviceEntity>();
Filter deviceIdFilter =
new FilterPredicate(DeviceEntity.DEVICEID_PROPERTY, FilterOperator.EQUAL, deviceId);
Query query = new Query(DeviceEntity.KIND).setFilter(deviceIdFilter);
PreparedQuery preparedQuery = dataStore.prepare(query);
for (Entity entity : preparedQuery.asIterable()) {
result.add(new DeviceEntity(entity));
}
return result;
}
开发者ID:GoogleCloudPlatform,项目名称:solutions-griddler-sample-backend-java,代码行数:21,代码来源:DeviceService.java
示例7: getGamePlayEntities
import com.google.appengine.api.datastore.PreparedQuery; //导入方法依赖的package包/类
/**
* Gets all GamePlay entities for a given game.
*
*/
private List<GamePlayEntity> getGamePlayEntities(long gameId) {
List<GamePlayEntity> gamePlays = new ArrayList<GamePlayEntity>();
// All GamePlay entities for a given game belong to the same entity group rooted at the game
// entity.
Key ancestorKey = KeyFactory.createKey(GameEntity.KIND, gameId);
Query query = new Query(GamePlayEntity.KIND).setAncestor(ancestorKey);
PreparedQuery preparedQuery = dataStore.prepare(query);
for (Entity gamePlayEntity : preparedQuery.asIterable()) {
gamePlays.add(new GamePlayEntity(gamePlayEntity));
}
return gamePlays;
}
示例8: getPlayers
import com.google.appengine.api.datastore.PreparedQuery; //导入方法依赖的package包/类
/**
* Gets a list of players that a given user can play with. This implementation simply returns the
* list of all players other than the current user.
*
* @param user user making the request.
*/
public List<Player> getPlayers(User user) {
List<Player> results = new ArrayList<Player>();
Filter activePlayersFilter =
new FilterPredicate(PlayerEntity.ACTIVE_PROPERTY, FilterOperator.EQUAL, true);
Query query = new Query(PlayerEntity.KIND).setFilter(activePlayersFilter);
PreparedQuery preparedQuery = dataStore.prepare(query);
for (Entity entity : preparedQuery.asIterable()) {
PlayerEntity playerEntity = new PlayerEntity(entity);
if (!playerEntity.getEmail().equalsIgnoreCase(user.getEmail())) {
results.add(new Player(playerEntity.getId(), playerEntity.getNickname()));
}
}
return results;
}
开发者ID:GoogleCloudPlatform,项目名称:solutions-griddler-sample-backend-java,代码行数:24,代码来源:PlayerService.java
示例9: getShortTexts
import com.google.appengine.api.datastore.PreparedQuery; //导入方法依赖的package包/类
public List<ShortTextDataStore> getShortTexts() {
Filter filter = new FilterPredicate("user",
FilterOperator.EQUAL,
UserServiceFactory.getUserService()
.getCurrentUser().getNickname());
Query query = getQuery().setFilter(filter)
.addSort("date", SortDirection.DESCENDING);
PreparedQuery pq = getPreparedQuery(query);
List<ShortTextDataStore> data = new ArrayList<>();
for (Entity textEntity: pq.asIterable()) {
data.add(new ShortTextDataStore(textEntity));
}
return data;
}
示例10: listRawEntity
import com.google.appengine.api.datastore.PreparedQuery; //导入方法依赖的package包/类
public Iterable<Entity> listRawEntity(Query q, Boolean returnKeysOnly) {
DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
if (returnKeysOnly) {
q.setKeysOnly();
}
PreparedQuery pq = datastore.prepare(q);
return pq.asIterable();
}
示例11: timeZonesArray
import com.google.appengine.api.datastore.PreparedQuery; //导入方法依赖的package包/类
public static ArrayList<TimeZone> timeZonesArray() {
DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
Query q = new Query(TimeZone.DatastoreProperties.KIND.getName());
q.addProjection(new PropertyProjection(TimeZone.DatastoreProperties.TIME_ZONE_ID.getName(), String.class));
PreparedQuery pq = datastore.prepare(q);
ArrayList<TimeZone> timeZones = new ArrayList<TimeZone>();
for(Entity result : pq.asIterable())
timeZones.add(new TimeZone(result));
return timeZones;
}
示例12: getSessionsByUserKey
import com.google.appengine.api.datastore.PreparedQuery; //导入方法依赖的package包/类
public static ArrayList<Session> getSessionsByUserKey(DatastoreService datastore, Key userKey) {
Filter userFilter = new FilterPredicate(DatastoreProperties.USER_KEY.getName(), FilterOperator.EQUAL, userKey);
Query q = new Query(DatastoreProperties.KIND.getName());
q.setFilter(userFilter);
PreparedQuery pq = datastore.prepare(q);
ArrayList<Session> sessions = new ArrayList<Session>();
for(Entity result : pq.asIterable())
sessions.add(new Session(result));
return sessions;
}
示例13: execute
import com.google.appengine.api.datastore.PreparedQuery; //导入方法依赖的package包/类
@Override
ExecutionResult execute(DatastoreConnection conn) {
DatastoreService ds = conn.getDatastoreService();
Query q = "*".equals(kind) ? new Query() : new Query(kind);
if (fields==null)
q.setKeysOnly();
if (filters!=null) {
for (Object k : filters.keySet()) {
q.addFilter((String)k, FilterOperator.EQUAL, filters.get(k));
}
}
PreparedQuery pq = ds.prepare(q);
Iterable<Entity> i = pq.asIterable();
JsonArray a = new JsonArray();
for (Entity result : i) {
JsonObject obj = new JsonObject();
obj.put("__key__", result.getKey());
if (fields != null) {
Map<String, Object> props = result.getProperties();
for (Object f : fields) {
Object val = props.get(f);
obj.put((String) f, val);
}
}
a.add(obj);
}
return new ExecutionResult(0, a);
}
示例14: listFiles
import com.google.appengine.api.datastore.PreparedQuery; //导入方法依赖的package包/类
/**
* Returns the paginated list of uploaded files.
*
* @param user the authenticated user.
* @param offset the file list offset.
* @param limit the file list limit.
* @return the paginated list of uploaded files.
*/
@ApiMethod(name = "listFiles", path = "files", httpMethod = HttpMethod.GET)
@Validate
public List<FileData> listFiles(
@Auth User user,
@Named("offset") @DefaultValue("0") @Min(0) int offset,
@Named("limit") @DefaultValue("100") @Min(0) @Max(100) int limit) {
Query q = new Query(Constants.ENTITY_NAME);
PreparedQuery pq = datastore.prepare(q);
Iterable<Entity> entities = pq.asIterable(FetchOptions.Builder.withOffset(offset).limit(limit));
Iterable<FileData> files = Iterables.transform(entities, entityToFileData());
return Lists.newArrayList(files);
}
示例15: doGet
import com.google.appengine.api.datastore.PreparedQuery; //导入方法依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public final void doGet(final HttpServletRequest req,
final HttpServletResponse resp)
throws IOException {
// First retrieve messages from the memcache
MemcacheService memcacheService = MemcacheServiceFactory
.getMemcacheService();
List<String> messages =
(List<String>) memcacheService.get(Constants.MESSAGE_CACHE_KEY);
if (messages == null) {
// If no messages in the memcache, look for the datastore
DatastoreService datastore =
DatastoreServiceFactory.getDatastoreService();
PreparedQuery query = datastore.prepare(
new Query("PubsubMessage").addSort("receipt-time",
Query.SortDirection.DESCENDING));
messages = new ArrayList<>();
for (Entity entity : query.asIterable(
FetchOptions.Builder.withLimit(MAX_COUNT))) {
String message = (String) entity.getProperty("message");
messages.add(message);
}
// Store them to the memcache for future use.
memcacheService.put(Constants.MESSAGE_CACHE_KEY, messages);
}
ObjectMapper mapper = new ObjectMapper();
resp.setContentType("application/json; charset=UTF-8");
mapper.writeValue(resp.getWriter(), messages);
resp.getWriter().close();
}