You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ignite.apache.org by Edison <xe...@163.com> on 2015/10/12 03:14:38 UTC

Using Json object to replace POJO

Hi,


I'm new to Ignite, and after going through the docs and some source codes, it seems currently Ignite has only provided java POJO based adapters and cache stores. 
Sometimes, we use JSON objects directly with persist layer, to avoid the expense of OR-mapping and fast content change. 
So I'm trying to override CacheAbstractJdbcStore to implement this, taking JSONObject as V. Not sure whether this is a good direction. 
However, it'll be great if Ignite can provide this support by default. 


Will Ignite plan to do this, or there has already been such function? 


Thank you!

Re: Using Json object to replace POJO

Posted by Alexey Kuznetsov <ak...@gridgain.com>.
Edison, I think [1] is what you are looking for.

As I understand this feature is under development for right now.
You can watch for changes on this issue in Ignite JIRA: register in JIRA
and add yourself to watchers and you will be notified by e-mail.

[1] https://issues.apache.org/jira/browse/IGNITE-962


On Mon, Oct 12, 2015 at 8:14 AM, Edison <xe...@163.com> wrote:

> Hi,
>
> I'm new to Ignite, and after going through the docs and some source codes,
> it seems currently Ignite has only provided java POJO based adapters and
> cache stores.
> Sometimes, we use JSON objects directly with persist layer, to avoid the
> expense of OR-mapping and fast content change.
> So I'm trying to override CacheAbstractJdbcStore to implement this, taking
> JSONObject as V. Not sure whether this is a good direction.
> However, it'll be great if Ignite can provide this support by default.
>
> Will Ignite plan to do this, or there has already been such function?
>
> Thank you!
>
>
>
>



-- 
Alexey Kuznetsov
GridGain Systems
www.gridgain.com

Re: Re: Re: Using different SQL to load cache every time?

Posted by Dmitriy Setrakyan <ds...@apache.org>.
On Sun, Oct 25, 2015 at 6:17 PM, Edison <xe...@163.com> wrote:

> It's pretty simple. In the top API, they'll call method like read(String
> sql, List<Object> parameters), then I'll use Ignite to read from the cache
> or db(if not hit).
>

Hm… not sure how you can know if SQL is a hit or a miss. What if you only
have a partial state in memory and the rest on disk? Is this possible?


> The thing is, every time the sql provide could be different.
> So how could I make a CacheStore to accept different sql dynamically?
>
Or, in which context should I save the sql so that I can pick it out in
> CacheStore?
>

The only method in CacheStore which can work with free-form SQL is
loadCache() method. Please see the javadoc here:
http://s.apache.org/loadCache


>
>
>
> At 2015-10-24 07:59:14, "Dmitriy Setrakyan" <ds...@apache.org> wrote:
>
> I don’t think I understand the use case. Can you please explain the
> sequence of API calls you plan to make and the desired effect?
>
> On Fri, Oct 23, 2015 at 2:32 AM, Edison <xe...@163.com> wrote:
>
>>
>> Actually, I'm trying to implement SQL ACID function.
>> For the top user, they only need to provide the table and sql.
>> Then, in a common interface, I'll make the the adapter to accept the sql
>> and do the real ACID operation on the cache as well as database.
>> Thus, the sql to run from the top user could be different every time.
>>
>>
>> At 2015-10-23 15:57:51, "Dmitriy Setrakyan" <ds...@apache.org>
>> wrote:
>>
>> I am a bit confused with the question. In the subject it says “load
>> cache”, but in the body it says “query cache”.
>>
>> If the question is about “loading cache", then, as Sergi suggested, you
>> need to implement your own CacheStore. You can take any of the cache stores
>> already provided and adapt them for your needs. More on CacheStore here:
>> https://apacheignite.readme.io/docs/persistent-store
>>
>> If the question is about “querying cache” in memory, then you can create
>> SQL queries dynamically on the fly and execute them over Ignite data grid.
>> More on SQL here: https://apacheignite.readme.io/docs/sql-queries
>>
>> D.
>>
>> On Thu, Oct 22, 2015 at 11:40 PM, Edison <xe...@163.com> wrote:
>>
>>> Hi,
>>>
>>> Instead of given the SQL in EntryMapping, is it possible to use dynamic
>>> SQL to query the cache every time?
>>> If yes, how?
>>>
>>> Thanks,
>>>
>>>
>>>
>>>
>>
>>
>>
>>
>>
>
>
>
>
>

Re:Re: Re: Using different SQL to load cache every time?

Posted by Edison <xe...@163.com>.
It's pretty simple. In the top API, they'll call method like read(String sql, List<Object> parameters), then I'll use Ignite to read from the cache or db(if not hit).
The thing is, every time the sql provide could be different.
So how could I make a CacheStore to accept different sql dynamically?
Or, in which context should I save the sql so that I can pick it out in CacheStore?



