这是我的问题。因为我使用的是 JDO,所以数据保存在数据存储后端。现在我想用带有条件的查询来检索数据。例如,
public List<Query> getQueries(final EntityKind entityKind) throws RuntimeException {
System.out.println("In getQueries()!!!" + entityKind);
if (entityKind == null) {
logger.log(Level.SEVERE, "QueryService : getQueries() : entityKind is null.");
throw new RuntimeException("QueryService : getQueries() : entityKind is null.");
}
final long entityId = entityKind.getId();
PersistenceManager pm = PMF.getPersistenceManager();
List<Query> queryList = (List<Query>) new TransactionTemplate(pm).execute(new TransactionCallback<List<Query>>() {
public List<Query> doInTransaction(PersistenceManager pm) {
javax.jdo.Query query = pm.newQuery(Query.class,"SELECT FROM Query WHERE entityKindId == entityId");
Collection<Query> c = pm.detachCopyAll((Collection<Query>) query.execute(entityId));
return new ArrayList<Query>(c);
}
});
return queryList;
}
但这不起作用。这个我也试过了
public List<Query> getQueries(final EntityKind entityKind) throws RuntimeException {
System.out.println("In getQueries()!!!" + entityKind);
if (entityKind == null) {
logger.log(Level.SEVERE, "QueryService : getQueries() : entityKind is null.");
throw new RuntimeException("QueryService : getQueries() : entityKind is null.");
}
final long entityId = entityKind.getId();
PersistenceManager pm = PMF.getPersistenceManager();
List<Query> entityKindFields = (List<Query>) new TransactionTemplate(pm).execute(new TransactionCallback<List<Query>>() {
public List<Query> doInTransaction(PersistenceManager pm) {
javax.jdo.Query query = pm.newQuery(Query.class);
query.setFilter("entityKindId == :entityId");
Collection<Query> c = pm.detachCopyAll((Collection<Query>) query.execute(entityKindId));
return new ArrayList<Query>(c);
}
});
return queryList;
}
这也行不通。请帮忙!