You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ignite.apache.org by Muthu <mu...@gmail.com> on 2017/05/30 23:07:47 UTC

Combine two table caches to expose a database view type cache?

Hi Folks,

I need to combine two table caches to expose a database view type cache. Is
there an elegant way to do this where i don't need to manually
set/construct the view's POJO from the result of the join query?

Regards,
Muthu

Re: Combine two table caches to expose a database view type cache?

Posted by Nikolai Tikhonov <nt...@apache.org>.
Muthu,

You can use binary representation instead of POJO classes [1]. I think it
can help you to avoid boilerplate code.

1.
https://apacheignite.readme.io/docs/binary-marshaller#binaryobject-cache-api

On Mon, Jun 5, 2017 at 10:18 PM, Muthu <mu...@gmail.com> wrote:

> Our current application code uses this view in several places. We use
> MyBatis for ORM & it generates the DTO object & everything. The thought is
> if there is way to transparently use Ignite cache for the view instead of
> going to the database & let the rest of the application code use the same
> DTO object as generated by MyBatis.
>
> Regards,
> Muthu
>
> On Mon, Jun 5, 2017 at 12:10 PM, Muthu <mu...@gmail.com> wrote:
>
>>
>> Thanks Nikolai for the suggestion..one other thing i was thinking was to
>> use continuous queries feature to create & update the new cache...but the
>> problem is i still have to manually construct the resultant DTO object
>> (manually set every field in the code). Since this is a view that joins two
>> or three tables with lots of columns i was wondering if there was a way i
>> can auto generate this boiler plate code...
>>
>> Regards,
>> Muthu
>>
>> On Mon, Jun 5, 2017 at 5:44 AM, Nikolai Tikhonov <nt...@apache.org>
>> wrote:
>>
>>> Hello,
>>>
>>> You need to implement your own CacheStore which will execute several
>>> selects for one entry and combine two rows to one cache entry.
>>>
>>> On Thu, Jun 1, 2017 at 9:34 AM, Muthu <mu...@gmail.com> wrote:
>>>
>>>> Hello Folks,
>>>>
>>>> Just to add a little bit more clarity & context...taking the
>>>> Cross-Cache querying example from the ignite docs (copied below) if one
>>>> were to select fields from both Person & Organization table caches in the
>>>> select query what would be the elegant way to construct a domain POJO from
>>>> the query result set instead of constructing it in the application code.
>>>>
>>>>
>>>>    - Cross-Cache SqlFieldsQuery
>>>>    <https://apacheignite.readme.io/docs/sql-queries>
>>>>
>>>> // In this example, suppose Person objects are stored in a // cache named 'personCache' and Organization objects // are stored in a cache named 'orgCache'.IgniteCache<Long, Person> personCache = ignite.cache("personCache");
>>>> // Select with join between Person and Organization to // get the names of all the employees of a specific organization.SqlFieldsQuery sql = new SqlFieldsQuery(
>>>>     "select Person.name  "
>>>>         + "from Person as p, \"orgCache\".Organization as org where "
>>>>         + "p.orgId = org.id "
>>>>         + "and org.name = ?");
>>>> // Execute the query and obtain the query result cursor.try (QueryCursor<List<?>> cursor =  personCache.query(sql.setArgs("Ignite"))) {
>>>>     for (List<?> row : cursor)
>>>>         System.out.println("Person name=" + row.get(0));
>>>> }
>>>>
>>>>
>>>> Regards,
>>>> Muthu
>>>>
>>>> -- The latest fact in modern technology isn't that machines will begin
>>>> to think like people, but that people will begin to think like machines.
>>>> -- Nothing exists except atoms and empty space, everything else is
>>>> opinion - *Democritus*
>>>>
>>>> On Tue, May 30, 2017 at 4:26 PM, Muthu <mu...@gmail.com>
>>>> wrote:
>>>>
>>>>>
>>>>> Just to clarify a little bit i don't want the view created on the
>>>>> database but rather created & exposed purely in ignite. The individual
>>>>> tables are already cached & available as L2 cache (MyBatis L2 cache) in
>>>>> Ignite.
>>>>>
>>>>> Regards,
>>>>> Muthu
>>>>>
>>>>>
>>>>> On Tue, May 30, 2017 at 4:07 PM, Muthu <mu...@gmail.com>
>>>>> wrote:
>>>>>
>>>>>> Hi Folks,
>>>>>>
>>>>>> I need to combine two table caches to expose a database view type
>>>>>> cache. Is there an elegant way to do this where i don't need to manually
>>>>>> set/construct the view's POJO from the result of the join query?
>>>>>>
>>>>>> Regards,
>>>>>> Muthu
>>>>>>
>>>>>>
>>>>>
>>>>
>>>
>>
>

