本文整理汇总了Java中com.google.appengine.api.datastore.PreparedQuery类的典型用法代码示例。如果您正苦于以下问题:Java PreparedQuery类的具体用法?Java PreparedQuery怎么用?Java PreparedQuery使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PreparedQuery类属于com.google.appengine.api.datastore包,在下文中一共展示了PreparedQuery类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getNationalHighScores
import com.google.appengine.api.datastore.PreparedQuery; //导入依赖的package包/类
/**
* Method to retrieve the national high scores
* @return
*/
public List<Entity> getNationalHighScores(String countryCode){
log.info("Retrieving national high scores");
//create the country code filter
Filter country = new FilterPredicate(Constants.COUNTRY_CODE,FilterOperator.EQUAL,countryCode);
//create the query to read the records sorted by score
Query q = new Query(Constants.RECORD).addSort(Constants.SCORE, SortDirection.DESCENDING);
//set the filter to the query
q.setFilter(country);
PreparedQuery pq = datastore.prepare(q);
//retrieve and return the list of records
return pq.asList(FetchOptions.Builder.withLimit(100));
}
示例2: getMonthlyHighScores
import com.google.appengine.api.datastore.PreparedQuery; //导入依赖的package包/类
/**
* Method to retrieve the monthly high scores
* @return
*/
public List<Entity> getMonthlyHighScores(){
log.info("Retrieving monthly high scores");
//calculate calendar info
Calendar calendar= Calendar.getInstance();
int year=calendar.get(Calendar.YEAR);
int month=calendar.get(Calendar.MONTH);
//create filters
Filter yearFilter = new FilterPredicate(Constants.YEAR,FilterOperator.EQUAL,year);
Filter monthFilter = new FilterPredicate(Constants.MONTH,FilterOperator.EQUAL,month);
//create the query to read the records sorted by score
Query q = new Query(Constants.RECORD).addSort(Constants.SCORE, SortDirection.DESCENDING);
//set filters to the query
q.setFilter(yearFilter);
q.setFilter(monthFilter);
//prepare query
PreparedQuery pq = datastore.prepare(q);
//retrieve and return the list of records
return pq.asList(FetchOptions.Builder.withLimit(100));
}
示例3: getWeeklyHighScores
import com.google.appengine.api.datastore.PreparedQuery; //导入依赖的package包/类
/**
* Method to retrieve the weekly high scores
* @return
*/
public List<Entity> getWeeklyHighScores(){
log.info("Retrieving weekly high scores");
//calculate calendar info
Calendar calendar= Calendar.getInstance();
int year=calendar.get(Calendar.YEAR);
int week=calendar.get(Calendar.WEEK_OF_YEAR);
//create filters
Filter yearFilter = new FilterPredicate(Constants.YEAR,FilterOperator.EQUAL,year);
Filter weekFilter = new FilterPredicate(Constants.WEEK_OF_THE_YEAR,FilterOperator.EQUAL,week);
//create the query to read the records sorted by score
Query q = new Query(Constants.RECORD).addSort(Constants.SCORE, SortDirection.DESCENDING);
//set filters to the query
q.setFilter(yearFilter);
q.setFilter(weekFilter);
//prepare query
PreparedQuery pq = datastore.prepare(q);
//retrieve and return the list of records
return pq.asList(FetchOptions.Builder.withLimit(100));
}
示例4: getDailyHighScores
import com.google.appengine.api.datastore.PreparedQuery; //导入依赖的package包/类
/**
* Method to retrieve the daily high scores
* @return
*/
public List<Entity> getDailyHighScores(){
log.info("Retrieving weekly high scores");
//calculate calendar info
Calendar calendar= Calendar.getInstance();
int year=calendar.get(Calendar.YEAR);
int day=calendar.get(Calendar.DAY_OF_YEAR);
//create filters
Filter yearFilter = new FilterPredicate(Constants.YEAR,FilterOperator.EQUAL,year);
Filter dayFilter = new FilterPredicate(Constants.DAY_OF_THE_YEAR,FilterOperator.EQUAL,day);
//create the query to read the records sorted by score
Query q = new Query(Constants.RECORD).addSort(Constants.SCORE, SortDirection.DESCENDING);
//set filters to the query
q.setFilter(yearFilter);
q.setFilter(dayFilter);
//prepare query
PreparedQuery pq = datastore.prepare(q);
//retrieve and return the list of records
return pq.asList(FetchOptions.Builder.withLimit(100));
}
示例5: listBooks
import com.google.appengine.api.datastore.PreparedQuery; //导入依赖的package包/类
@Override
public Result<Book> listBooks(String startCursorString) {
FetchOptions fetchOptions = FetchOptions.Builder.withLimit(10); // Only show 10 at a time
if (startCursorString != null && !startCursorString.equals("")) {
fetchOptions.startCursor(Cursor.fromWebSafeString(startCursorString)); // Where we left off
}
Query query = new Query(BOOK_KIND) // We only care about Books
.addSort(Book.TITLE, SortDirection.ASCENDING); // Use default Index "title"
PreparedQuery preparedQuery = datastore.prepare(query);
QueryResultIterator<Entity> results = preparedQuery.asQueryResultIterator(fetchOptions);
List<Book> resultBooks = entitiesToBooks(results); // Retrieve and convert Entities
Cursor cursor = results.getCursor(); // Where to start next time
if (cursor != null && resultBooks.size() == 10) { // Are we paging? Save Cursor
String cursorString = cursor.toWebSafeString(); // Cursors are WebSafe
return new Result<>(resultBooks, cursorString);
} else {
return new Result<>(resultBooks);
}
}
示例6: listBooksByUser
import com.google.appengine.api.datastore.PreparedQuery; //导入依赖的package包/类
@Override
public Result<Book> listBooksByUser(String userId, String startCursorString) {
FetchOptions fetchOptions = FetchOptions.Builder.withLimit(10); // Only show 10 at a time
if (startCursorString != null && !startCursorString.equals("")) {
fetchOptions.startCursor(Cursor.fromWebSafeString(startCursorString)); // Where we left off
}
Query query = new Query(BOOK_KIND) // We only care about Books
// Only for this user
.setFilter(new Query.FilterPredicate(
Book.CREATED_BY_ID, Query.FilterOperator.EQUAL, userId))
// a custom datastore index is required since you are filtering by one property
// but ordering by another
.addSort(Book.TITLE, SortDirection.ASCENDING);
PreparedQuery preparedQuery = datastore.prepare(query);
QueryResultIterator<Entity> results = preparedQuery.asQueryResultIterator(fetchOptions);
List<Book> resultBooks = entitiesToBooks(results); // Retrieve and convert Entities
Cursor cursor = results.getCursor(); // Where to start next time
if (cursor != null && resultBooks.size() == 10) { // Are we paging? Save Cursor
String cursorString = cursor.toWebSafeString(); // Cursors are WebSafe
return new Result<>(resultBooks, cursorString);
} else {
return new Result<>(resultBooks);
}
}
示例7: hasRelation
import com.google.appengine.api.datastore.PreparedQuery; //导入依赖的package包/类
/**
* Determine whether this relation already exists.
*
* @return false because we don't care about naming collisions.
* @throws ODKDatastoreException
*/
@Override
public boolean hasRelation(String schema, String tableName, User user) throws ODKDatastoreException {
List<com.google.appengine.api.datastore.Entity> gaeKeys = null;
try {
com.google.appengine.api.datastore.Query query = new com.google.appengine.api.datastore.Query(
schema + "." + tableName);
query.setKeysOnly();
PreparedQuery preparedQuery = ds.prepare(query);
gaeKeys = preparedQuery.asList(FetchOptions.Builder.withLimit(2));
} catch (OverQuotaException e) {
throw new ODKOverQuotaException(e);
} catch (Exception ex) {
// No-op
}
if (gaeKeys == null || gaeKeys.size() == 0)
return false;
return true;
}
示例8: getPagesWrittenBy
import com.google.appengine.api.datastore.PreparedQuery; //导入依赖的package包/类
public static List<StoryPage> getPagesWrittenBy(final String authorId,
final int start, final int end) {
final DatastoreQuery query = new DatastoreQuery(KIND_NAME);
query.addSort(BEGINNING_NUMBER_PROPERTY);
query.addSort(ID_NUMBER_PROPERTY);
query.addSort(ID_VERSION_PROPERTY);
final Filter filter = getAuthorIdFilter(authorId);
query.setFilter(filter);
final Store store = new Store();
final PreparedQuery preparedQuery = store.prepare(query);
final int limit = end - start;
final FetchOptions fetchOptions = FetchOptions.Builder.withLimit(limit);
final int offset = start;
fetchOptions.offset(offset);
final List<DatastoreEntity> entities = DatastoreEntity
.fromPreparedQuery(preparedQuery, fetchOptions);
final List<StoryPage> pages = getPagesFromEntities(entities);
return pages;
}
示例9: getRootPipelinesDisplayName
import com.google.appengine.api.datastore.PreparedQuery; //导入依赖的package包/类
@Override
public Set<String> getRootPipelinesDisplayName() {
Query query = new Query(JobRecord.DATA_STORE_KIND);
query.addProjection(
new PropertyProjection(JobRecord.ROOT_JOB_DISPLAY_NAME, String.class));
query.setDistinct(true);
final PreparedQuery preparedQuery = dataStore.prepare(query);
return tryFiveTimes(new Operation<Set<String>>("getRootPipelinesDisplayName") {
@Override
public Set<String> call() {
Set<String> pipelines = new LinkedHashSet<>();
for (Entity entity : preparedQuery.asIterable()) {
pipelines.add((String) entity.getProperty(JobRecord.ROOT_JOB_DISPLAY_NAME));
}
return pipelines;
}
});
}
示例10: deleteAll
import com.google.appengine.api.datastore.PreparedQuery; //导入依赖的package包/类
private void deleteAll(final String kind, final Key rootJobKey) {
logger.info("Deleting all " + kind + " with rootJobKey=" + rootJobKey);
final int chunkSize = 100;
final FetchOptions fetchOptions = FetchOptions.Builder.withChunkSize(chunkSize);
final PreparedQuery preparedQuery = dataStore.prepare(new Query(kind).setKeysOnly().setFilter(
new FilterPredicate(ROOT_JOB_KEY_PROPERTY, EQUAL, rootJobKey)));
tryFiveTimes(new Operation<Void>("delete") {
@Override
public Void call() {
Iterator<Entity> iter = preparedQuery.asIterator(fetchOptions);
while (iter.hasNext()) {
ArrayList<Key> keys = new ArrayList<>(chunkSize);
for (int i = 0; i < chunkSize && iter.hasNext(); i++) {
keys.add(iter.next().getKey());
}
logger.info("Deleting " + keys.size() + " " + kind + "s with rootJobKey=" + rootJobKey);
dataStore.delete(null, keys);
}
return null;
}
});
}
示例11: 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);
}
}
示例12: 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);
}
示例13: 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);
}
示例14: 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);
}
示例15: 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;
}