как использовать FetchOptions в датасторе движка приложения Google - PullRequest
0 голосов
/ 19 января 2011

как использовать FetchOptions функции в php?

Я хочу знать, как использовать функции limit и offset в следующемкод запроса?

<?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('field1','EQUAL' ,'value1');
$dataService = DatastoreServiceFactory::getDatastoreService();
$prepared = $dataService->prepare($q);
foreach($prepared->asIterable() as $i) {
echo $field1 = $i->getProperty('field1');
echo $field2 = $i->getProperty('field2');
}
?>

1 Ответ

0 голосов
/ 09 февраля 2011
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));
...