Re: Combine two table caches to expose a database view type cache?

Posted by Muthu <mu...@gmail.com>.
Our current application code uses this view in several places. We use
MyBatis for ORM & it generates the DTO object & everything. The thought is
if there is way to transparently use Ignite cache for the view instead of
going to the database & let the rest of the application code use the same
DTO object as generated by MyBatis.

Regards,
Muthu

On Mon, Jun 5, 2017 at 12:10 PM, Muthu <mu...@gmail.com> wrote:

>
> Thanks Nikolai for the suggestion..one other thing i was thinking was to
> use continuous queries feature to create & update the new cache...but the
> problem is i still have to manually construct the resultant DTO object
> (manually set every field in the code). Since this is a view that joins two
> or three tables with lots of columns i was wondering if there was a way i
> can auto generate this boiler plate code...
>
> Regards,
> Muthu
>
> On Mon, Jun 5, 2017 at 5:44 AM, Nikolai Tikhonov <nt...@apache.org>
> wrote:
>
>> Hello,
>>
>> You need to implement your own CacheStore which will execute several
>> selects for one entry and combine two rows to one cache entry.
>>
>> On Thu, Jun 1, 2017 at 9:34 AM, Muthu <mu...@gmail.com> wrote:
>>
>>> Hello Folks,
>>>
>>> Just to add a little bit more clarity & context...taking the Cross-Cache
>>> querying example from the ignite docs (copied below) if one were to select
>>> fields from both Person & Organization table caches in the select query
>>> what would be the elegant way to construct a domain POJO from the query
>>> result set instead of constructing it in the application code.
>>>
>>>
>>>    - Cross-Cache SqlFieldsQuery
>>>    <https://apacheignite.readme.io/docs/sql-queries>
>>>
>>> // In this example, suppose Person objects are stored in a // cache named 'personCache' and Organization objects // are stored in a cache named 'orgCache'.IgniteCache<Long, Person> personCache = ignite.cache("personCache");
>>> // Select with join between Person and Organization to // get the names of all the employees of a specific organization.SqlFieldsQuery sql = new SqlFieldsQuery(
>>>     "select Person.name  "
>>>         + "from Person as p, \"orgCache\".Organization as org where "
>>>         + "p.orgId = org.id "
>>>         + "and org.name = ?");
>>> // Execute the query and obtain the query result cursor.try (QueryCursor<List<?>> cursor =  personCache.query(sql.setArgs("Ignite"))) {
>>>     for (List<?> row : cursor)
>>>         System.out.println("Person name=" + row.get(0));
>>> }
>>>
>>>
>>> Regards,
>>> Muthu
>>>
>>> -- The latest fact in modern technology isn't that machines will begin
>>> to think like people, but that people will begin to think like machines.
>>> -- Nothing exists except atoms and empty space, everything else is
>>> opinion - *Democritus*
>>>
>>> On Tue, May 30, 2017 at 4:26 PM, Muthu <mu...@gmail.com>
>>> wrote:
>>>
>>>>
>>>> Just to clarify a little bit i don't want the view created on the
>>>> database but rather created & exposed purely in ignite. The individual
>>>> tables are already cached & available as L2 cache (MyBatis L2 cache) in
>>>> Ignite.
>>>>
>>>> Regards,
>>>> Muthu
>>>>
>>>>
>>>> On Tue, May 30, 2017 at 4:07 PM, Muthu <mu...@gmail.com>
>>>> wrote:
>>>>
>>>>> Hi Folks,
>>>>>
>>>>> I need to combine two table caches to expose a database view type
>>>>> cache. Is there an elegant way to do this where i don't need to manually
>>>>> set/construct the view's POJO from the result of the join query?
>>>>>
>>>>> Regards,
>>>>> Muthu
>>>>>
>>>>>
>>>>
>>>
>>
>

