javaignitedistributed-caching

Optimal Approach for Caching/Persistence for custom model


I am fairly new to Ignite and trying it out. My usecase is I have a model that needs to be cached/persisted. It's not a traditional pojo model moreover i want to keep the storage and the model decoupled. So i cannot use it in the traditional sense with annotating the appropriate keys/indexes in the pojo. And being able to execute a query on the cached data is needed.

So far based on whatever I've read and my usecase, the only option's I see are:

  1. Go the complete SQL route i.e. CREATE TABLE, INSERT, REMOVE, SELECT via jdbc using Batch Exec.

  2. Store it as a BinaryObject i.e.

IgniteCache<BinaryObject, BinaryObject>

But with this, I am not sure if I can get querying support. Since it would get stored as a blob/byte[].

So what I am looking for is, are there other options that I might have missed out? For #1, is there a way to use jdbc/SQL and locking, given I am using atomicity=transactional.

For #2, is there a way I can add querying support to it. I looked at https://github.com/dmagda/ignite_world_demo/blob/master/src/main/java/demo/keyvalue/KeyValueBinaryDataProcessing.java but it does not cover querying.

Update for folks who might run into this.

Tried binary approach and it works. The reference link does use a pojo (not exactly what i wanted). But on looking further, the main point was to set a valueType to the QueryEntity and it need not be a class name, just mapping value to reference back during object creation during put and similarly during query.

queryEntity.setValueType("employee");

//this can be now referenced while creating an object
ignite.binary().builder("employee");

// similarly used while querying
SqlFieldsQuery sqlQuery = new SqlFieldsQuery("select * from employee");

Solution

  • You can store it as BinaryObject, and you can have limited querying support by specifying some fields to map to SQL via QueryEntities.

    Then, you can get the whole key/value by doing queries like

    SELECT _key, _val FROM pojo WHERE name = ?;
    

    Please note that you will need to use Native SQL API, JDBC won't do.