开发者

how to use FetchOptions in google app engine datastor

how to use FetchOptions functions in php?

I want to know how to use the limit and offset functions in the below query code?

<?php
import com.google.appengine.api.datastore;
import com.google.appengine.api.datastore.Query;
import com.google.appengine.api.datastore.DatastoreServiceFactory;
import com.google.appengine.api.datastore.FetchOptions;

$q = new Query('test');
//http://code.google.com/appengine/docs/java/javadoc/com/google/appengine/api/datastore/Query.html
//http://code.google.com/appengine/docs/java/javadoc/com/google/appengine/api/datastore/FetchOptions.html

$q->addFilter('fi开发者_C百科eld1','EQUAL' ,'value1');
$dataService = DatastoreServiceFactory::getDatastoreService();
$prepared = $dataService->prepare($q);
foreach($prepared->asIterable() as $i) {
echo $field1 = $i->getProperty('field1');
echo $field2 = $i->getProperty('field2');
}
?>


import com.google.appengine.api.datastore.Query;
import com.google.appengine.api.datastore.Query.FilterOperator;
import com.google.appengine.api.datastore.Query.FilterOperator.EQUAL;
import com.google.appengine.api.datastore.Query.FilterOperator.GREATER_THAN;
import com.google.appengine.api.datastore.Query.FilterOperator.GREATER_THAN_OR_EQUAL;
import com.google.appengine.api.datastore.Query.FilterOperator.IN;
import com.google.appengine.api.datastore.Query.FilterOperator.LESS_THAN;
import com.google.appengine.api.datastore.Query.FilterOperator.LESS_THAN_OR_EQUAL;
import com.google.appengine.api.datastore.Query.FilterOperator.NOT_EQUAL;

import com.google.appengine.api.datastore.Query.SortDirection.ASCENDING;
import com.google.appengine.api.datastore.Query.SortDirection.DESCENDING;

import com.google.appengine.api.datastore.DatastoreServiceFactory;

// only way I got this working is to use java_class and put on variable or constant...
define('FetchOptionsBuilder', java_class('com.google.appengine.api.datastore.FetchOptions$Builder'));

// query
$q = new Query('test');

// filter
$q->addFilter('field1', EQUAL, 'value1');

// sort
$q->addSort('field1', ASCENDING);

// offset and count
$dataService = DatastoreServiceFactory::getDatastoreService();
$prepared = $dataService->prepare($q);
echo $prepared->countEntities(FetchOptionsBuilder->withOffset(0));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