Re: Combine two table caches to expose a database view type cache?

Posted by Muthu <mu...@gmail.com>.
Thanks Nikolai for the suggestion..one other thing i was thinking was to
use continuous queries feature to create & update the new cache...but the
problem is i still have to manually construct the resultant DTO object
(manually set every field in the code). Since this is a view that joins two
or three tables with lots of columns i was wondering if there was a way i
can auto generate this boiler plate code...

Regards,
Muthu

On Mon, Jun 5, 2017 at 5:44 AM, Nikolai Tikhonov <nt...@apache.org>
wrote:

> Hello,
>
> You need to implement your own CacheStore which will execute several
> selects for one entry and combine two rows to one cache entry.
>
> On Thu, Jun 1, 2017 at 9:34 AM, Muthu <mu...@gmail.com> wrote:
>
>> Hello Folks,
>>
>> Just to add a little bit more clarity & context...taking the Cross-Cache
>> querying example from the ignite docs (copied below) if one were to select
>> fields from both Person & Organization table caches in the select query
>> what would be the elegant way to construct a domain POJO from the query
>> result set instead of constructing it in the application code.
>>
>>
>>    - Cross-Cache SqlFieldsQuery
>>    <https://apacheignite.readme.io/docs/sql-queries>
>>
>> // In this example, suppose Person objects are stored in a // cache named 'personCache' and Organization objects // are stored in a cache named 'orgCache'.IgniteCache<Long, Person> personCache = ignite.cache("personCache");
>> // Select with join between Person and Organization to // get the names of all the employees of a specific organization.SqlFieldsQuery sql = new SqlFieldsQuery(
>>     "select Person.name  "
>>         + "from Person as p, \"orgCache\".Organization as org where "
>>         + "p.orgId = org.id "
>>         + "and org.name = ?");
>> // Execute the query and obtain the query result cursor.try (QueryCursor<List<?>> cursor =  personCache.query(sql.setArgs("Ignite"))) {
>>     for (List<?> row : cursor)
>>         System.out.println("Person name=" + row.get(0));
>> }
>>
>>
>> Regards,
>> Muthu
>>
>> -- The latest fact in modern technology isn't that machines will begin to
>> think like people, but that people will begin to think like machines.
>> -- Nothing exists except atoms and empty space, everything else is
>> opinion - *Democritus*
>>
>> On Tue, May 30, 2017 at 4:26 PM, Muthu <mu...@gmail.com> wrote:
>>
>>>
>>> Just to clarify a little bit i don't want the view created on the
>>> database but rather created & exposed purely in ignite. The individual
>>> tables are already cached & available as L2 cache (MyBatis L2 cache) in
>>> Ignite.
>>>
>>> Regards,
>>> Muthu
>>>
>>>
>>> On Tue, May 30, 2017 at 4:07 PM, Muthu <mu...@gmail.com>
>>> wrote:
>>>
>>>> Hi Folks,
>>>>
>>>> I need to combine two table caches to expose a database view type
>>>> cache. Is there an elegant way to do this where i don't need to manually
>>>> set/construct the view's POJO from the result of the join query?
>>>>
>>>> Regards,
>>>> Muthu
>>>>
>>>>
>>>
>>
>

Re: Combine two table caches to expose a database view type cache?

Posted by Nikolai Tikhonov <nt...@apache.org>.
Hello,

You need to implement your own CacheStore which will execute several
selects for one entry and combine two rows to one cache entry.

On Thu, Jun 1, 2017 at 9:34 AM, Muthu <mu...@gmail.com> wrote:

