在 Gemfire 6.5 区域的 OQL 查询中调用对象的方法
Invoking a Method on an Object in an OQL Query on a Gemfire 6.5 Region
我正在使用下面的 Java 6 代码来查询 Gemfire 6.5 缓存。
我的问题是我正在尝试使用来自区域中对象的方法调用通过 WHERE 过滤我的结果但出于某种原因它抱怨 java.lang.String 不包含我在以下情况下尝试使用的方法它应该谈论 MyEntity,因为缓存中的对象就是这个 class。
我最好的猜测是反序列化有些有趣,class 作为字符串 class 出现,此时它不包含该方法,然后被转换为MyEntity class 与方法,并且代码试图在 class 转换之前从 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.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 对象供我进一步处理
我正在使用下面的 Java 6 代码来查询 Gemfire 6.5 缓存。
我的问题是我正在尝试使用来自区域中对象的方法调用通过 WHERE 过滤我的结果但出于某种原因它抱怨 java.lang.String 不包含我在以下情况下尝试使用的方法它应该谈论 MyEntity,因为缓存中的对象就是这个 class。
我最好的猜测是反序列化有些有趣,class 作为字符串 class 出现,此时它不包含该方法,然后被转换为MyEntity class 与方法,并且代码试图在 class 转换之前从 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.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 对象供我进一步处理