我正在使用下面的Java 6代码来查询Gemfire 6.5缓存。
我的问题是我试图使用来自区域中对象的方法调用使用 WHERE 过滤我的结果但由于某种原因,它抱怨 java.lang.String 不包含我尝试使用的方法,当它应该谈论 MyEntity 时,因为正是这个类是缓存中的对象。
我最好的猜测是,去啰化有一些有趣的东西,并且该类作为 String 类出现,此时它不包含该方法,然后使用该方法转换为 MyEntity 类,并且代码正在尝试在类转换之前从 MyEntity 调用该方法。
package gemfire.run;
import com.gemstone.gemfire.DataSerializable;
import com.gemstone.gemfire.Instantiator;
import com.gemstone.gemfire.cache.client.ClientCache;
import com.gemstone.gemfire.cache.client.ClientCacheFactory;
import com.gemstone.gemfire.cache.query.Query;
import com.gemstone.gemfire.cache.query.QueryService;
import com.gemstone.gemfire.cache.query.SelectResults;
import entity.MyEntity;
public class QueryServerCache {
@SuppressWarnings({ "unchecked", "unused" })
public static void main(String[] args) {
System.out.println("Start Program");
Instantiator.register(new Instantiator(MyEntity.class, 60151) {
@Override
public DataSerializable newInstance() {
return new MyEntity();
}
});
ClientCache clientCache = new ClientCacheFactory().addPoolServer("myServer.net", 12345).set("log-level", "error").create();
QueryService queryService = clientCache.getQueryService();
Query q1 = queryService.newQuery("SELECT DISTINCT * FROM /rootregion/traderegion o WHERE o.getEventId = 'X123'");
Query q = queryService.newQuery("SELECT * FROM /rootregion/traderegion LIMIT 10");
try {
SelectResults<MyEntity> results = (SelectResults<MyEntity>) q1.execute();
System.out.println("n" + results.size() + "n");
for (MyEntity o : results) {
System.out.println(o.getEventId());
}
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("nExit Program");
}
}
代码的堆栈跟踪为:
Start Program
com.gemstone.gemfire.cache.client.ServerOperationException: While performing a remote query
at com.gemstone.gemfire.cache.client.internal.AbstractOp.processChunkedResponse(AbstractOp.java:323)
at com.gemstone.gemfire.cache.client.internal.QueryOp$QueryOpImpl.processResponse(QueryOp.java:145)
at com.gemstone.gemfire.cache.client.internal.AbstractOp.attemptReadResponse(AbstractOp.java:150)
at com.gemstone.gemfire.cache.client.internal.AbstractOp.attempt(AbstractOp.java:363)
at com.gemstone.gemfire.cache.client.internal.ConnectionImpl.execute(ConnectionImpl.java:245)
at com.gemstone.gemfire.cache.client.internal.pooling.PooledConnection.execute(PooledConnection.java:321)
at com.gemstone.gemfire.cache.client.internal.OpExecutorImpl.executeWithPossibleReAuthentication(OpExecutorImpl.java:646)
at com.gemstone.gemfire.cache.client.internal.OpExecutorImpl.execute(OpExecutorImpl.java:108)
at com.gemstone.gemfire.cache.client.internal.OpExecutorImpl.execute(OpExecutorImpl.java:84)
at com.gemstone.gemfire.cache.client.internal.PoolImpl.execute(PoolImpl.java:610)
at com.gemstone.gemfire.cache.client.internal.QueryOp.execute(QueryOp.java:47)
at com.gemstone.gemfire.cache.client.internal.ServerProxy.query(ServerProxy.java:80)
at com.gemstone.gemfire.cache.query.internal.DefaultQuery.executeOnServer(DefaultQuery.java:248)
at com.gemstone.gemfire.cache.query.internal.DefaultQuery.execute(DefaultQuery.java:135)
at com.gemstone.gemfire.cache.query.internal.DefaultQuery.execute(DefaultQuery.java:117)
at gemfire.run.QueryServerCache.main(QueryServerCache.java:33)
Caused by: com.gemstone.gemfire.cache.query.NameNotFoundException: No public attribute named ' getEventId ' was found in class java.lang.String
at com.gemstone.gemfire.cache.query.internal.AttributeDescriptor.getReadMember(AttributeDescriptor.java:184)
at com.gemstone.gemfire.cache.query.internal.AttributeDescriptor.read(AttributeDescriptor.java:70)
at com.gemstone.gemfire.cache.query.internal.AttributeDescriptor.read(AttributeDescriptor.java:56)
at com.gemstone.gemfire.cache.query.internal.PathUtils.evaluateAttribute(PathUtils.java:63)
at com.gemstone.gemfire.cache.query.internal.CompiledPath.evaluate(CompiledPath.java:127)
at com.gemstone.gemfire.cache.query.internal.CompiledComparison.evaluate(CompiledComparison.java:72)
at com.gemstone.gemfire.cache.query.internal.CompiledSelect.doNestedIterations(CompiledSelect.java:449)
at com.gemstone.gemfire.cache.query.internal.CompiledSelect.doNestedIterations(CompiledSelect.java:490)
at com.gemstone.gemfire.cache.query.internal.CompiledSelect.doIterationEvaluate(CompiledSelect.java:376)
at com.gemstone.gemfire.cache.query.internal.CompiledSelect.evaluate(CompiledSelect.java:304)
at com.gemstone.gemfire.cache.query.internal.DefaultQuery.executeUsingContext(DefaultQuery.java:382)
at com.gemstone.gemfire.cache.query.internal.DefaultQuery.execute(DefaultQuery.java:181)
at com.gemstone.gemfire.cache.query.internal.DefaultQuery.execute(DefaultQuery.java:117)
at com.gemstone.gemfire.internal.cache.tier.sockets.BaseCommand.processQueryUsingParams(BaseCommand.java:1216)
at com.gemstone.gemfire.internal.cache.tier.sockets.BaseCommand.processQuery(BaseCommand.java:1167)
at com.gemstone.gemfire.internal.cache.tier.sockets.command.Query.cmdExecute(Query.java:76)
at com.gemstone.gemfire.internal.cache.tier.sockets.BaseCommand.execute(BaseCommand.java:133)
at com.gemstone.gemfire.internal.cache.tier.sockets.ServerConnection.doNormalMsg(ServerConnection.java:758)
at com.gemstone.gemfire.internal.cache.tier.sockets.ServerConnection.doOneMessage(ServerConnection.java:879)
at com.gemstone.gemfire.internal.cache.tier.sockets.ServerConnection.run(ServerConnection.java:1067)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at com.gemstone.gemfire.internal.cache.tier.sockets.AcceptorImpl$1$1.run(AcceptorImpl.java:504)
at java.lang.Thread.run(Thread.java:662)
Exit Program
使用查询 q 而不是 q1 运行它工作正常,因此它似乎能够访问 MyEntity 进行反序列化,但是如果我尝试类似的东西:
Query q1 = queryService.newQuery("SELECT DISTINCT * FROM /rootregion/traderegion o WHERE (MyEntity)o.getEventId = 'X123'");
我收到一个错误,不知道MyEntity是什么。
因此,事实证明,该区域正在使用一个心跳,空字符串对象,我只需要过滤结果以将其删除,然后使用MyEntity特定的方法和变量进行进一步过滤。
Query q = queryService.newQuery("SELECT * FROM (SELECT * FROM /rootregion/traderegion WHERE toString()!='') WHERE eventId='X123'");
这过滤掉了空对象,只剩下MyEntity对象进行进一步处理