在开发人员网站上的所有示例之后,我正在使用 GAE Cloud 端点和 Datastore。生成客户端库时出现无法解决的错误:
“线程“主”java.lang.IllegalArgumentException 中的异常:不支持参数化类型接口 java.lang.Iterable...”
谁能告诉我为什么会收到错误以及如何解决?
这是我的代码:
**Util.java**
package com.davozardini.myfisrtapp;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import com.google.appengine.api.datastore.DatastoreService;
import com.google.appengine.api.datastore.DatastoreServiceFactory;
import com.google.appengine.api.datastore.Entity;
import com.google.appengine.api.datastore.EntityNotFoundException;
import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.PreparedQuery;
import com.google.appengine.api.datastore.Query;
import com.google.appengine.api.datastore.Query.FilterOperator;
/**
* This is the utility class for entity operation methods.
*
*/
public class Util {
private static final Logger logger = Logger.getLogger(Util.class.getCanonicalName());
private static DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
/**
*
* @param entity : entity to be persisted
*/
public static void persistEntity(Entity entity) {
logger.log(Level.INFO, "Saving entity");
datastore.put(entity);
}
/**
* Delete the entity from persistent store represented by the key
* @param key : key to delete the entity from the persistent store
*/
public static void deleteEntity(Key key) {
logger.log(Level.INFO, "Deleting entity");
datastore.delete(key);
}
/**
* Search and return the entity from datastore.
* @param key : key to find the entity
* @return entity
*/
public static Entity findEntity(Key key) {
logger.log(Level.INFO, "Search the entity");
try {
return datastore.get(key);
} catch (EntityNotFoundException e) {
return null;
}
}
/***
* Search entities based on search criteria
* @param kind
* @param searchBy
* : Searching Criteria (Property)
* @param searchFor
* : Searching Value (Property Value)
* @return List all entities of a kind from the cache or datastore (if not
* in cache) with the specified properties
*/
public static Iterable<Entity> listEntities(String kind) {
logger.log(Level.INFO, "Search entities based on search criteria");
Query q = new Query(kind);
PreparedQuery pq = datastore.prepare(q);
return pq.asIterable();
}
}
Person.java 包 com.davozardini.myfisrtapp;
import com.google.appengine.api.datastore.Entity;
import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;
import com.davozardini.myfisrtapp.Util;
import com.google.api.server.spi.config.Api;
import com.google.api.server.spi.config.AnnotationBoolean;
import com.google.api.server.spi.config.ApiMethod;
import com.google.api.server.spi.config.ApiMethod.HttpMethod;
import javax.inject.Named;
@Api(
name = "Person",
version = "v1",
description = "myfisrtapp Person API",
defaultVersion = AnnotationBoolean.TRUE
)
/**
* This class handles all the CRUD operations related to
* People entity.
*
*/
public class Person {
/**
* Get all Person entities
* @return: Iterable<Entity> entities
*/
@ApiMethod(
name = "Person.getAllPersons",
path = "Person",
httpMethod = HttpMethod.GET
)
public static Iterable<Entity> getAllPersons() {
Iterable<Entity> entities = Util.listEntities("Person");
return entities;
}
/**
* Get Person entity
* @param name : key of the Person
* @return: Person entity
*/
public static Entity getPerson(@Named("name")String name) {
Key key = KeyFactory.createKey("Person",name);
return Util.findEntity(key);
}
/**
* Update the product
* @param name: name of the product
* @param description : description
* @return updated product
*/
public static void createPerson(@Named("name")String name, @Named("description")String description) {
Entity person = new Entity("Person");
person.setProperty("name", name);
person.setProperty("description", description);
Util.persistEntity(person);
}
}