Nikhil,
If you can't configure PDX on the client (why not, btw?), then you can use
a function to send the data from the client to the server, and then do the
put in that function on the server. That will store the object in PDX
serialized form. Then you can use gfsh to query it back.
Querying from a java client will only work for projections, though, since
the object won't be able to be deserialized on the client.
Here is some code as an example.
Execution execution = FunctionService
.onRegion(this.region)
.withArgs(new Object[] {"AAPL", 100, 114.00})
.withFilter(Collections.singleton(String.valueOf(i)));
ResultCollector collector = execution.execute("PutFunction");
The PutFunction execute method would look like:
public void execute(FunctionContext context) {
// Get region, key and data
RegionFunctionContext rfc = (RegionFunctionContext) context;
Region<String,Trade> region = rfc.getDataSet();
String key = (String) rfc.getFilter().iterator().next();
Object[] arguments = (Object[]) rfc.getArguments();
System.out.println("Executing " + getId() + " with " + key + "->" +
Arrays.toString(arguments));
// Put value
Trade value = new Trade(key, (String)arguments[0], (Integer)arguments[1],
(Float)arguments[2]);
region.put(key, value);
// Return result
context.getResultSender().lastResult(true);
}
gfsh>query --query="SELECT id FROM /data WHERE id='1'"
Result : true
startCount : 0
endCount : 20
Rows : 1
Result
------
1
gfsh>query --query="SELECT * FROM /data WHERE id='1'"
Result : true
startCount : 0
endCount : 20
Rows : 1
shares | price | id | cusip
------ | ---------------- | -- | -----
22 | 329.297607421875 | 1 | HMIN
Barry Oglesby
GemFire Advanced Customer Engineering (ACE)
For immediate support please contact Pivotal Support at
http://support.pivotal.io/
On Thu, Dec 3, 2015 at 10:37 AM, Vincent Ford <[email protected]> wrote:
> Hi Nikhil,
>
> You need to do one or the other. Without the classes on the server
> classpath then a client will only be able to do gets and puts against the
> server if not using PDX. The serialization of the entry starts at the
> client and default is to use standard Java serialization but this requires
> classes be provided on the server side for deserialization when doing query
> or other operations. Will you have native clients in the future or will
> memory footprint be important when scaling the application then you should
> consider using PDX at the clients.
>
> *Vince Ford*
> GemFire Sustenance Engineering
> Beaverton, OR USA
> 503-533-3726 (office)
> http://www.pivotal.io
> Open Source Project Geode https://geode.incubator.apache.org/
> <https://network.pivotal.io/products/project-geode>
>
> On Thu, Dec 3, 2015 at 10:12 AM, Nikhil Chandrappa <[email protected]
> >
> wrote:
>
> > Hi,
> >
> > *Issue*:
> >
> > Unable to query the Gemfire region. I get the following exception
> >
> > gfsh>query --query="SELECT firstName FROM /Account WHERE id=1"
> >
> > Result : false
> > startCount : 0
> > endCount : 20
> > Message : A ClassNotFoundException was thrown while trying to
> > deserialize cached value.
> >
> > NEXT_STEP_NAME : END
> >
> > *Context*:
> >
> > We are using Spring Data Gemfire caching for storing the cached objects
> in
> > to Gemfire. We want to be able to query the Gemfire region to see the
> cache
> > data.
> >
> > Following are the constraints we have,
> >
> > 1. we cannot enable the PDX serializer on the client
> > 2. Domain objects cannot be placed on the Gemfire server classpath
> >
> > *Analysis:*
> >
> > *a)*
> > we have configured Gemfire cluster with PDX serialization, however
> Gemfire
> > will store the objects as Java Serialized object. is this a valid
> behavior?
> >
> > *b)*
> > If we use the query service like below,
> >
> > // Log for debugging
> >
> > cache.getLogger().info("Executing Query: "+ queryStr);
> >
> > SelectResults results = (SelectResults) query.execute();
> >
> > // Log for debugging
> >
> > cache.getLogger().info("After Query Execution");
> >
> > I am getting "A ClassNotFoundException was thrown while trying to
> > deserialize cached value."
> >
> > What are the options that we have for querying the regions with
> constraints
> > that are mentioned above? We want to able to query the Gemfire regions
> > without having the domain objects present on the classpath.
> >
> > *Configurations:*
> >
> > ClientCache.xml
> >
> > <?xml version="1.0" encoding="utf-8"?>
> > <beans xmlns="http://www.springframework.org/schema/beans"
> > xmlns:cache="http://www.springframework.org/schema/cache"
> > xmlns:context="http://www.springframework.org/schema/context"
> > xmlns:gfe="http://www.springframework.org/schema/gemfire"
> > xmlns:gfe-data="
> http://www.springframework.org/schema/data/gemfire"
> > xmlns:p="http://www.springframework.org/schema/p"
> > xmlns:util="http://www.springframework.org/schema/util"
> > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> > xsi:schemaLocation="
> > http://www.springframework.org/schema/beans
> > http://www.springframework.org/schema/beans/spring-beans.xsd
> > http://www.springframework.org/schema/cache
> > http://www.springframework.org/schema/cache/spring-cache.xsd
> > http://www.springframework.org/schema/context
> > http://www.springframework.org/schema/context/spring-context.xsd
> > http://www.springframework.org/schema/gemfire
> > http://www.springframework.org/schema/gemfire/spring-gemfire.xsd
> > http://www.springframework.org/schema/data/gemfire
> >
> http://www.springframework.org/schema/data/gemfire/spring-data-gemfire.xsd
> > http://www.springframework.org/schema/util
> > http://www.springframework.org/schema/util/spring-util.xsd
> > ">
> >
> >
> > <util:properties id="clientConfigurationSettings">
> > <prop key="pivotal.cache.specs.directory">specs</prop>
> > </util:properties>
> >
> > <context:property-placeholder location="classpath:server.properties"
> > properties-ref="clientConfigurationSettings"/>
> >
> > <util:properties id="gemfireCacheConfigurationSettings">
> > <prop key="log-level">config</prop>
> > <prop key="cluster-ssl-enabled">true</prop>
> > <prop
> >
> >
> key="cluster-ssl-truststore">/Users/nchandrappa/Documents/grid/security/cacerts.keystore</prop>
> > <prop key="cluster-ssl-truststore-password">password</prop>
> > </util:properties>
> >
> > <gfe:pool id="serverConnectionPool">
> > <gfe:locator host="localhost" port="10334"/>
> > </gfe:pool>
> >
> > <gfe:client-cache properties-ref="gemfireCacheConfigurationSettings"
> > id="gemfireCache" pool-name="serverConnectionPool"/>
> >
> > <cache:annotation-driven/>
> >
> > <bean id="cacheManager"
> >
> >
> class="pivotal.gemfire.core.cache.manager.RegionCreationGemFireCacheManager"
> > p:cache-ref="gemfireCache"/>
> > <bean class="pivotal.gemfire.core.cache.manager.RegionCreator" />
> >
> > <context:component-scan base-package="pivotal.client"/>
> >
> > </beans>
> >
> >
> > ServerCache.xml
> >
> > <?xml version="1.0"?>
> > <!DOCTYPE cache PUBLIC
> > "-//GemStone Systems, Inc.//GemFire Declarative Caching 8.0//EN"
> > "http://www.gemstone.com/dtd/cache8_0.dtd">
> >
> > <cache>
> > <pdx read-serialized="true" />
> > </cache>
> >
> > Thanks,
> > Nikhil
> >
>