> Hello Folks,
>
> Just to add a little bit more clarity & context...taking the Cross-Cache
> querying example from the ignite docs (copied below) if one were to select
> fields from both Person & Organization table caches in the select query
> what would be the elegant way to construct a domain POJO from the query
> result set instead of constructing it in the application code.
>
>
>    - Cross-Cache SqlFieldsQuery
>    <https://apacheignite.readme.io/docs/sql-queries>
>
> // In this example, suppose Person objects are stored in a // cache named 'personCache' and Organization objects // are stored in a cache named 'orgCache'.IgniteCache<Long, Person> personCache = ignite.cache("personCache");
> // Select with join between Person and Organization to // get the names of all the employees of a specific organization.SqlFieldsQuery sql = new SqlFieldsQuery(
>     "select Person.name  "
>         + "from Person as p, \"orgCache\".Organization as org where "
>         + "p.orgId = org.id "
>         + "and org.name = ?");
> // Execute the query and obtain the query result cursor.try (QueryCursor<List<?>> cursor =  personCache.query(sql.setArgs("Ignite"))) {
>     for (List<?> row : cursor)
>         System.out.println("Person name=" + row.get(0));
> }
>
>
> Regards,
> Muthu
>
> -- The latest fact in modern technology isn't that machines will begin to
> think like people, but that people will begin to think like machines.
> -- Nothing exists except atoms and empty space, everything else is opinion
> - *Democritus*
>
> On Tue, May 30, 2017 at 4:26 PM, Muthu <mu...@gmail.com> wrote:
>
>>
>> Just to clarify a little bit i don't want the view created on the
>> database but rather created & exposed purely in ignite. The individual
>> tables are already cached & available as L2 cache (MyBatis L2 cache) in
>> Ignite.
>>
>> Regards,
>> Muthu
>>
>>
>> On Tue, May 30, 2017 at 4:07 PM, Muthu <mu...@gmail.com> wrote:
>>
>>> Hi Folks,
>>>
>>> I need to combine two table caches to expose a database view type cache.
>>> Is there an elegant way to do this where i don't need to manually
>>> set/construct the view's POJO from the result of the join query?
>>>
>>> Regards,
>>> Muthu
>>>
>>>
>>
>

Re: Combine two table caches to expose a database view type cache?

Posted by Muthu <mu...@gmail.com>.
Hello Folks,

Just to add a little bit more clarity & context...taking the Cross-Cache
querying example from the ignite docs (copied below) if one were to select
fields from both Person & Organization table caches in the select query
what would be the elegant way to construct a domain POJO from the query
result set instead of constructing it in the application code.


   - Cross-Cache SqlFieldsQuery
   <https://apacheignite.readme.io/docs/sql-queries>

// In this example, suppose Person objects are stored in a // cache
named 'personCache' and Organization objects // are stored in a cache
named 'orgCache'.IgniteCache<Long, Person> personCache =
ignite.cache("personCache");
// Select with join between Person and Organization to // get the
names of all the employees of a specific organization.SqlFieldsQuery
sql = new SqlFieldsQuery(
    "select Person.name  "
        + "from Person as p, \"orgCache\".Organization as org where "
        + "p.orgId = org.id "
        + "and org.name = ?");
// Execute the query and obtain the query result cursor.try
(QueryCursor<List<?>> cursor =
personCache.query(sql.setArgs("Ignite"))) {
    for (List<?> row : cursor)
        System.out.println("Person name=" + row.get(0));
}


Regards,
Muthu

-- The latest fact in modern technology isn't that machines will begin to
think like people, but that people will begin to think like machines.
-- Nothing exists except atoms and empty space, everything else is opinion
- *Democritus*

On Tue, May 30, 2017 at 4:26 PM, Muthu <mu...@gmail.com> wrote:

>
> Just to clarify a little bit i don't want the view created on the database
> but rather created & exposed purely in ignite. The individual tables are
> already cached & available as L2 cache (MyBatis L2 cache) in Ignite.
>
> Regards,
> Muthu
>
>
> On Tue, May 30, 2017 at 4:07 PM, Muthu <mu...@gmail.com> wrote:
>
>> Hi Folks,
>>
>> I need to combine two table caches to expose a database view type cache.
>> Is there an elegant way to do this where i don't need to manually
>> set/construct the view's POJO from the result of the join query?
>>
>> Regards,
>> Muthu
>>
>>
>

Re: Combine two table caches to expose a database view type cache?

Posted by Muthu <mu...@gmail.com>.
Just to clarify a little bit i don't want the view created on the database
but rather created & exposed purely in ignite. The individual tables are
already cached & available as L2 cache (MyBatis L2 cache) in Ignite.

Regards,
Muthu


On Tue, May 30, 2017 at 4:07 PM, Muthu <mu...@gmail.com> wrote:

> Hi Folks,
>
> I need to combine two table caches to expose a database view type cache.
> Is there an elegant way to do this where i don't need to manually
> set/construct the view's POJO from the result of the join query?
>
> Regards,
> Muthu
>
>