At 2015-10-24 07:59:14, "Dmitriy Setrakyan" <ds...@apache.org> wrote:

I don’t think I understand the use case. Can you please explain the sequence of API calls you plan to make and the desired effect?



On Fri, Oct 23, 2015 at 2:32 AM, Edison <xe...@163.com> wrote:



Actually, I'm trying to implement SQL ACID function. 
For the top user, they only need to provide the table and sql.
Then, in a common interface, I'll make the the adapter to accept the sql and do the real ACID operation on the cache as well as database.
Thus, the sql to run from the top user could be different every time. 



At 2015-10-23 15:57:51, "Dmitriy Setrakyan" <ds...@apache.org> wrote:

I am a bit confused with the question. In the subject it says “load cache”, but in the body it says “query cache”.


If the question is about “loading cache", then, as Sergi suggested, you need to implement your own CacheStore. You can take any of the cache stores already provided and adapt them for your needs. More on CacheStore here: https://apacheignite.readme.io/docs/persistent-store


If the question is about “querying cache” in memory, then you can create SQL queries dynamically on the fly and execute them over Ignite data grid. More on SQL here: https://apacheignite.readme.io/docs/sql-queries


D.


On Thu, Oct 22, 2015 at 11:40 PM, Edison <xe...@163.com> wrote:

Hi,


Instead of given the SQL in EntryMapping, is it possible to use dynamic SQL to query the cache every time? 
If yes, how?


Thanks,




 







 



Re: Re: Using different SQL to load cache every time?

Posted by Dmitriy Setrakyan <ds...@apache.org>.
I don’t think I understand the use case. Can you please explain the
sequence of API calls you plan to make and the desired effect?

On Fri, Oct 23, 2015 at 2:32 AM, Edison <xe...@163.com> wrote:

>
> Actually, I'm trying to implement SQL ACID function.
> For the top user, they only need to provide the table and sql.
> Then, in a common interface, I'll make the the adapter to accept the sql
> and do the real ACID operation on the cache as well as database.
> Thus, the sql to run from the top user could be different every time.
>
>
> At 2015-10-23 15:57:51, "Dmitriy Setrakyan" <ds...@apache.org> wrote:
>
> I am a bit confused with the question. In the subject it says “load
> cache”, but in the body it says “query cache”.
>
> If the question is about “loading cache", then, as Sergi suggested, you
> need to implement your own CacheStore. You can take any of the cache stores
> already provided and adapt them for your needs. More on CacheStore here:
> https://apacheignite.readme.io/docs/persistent-store
>
> If the question is about “querying cache” in memory, then you can create
> SQL queries dynamically on the fly and execute them over Ignite data grid.
> More on SQL here: https://apacheignite.readme.io/docs/sql-queries
>
> D.
>
> On Thu, Oct 22, 2015 at 11:40 PM, Edison <xe...@163.com> wrote:
>
>> Hi,
>>
>> Instead of given the SQL in EntryMapping, is it possible to use dynamic
>> SQL to query the cache every time?
>> If yes, how?
>>
>> Thanks,
>>
>>
>>
>>
>
>
>
>
>

Re:Re: Using different SQL to load cache every time?

Posted by Edison <xe...@163.com>.

Actually, I'm trying to implement SQL ACID function. 
For the top user, they only need to provide the table and sql.
Then, in a common interface, I'll make the the adapter to accept the sql and do the real ACID operation on the cache as well as database.
Thus, the sql to run from the top user could be different every time. 



At 2015-10-23 15:57:51, "Dmitriy Setrakyan" <ds...@apache.org> wrote:

I am a bit confused with the question. In the subject it says “load cache”, but in the body it says “query cache”.


If the question is about “loading cache", then, as Sergi suggested, you need to implement your own CacheStore. You can take any of the cache stores already provided and adapt them for your needs. More on CacheStore here: https://apacheignite.readme.io/docs/persistent-store


If the question is about “querying cache” in memory, then you can create SQL queries dynamically on the fly and execute them over Ignite data grid. More on SQL here: https://apacheignite.readme.io/docs/sql-queries


D.


On Thu, Oct 22, 2015 at 11:40 PM, Edison <xe...@163.com> wrote:

Hi,


Instead of given the SQL in EntryMapping, is it possible to use dynamic SQL to query the cache every time? 
If yes, how?


Thanks,




 



Re: Using different SQL to load cache every time?

Posted by Dmitriy Setrakyan <ds...@apache.org>.
I am a bit confused with the question. In the subject it says “load cache”,
but in the body it says “query cache”.

If the question is about “loading cache", then, as Sergi suggested, you
need to implement your own CacheStore. You can take any of the cache stores
already provided and adapt them for your needs. More on CacheStore here:
https://apacheignite.readme.io/docs/persistent-store

If the question is about “querying cache” in memory, then you can create
SQL queries dynamically on the fly and execute them over Ignite data grid.
More on SQL here: https://apacheignite.readme.io/docs/sql-queries

