本文整理汇总了Java中com.google.appengine.api.datastore.Cursor.toWebSafeString方法的典型用法代码示例。如果您正苦于以下问题:Java Cursor.toWebSafeString方法的具体用法?Java Cursor.toWebSafeString怎么用?Java Cursor.toWebSafeString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.appengine.api.datastore.Cursor
的用法示例。
在下文中一共展示了Cursor.toWebSafeString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: listBooks
import com.google.appengine.api.datastore.Cursor; //导入方法依赖的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);
}
}
示例2: listBooksByUser
import com.google.appengine.api.datastore.Cursor; //导入方法依赖的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);
}
}
示例3: create
import com.google.appengine.api.datastore.Cursor; //导入方法依赖的package包/类
@Nullable
public static PagingInfo create(@Nullable Cursor afterCursor, int limit, boolean moreResults,
UriInfo uriInfo) {
String afterCursorStr = (afterCursor == null) ? "" : afterCursor.toWebSafeString();
if (afterCursorStr.isEmpty()) {
return null;
} else {
String nextUrl;
if (moreResults) {
Multimap<String, String> queryParams = toMultimap(uriInfo.getQueryParameters());
queryParams.replaceValues(AFTER_CURSOR_PARAM, asList(afterCursorStr));
queryParams.replaceValues(LIMIT_PARAM, asList(String.valueOf(limit)));
nextUrl = URLUtil.buildURL(uriInfo.getAbsolutePath(), queryParams);
} else {
nextUrl = null;
}
return new PagingInfo(nextUrl, afterCursorStr);
}
}
示例4: listQuote
import com.google.appengine.api.datastore.Cursor; //导入方法依赖的package包/类
@ApiMethod(name = "listUsers")
public CollectionResponse<Users> listQuote(@Nullable @com.google.api.server.spi.config.Named("cursor") String cursorString,
@Nullable @com.google.api.server.spi.config.Named("count") Integer count) {
Query<Users> query = ofy().load().type(Users.class);
if (count != null) query.limit(count);
if (cursorString != null && cursorString != "") {
query = query.startAt(Cursor.fromWebSafeString(cursorString));
}
List<Users> records = new ArrayList<Users>();
QueryResultIterator<Users> iterator = query.iterator();
int num = 0;
while (iterator.hasNext()) {
records.add(iterator.next());
if (count != null) {
num++;
if (num == count) break;
}
}
//Find the next cursor
if (cursorString != null && cursorString != "") {
Cursor cursor = iterator.getCursor();
if (cursor != null) {
cursorString = cursor.toWebSafeString();
}
}
return CollectionResponse.<Users>builder().setItems(records).setNextPageToken(cursorString).build();
}
示例5: setResult
import com.google.appengine.api.datastore.Cursor; //导入方法依赖的package包/类
public void setResult(final QueryResultList<Entity> result, final Cursor cursor, final boolean noMore) {
final ArrayList<Entity> list = new ArrayList<>(result);
if (bshFilter != null) {
filterList(list);
}
resultBytes = SerializationHelper.getBytes(list);
hasMore = !noMore;
webCursor = cursor.toWebSafeString();
}
示例6: merge
import com.google.appengine.api.datastore.Cursor; //导入方法依赖的package包/类
private String merge(String cursorString) {
Query<UserAnswer> query = ofy().load().type(UserAnswer.class).limit(1000);
List<UserAnswer> toSaveList = new ArrayList<UserAnswer>();
if (cursorString != null) {
query = query.startAt(Cursor.fromWebSafeString(cursorString));
}
boolean cont = false;
QueryResultIterator<UserAnswer> iterator = query.iterator();
while (iterator.hasNext()) {
UserAnswer userAnswer = iterator.next();
Map<String, String> answers = userAnswer.getAnswers();
if(answers != null) {
String answer = answers.get("householdIncome");
if("$100,000-$149,999".equals(answer) || "$150,000-$199,999".equals(answer) ||
"$200,000-$249,999".equals(answer) || "$300,000 or more".equals(answer)) {
answers.put("householdIncome", "$100,000 or more");
toSaveList.add(userAnswer);
}
}
cont = true;
}
if(toSaveList.size() > 0) {
ofy().save().entities(toSaveList).now();
logger.info(String.format("Merged %d answers", toSaveList.size()));
}
if(cont) {
Cursor cursor = iterator.getCursor();
return cursor.toWebSafeString();
} else {
return null;
}
}
示例7: approve
import com.google.appengine.api.datastore.Cursor; //导入方法依赖的package包/类
private String approve(String cursorString) {
Query<UserAnswer> query = ofy().load().type(UserAnswer.class).limit(30);
if (cursorString != null) {
query = query.startAt(Cursor.fromWebSafeString(cursorString));
}
boolean cont = false;
QueryResultIterator<UserAnswer> iterator = query.iterator();
while (iterator.hasNext()) {
UserAnswer userAnswer = iterator.next();
try {
List<Assignment> assignments = getAssignmentsForHITService.getAssignments(true, userAnswer.getHitId());
for(Assignment assignment: assignments) {
approveAssignmentService.approveAssignment(true, assignment.getAssignmentId());
}
} catch (MturkException e) {
logger.log(Level.WARNING, e.getMessage());
}
cont = true;
}
if(cont) {
Cursor cursor = iterator.getCursor();
return cursor.toWebSafeString();
} else {
return null;
}
}
示例8: dispose
import com.google.appengine.api.datastore.Cursor; //导入方法依赖的package包/类
private String dispose(String cursorString) {
Calendar endCal = Calendar.getInstance();
endCal.setTime(new Date());
endCal.set(Calendar.HOUR_OF_DAY, 0);
endCal.set(Calendar.MINUTE, 0);
endCal.set(Calendar.SECOND, 0);
Calendar startCal = Calendar.getInstance();
startCal.setTime(endCal.getTime());
startCal.add(Calendar.DAY_OF_MONTH, -1);
Query<UserAnswer> query = ofy().load().type(UserAnswer.class)
.filter("date >=", startCal.getTime()).filter("date <", endCal.getTime()).limit(30);
if (cursorString != null) {
query = query.startAt(Cursor.fromWebSafeString(cursorString));
}
boolean cont = false;
QueryResultIterator<UserAnswer> iterator = query.iterator();
while (iterator.hasNext()) {
UserAnswer userAnswer = iterator.next();
try {
disposeHITService.disposeHIT(true, userAnswer.getHitId());
logger.log(Level.INFO, String.format("Disposed HIT %s", userAnswer.getHitId()));
} catch (MturkException e) {
logger.log(Level.WARNING, e.getMessage());
}
cont = true;
}
if(cont) {
Cursor cursor = iterator.getCursor();
return cursor.toWebSafeString();
} else {
return null;
}
}
示例9: listCategory
import com.google.appengine.api.datastore.Cursor; //导入方法依赖的package包/类
/**
* This method lists all the entities inserted in datastore.
* It uses HTTP GET method and paging support.
*
* @return A CollectionResponse class containing the list of all entities
* persisted and a cursor to the next page.
*/
@SuppressWarnings({ "unchecked", "unused" })
@ApiMethod(name = "listCategory")
public CollectionResponse<Category> listCategory(
@Nullable @Named("cursor") String cursorString,
@Nullable @Named("limit") Integer limit) {
EntityManager mgr = null;
Cursor cursor = null;
List<Category> execute = null;
try {
mgr = getEntityManager();
Query query = mgr.createQuery("select from Category as Category");
if (cursorString != null && cursorString != "") {
cursor = Cursor.fromWebSafeString(cursorString);
query.setHint(JPACursorHelper.CURSOR_HINT, cursor);
}
if (limit != null) {
query.setFirstResult(0);
query.setMaxResults(limit);
}
execute = (List<Category>) query.getResultList();
cursor = JPACursorHelper.getCursor(execute);
if (cursor != null)
cursorString = cursor.toWebSafeString();
// Tight loop for fetching all entities from datastore and accomodate
// for lazy fetch.
for (Category obj : execute)
;
} finally {
mgr.close();
}
return CollectionResponse.<Category> builder().setItems(execute)
.setNextPageToken(cursorString).build();
}
示例10: listExpense
import com.google.appengine.api.datastore.Cursor; //导入方法依赖的package包/类
/**
* This method lists all the entities inserted in datastore.
* It uses HTTP GET method and paging support.
*
* @return A CollectionResponse class containing the list of all entities
* persisted and a cursor to the next page.
*/
@SuppressWarnings({ "unchecked", "unused" })
@ApiMethod(name = "listExpense")
public CollectionResponse<Expense> listExpense(
@Nullable @Named("cursor") String cursorString,
@Nullable @Named("limit") Integer limit) {
EntityManager mgr = null;
Cursor cursor = null;
List<Expense> execute = null;
try {
mgr = getEntityManager();
Query query = mgr.createQuery("select from Expense as Expense");
if (cursorString != null && cursorString != "") {
cursor = Cursor.fromWebSafeString(cursorString);
query.setHint(JPACursorHelper.CURSOR_HINT, cursor);
}
if (limit != null) {
query.setFirstResult(0);
query.setMaxResults(limit);
}
execute = (List<Expense>) query.getResultList();
cursor = JPACursorHelper.getCursor(execute);
if (cursor != null)
cursorString = cursor.toWebSafeString();
// Tight loop for fetching all entities from datastore and accomodate
// for lazy fetch.
for (Expense obj : execute)
;
} finally {
mgr.close();
}
return CollectionResponse.<Expense> builder().setItems(execute)
.setNextPageToken(cursorString).build();
}
示例11: listIncome
import com.google.appengine.api.datastore.Cursor; //导入方法依赖的package包/类
/**
* This method lists all the entities inserted in datastore.
* It uses HTTP GET method and paging support.
*
* @return A CollectionResponse class containing the list of all entities
* persisted and a cursor to the next page.
*/
@SuppressWarnings({ "unchecked", "unused" })
@ApiMethod(name = "listIncome")
public CollectionResponse<Income> listIncome(
@Nullable @Named("cursor") String cursorString,
@Nullable @Named("limit") Integer limit) {
EntityManager mgr = null;
Cursor cursor = null;
List<Income> execute = null;
try {
mgr = getEntityManager();
Query query = mgr.createQuery("select from Income as Income");
if (cursorString != null && cursorString != "") {
cursor = Cursor.fromWebSafeString(cursorString);
query.setHint(JPACursorHelper.CURSOR_HINT, cursor);
}
if (limit != null) {
query.setFirstResult(0);
query.setMaxResults(limit);
}
execute = (List<Income>) query.getResultList();
cursor = JPACursorHelper.getCursor(execute);
if (cursor != null)
cursorString = cursor.toWebSafeString();
// Tight loop for fetching all entities from datastore and accomodate
// for lazy fetch.
for (Income obj : execute)
;
} finally {
mgr.close();
}
return CollectionResponse.<Income> builder().setItems(execute)
.setNextPageToken(cursorString).build();
}
示例12: listDeviceInfo
import com.google.appengine.api.datastore.Cursor; //导入方法依赖的package包/类
/**
* This method lists all the entities inserted in datastore. It uses HTTP GET method and paging
* support.
*
* @return A CollectionResponse class containing the list of all entities persisted and a cursor
* to the next page.
*/
@SuppressWarnings({"unchecked", "unused"})
@ApiMethod(name = "listDeviceInfo")
public CollectionResponse<DeviceInfo> listDeviceInfo(
@Nullable @Named("cursor") String cursorString, @Nullable @Named("limit") Integer limit) {
Cursor cursor = null;
List<DeviceInfo> execute = null;
StringBuilder q = new StringBuilder("select from DeviceInfo as d order by timestamp DESC ");
Query query = em.get().createQuery(q.toString());
if (cursorString != null && cursorString != "") {
cursor = Cursor.fromWebSafeString(cursorString);
query.setHint(JPACursorHelper.CURSOR_HINT, cursor);
}
if (limit != null) {
query.setFirstResult(0);
query.setMaxResults(limit);
}
execute = query.getResultList();
cursor = JPACursorHelper.getCursor(execute);
if (cursor != null) {
cursorString = cursor.toWebSafeString();
}
// Tight loop for fetching all entities from datastore and accomodate
// for lazy fetch.
for (DeviceInfo obj : execute) {
;
}
return CollectionResponse.<DeviceInfo> builder().setItems(execute).setNextPageToken(
cursorString).build();
}
示例13: listAccountInfo
import com.google.appengine.api.datastore.Cursor; //导入方法依赖的package包/类
@ApiMethod(name = "listAccountInfo")
public CollectionResponse<AccountInfo> listAccountInfo(
@Nullable @Named("cursor") String cursorString, @Nullable @Named("limit") Integer limit) {
Cursor cursor = null;
StringBuilder q = new StringBuilder("select from AccountInfo as a");
Query query = em.get().createQuery(q.toString());
if (cursorString != null && cursorString != "") {
cursor = Cursor.fromWebSafeString(cursorString);
query.setHint(JPACursorHelper.CURSOR_HINT, cursor);
}
if (limit != null) {
query.setFirstResult(0);
query.setMaxResults(limit);
}
@SuppressWarnings("unchecked")
List<AccountInfo> execute = query.getResultList();
cursor = JPACursorHelper.getCursor(execute);
if (cursor != null) {
cursorString = cursor.toWebSafeString();
}
// Tight loop for fetching all entities from datastore and accomodate
// for lazy fetch.
for (AccountInfo obj : execute) {
;
}
return CollectionResponse.<AccountInfo> builder().setItems(execute).setNextPageToken(
cursorString).build();
}
示例14: listOffer
import com.google.appengine.api.datastore.Cursor; //导入方法依赖的package包/类
/**
* This method lists all the entities inserted in datastore.
* It uses HTTP GET method and paging support.
*
* @return A CollectionResponse class containing the list of all entities
* persisted and a cursor to the next page.
*/
@SuppressWarnings({"unchecked", "unused"})
@ApiMethod(name = "listOffer")
public CollectionResponse<Offer> listOffer(
@Nullable @Named("cursor") String cursorString, @Nullable @Named("limit") Integer limit) {
EntityManager mgr = null;
Cursor cursor = null;
List<Offer> execute = null;
try {
mgr = getEntityManager();
Query query = mgr.createQuery("select from Offer as Offer");
if (cursorString != null && cursorString != "") {
cursor = Cursor.fromWebSafeString(cursorString);
query.setHint(JPACursorHelper.CURSOR_HINT, cursor);
}
if (limit != null) {
query.setFirstResult(0);
query.setMaxResults(limit);
}
execute = (List<Offer>) query.getResultList();
cursor = JPACursorHelper.getCursor(execute);
if (cursor != null) cursorString = cursor.toWebSafeString();
// Tight loop for fetching all entities from datastore and accomodate
// for lazy fetch.
for (Offer obj : execute);
} finally {
mgr.close();
}
return CollectionResponse.<Offer>builder()
.setItems(execute).setNextPageToken(cursorString).build();
}
开发者ID:googlearchive,项目名称:solutions-mobile-shopping-assistant-backend-java,代码行数:44,代码来源:OfferEndpoint.java
示例15: listRecommendation
import com.google.appengine.api.datastore.Cursor; //导入方法依赖的package包/类
/**
* This method lists all the entities inserted in datastore.
* It uses HTTP GET method and paging support.
*
* @return A CollectionResponse class containing the list of all entities
* persisted and a cursor to the next page.
*/
@SuppressWarnings({"unchecked", "unused"})
@ApiMethod(name = "listRecommendation")
public CollectionResponse<Recommendation> listRecommendation(
@Nullable @Named("cursor") String cursorString, @Nullable @Named("limit") Integer limit) {
EntityManager mgr = null;
Cursor cursor = null;
List<Recommendation> execute = null;
try {
mgr = getEntityManager();
Query query = mgr.createQuery("select from Recommendation as Recommendation");
if (cursorString != null && cursorString != "") {
cursor = Cursor.fromWebSafeString(cursorString);
query.setHint(JPACursorHelper.CURSOR_HINT, cursor);
}
if (limit != null) {
query.setFirstResult(0);
query.setMaxResults(limit);
}
execute = (List<Recommendation>) query.getResultList();
cursor = JPACursorHelper.getCursor(execute);
if (cursor != null) cursorString = cursor.toWebSafeString();
// Tight loop for fetching all entities from datastore and accomodate
// for lazy fetch.
for (Recommendation obj : execute);
} finally {
mgr.close();
}
return CollectionResponse.<Recommendation>builder()
.setItems(execute).setNextPageToken(cursorString).build();
}
开发者ID:googlearchive,项目名称:solutions-mobile-shopping-assistant-backend-java,代码行数:44,代码来源:RecommendationEndpoint.java