2011-01-18 41 views
0

如何在php中使用FetchOptions函數?如何在谷歌應用引擎數據中使用FetchOptions

我想知道如何使用限制在下面的查詢碼偏移的功能呢?

<?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'); 
} 
?> 

回答

0
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));