我使用下面的Java 6代码来查询Gemfire 6.5缓存。
我的问题是我试图使用来自区域中对象的方法调用来过滤我的结果但是由于某种原因它抱怨java.lang.String不包含我试图使用的方法谈论MyEntity,因为这个类是缓存中的对象。
我最好的猜测是,dersialization有一些有趣的东西,并且该类作为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
使用Query q而不是q1运行它可以正常工作,所以它似乎能够访问MyEntity进行反序列化,但是如果我尝试这样的话:
Query q1 = queryService.newQuery("SELECT DISTINCT * FROM /rootregion/traderegion o WHERE (MyEntity)o.getEventId = 'X123'");
我得到一个错误,不知道MyEntity是什么。
答案 0 :(得分:0)
事实证明,在该区域中使用了一个心跳,空字符串对象,我只需要过滤结果以删除它,然后再使用我的MyEntity特定方法和变量进行过滤。
Query q = queryService.newQuery("SELECT * FROM (SELECT * FROM /rootregion/traderegion WHERE toString()!='') WHERE eventId='X123'");
这会过滤掉空对象,只留下MyEntity对象进行进一步处理