D.

On Thu, Oct 22, 2015 at 11:40 PM, Edison <xe...@163.com> wrote:

> Hi,
>
> Instead of given the SQL in EntryMapping, is it possible to use dynamic
> SQL to query the cache every time?
> If yes, how?
>
> Thanks,
>
>
>
>

Re: Using different SQL to load cache every time?

Posted by Sergi Vladykin <se...@gmail.com>.
I don't think it is possible with JdbcStore, if you have special
requirements you can implement custom CacheStore yourself.

Could you please describe better your use case? May it is possible to find
easier way to workaround it.

Sergi

2015-10-23 9:40 GMT+03:00 Edison <xe...@163.com>:

> Hi,
>
> Instead of given the SQL in EntryMapping, is it possible to use dynamic
> SQL to query the cache every time?
> If yes, how?
>
> Thanks,
>
>
>
>

Using different SQL to load cache every time?

Posted by Edison <xe...@163.com>.
Hi,


Instead of given the SQL in EntryMapping, is it possible to use dynamic SQL to query the cache every time? 
If yes, how?


Thanks,

Re: Using Json object to replace POJO

Posted by Dmitriy Setrakyan <ds...@apache.org>.
On Mon, Oct 12, 2015 at 8:41 PM, xeseo <xe...@163.com> wrote:

> Thanks for reply.
> well, for better understanding, I'll take an example.
> Let's say I have a table in database, table A(C1,C2).
> What I'm trying to do is reading content from database with the below SQL:
> select C1 as empName, C2 as empScore from A
> , then mapping the result into a JSON object, e.g.
> {"empName":"Edison","empScore":90}, to return.
> And JSON string as result is also acceptable, not sure whether [1] is the
> same thing.
>
> [1] https://issues.apache.org/jira/browse/IGNITE-962
>
>
Yes, IGNITE-962 is the same thing. You will be able to run SQL over JSON
when this ticket is complete.


>
> dsetrakyan wrote
> > JSONObject is also just a Java object.
>
> Although JSON Object is also a Java POJO, but I don't think I can use
> CacheJdbcPojoStore directly for this purpose.
> What I'm currently doing is making a class which implements CacheStore,
> following the source of CacheAbstractJdbcStore to handle db connection,
> reading, write etc, and build JSON object to return.
>
> Not sure if this is the right way.


It is the right away.


> Meanwhile, it''ll be great if Ignite can provide such function by default.
>

I think we can consider it once the IGNITE-962 is implemented.


>
>
>
> --
> View this message in context:
> http://apache-ignite-users.70518.x6.nabble.com/Using-Json-object-to-replace-POJO-tp1585p1597.html
> Sent from the Apache Ignite Users mailing list archive at Nabble.com.
>

Re: Using Json object to replace POJO

Posted by xeseo <xe...@163.com>.
Thanks for reply. 
well, for better understanding, I'll take an example.
Let's say I have a table in database, table A(C1,C2).
What I'm trying to do is reading content from database with the below SQL:
select C1 as empName, C2 as empScore from A
, then mapping the result into a JSON object, e.g.
{"empName":"Edison","empScore":90}, to return.
And JSON string as result is also acceptable, not sure whether [1] is the
same thing.

[1] https://issues.apache.org/jira/browse/IGNITE-962


dsetrakyan wrote
> JSONObject is also just a Java object.

Although JSON Object is also a Java POJO, but I don't think I can use
CacheJdbcPojoStore directly for this purpose.
What I'm currently doing is making a class which implements CacheStore,
following the source of CacheAbstractJdbcStore to handle db connection,
reading, write etc, and build JSON object to return.

Not sure if this is the right way. Meanwhile, it''ll be great if Ignite can
provide such function by default.



--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/Using-Json-object-to-replace-POJO-tp1585p1597.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.

Re: Using Json object to replace POJO

Posted by Dmitriy Setrakyan <ds...@apache.org>.
On Sun, Oct 11, 2015 at 6:14 PM, Edison <xe...@163.com> wrote:

> Sometimes, we use JSON objects directly with persist layer, to avoid the
> expense of OR-mapping and fast content change. So I'm trying to override
> CacheAbstractJdbcStore to implement this, taking JSONObject as V. Not sure
> whether this is a good direction.
>

JSONObject is also just a Java object. If you are using Ignite just as a
key-value store, then the existing API should suffice.

It sounds like you are asking about automatic OR mapping from JsonObject to
a relational database. If you have an existing tool that you are currently
using for it, you could simply invoke this tool from your CacheStore
implementation. You don't need to implement CacheAbstractJdbcStore for it,
by the way, you can use the CacheStore interface directly.

Will Ignite plan to do this, or there has already been such function?
>

I think that existing Ignite APIs should suffice for your use case. Can you
provide more detail as to exactly what kind of additional functionality you
would need?


>
>
> Thank you!
>
>
>
>