How do I read data from cache using JavaAPI after I put it through jdbc?

aryndin Source

For instance, I've created table using next DDL-query:

(id int PRIMARY KEY, city_id int, name varchar, company varchar, age int)
  WITH "template=partitioned, value_type=MyPerson";

Now i'm going to have it read from cache as MyPerson object. How do I do that? Do I need also to define MyPerson class? What if it would contain some (or totally) other fields that than Person table has?



answered 6 months ago Valentin Kulichenko #1

You can either create the MyPerson class or use withKeepBinary flag and BinaryObject API. See here for more details:

If you use the latter, you will have all the fields available. If you deserialize into a class instance, you will of course only have fields that are available in the class. Anything else would be ignored. Fields that exist in class but not in cache will be initialized with default values (nulls and zeros).

answered 6 months ago dmagda #2

It's easy to do. Skim through this GitHub project that shows how to blend SQL and key-value APIs together. It covers your scenario:

comments powered by Disqus