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:

CREATE TABLE IF NOT EXISTS Person 
(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?

sqlignite

Answers

answered 1 week ago Valentin Kulichenko #1

You can either create the MyPerson class or use withKeepBinary flag and BinaryObject API. See here for more details: https://apacheignite.readme.io/docs/binary-marshaller#binaryobject-cache-api

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 1 week 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: https://github.com/dmagda/ignite_world_demo

comments powered by Disqus