You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ignite.apache.org by davida <da...@live.com> on 2017/02/03 07:54:24 UTC

How to write-through when database contains identity column

Hi all, 
I have implemented write-through using CacheStoreAdapter. The object being
inserted contains identity column in the database and as a so, generates
value in DB (this value is also my cache key). I have noticed that when
CacheStoreAdapter.Write(object key, object val) method is executed as a
result of Put operation (e.g. Id=-1 while calling Put), the entry is not in
the cache yet, while Write method is executed.

So the question is, can I somehow modify the key entry in WriteMethod to
assign Idenity value coming from DB ? Also is there a better way to Put
entries with idenity column (i.e. IGenerators) ? 

public override void Write(object key, object val)
        {
            Program.Log("Write " + key.ToString());
            var kpi = (val as IBinaryObject).Deserialize<KPIDetail>();
            int newKey = new KPIDetailsRepo().InsertOrUpdate(kpi);
        
            // at this point the given key is not in the cache yet. However
changing key or val object won't impact the value inserted into the cache
             key = newKey;
             val = (val as IBinaryObject).ToBuilder().SetField<int>("ID",
newKey).Build();
        }

Thanks



--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/How-to-write-through-when-database-contains-identity-column-tp10412.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.

Re: How to write-through when database contains identity column

Posted by davida <da...@live.com>.
спасибо Andrew



--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/How-to-write-through-when-database-contains-identity-column-tp10412p10433.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.

Re: How to write-through when database contains identity column

Posted by Andrey Mashenkov <an...@gmail.com>.
Hi david,

This will not work.
1. You can't replace key parameter as it passed by value.
2. Even it you do this somehow this will be wrong, due to Write() method
will be run on node that own partitions that old key belongs to by
affinity, but not the new key.

It looks like it is not supported. However you are free to implement custom
id generator [1]

[1] http://apacheignite.gridgain.org/docs/id-generator


On Fri, Feb 3, 2017 at 10:54 AM, davida <da...@live.com> wrote:

> Hi all,
> I have implemented write-through using CacheStoreAdapter. The object being
> inserted contains identity column in the database and as a so, generates
> value in DB (this value is also my cache key). I have noticed that when
> CacheStoreAdapter.Write(object key, object val) method is executed as a
> result of Put operation (e.g. Id=-1 while calling Put), the entry is not in
> the cache yet, while Write method is executed.
>
> So the question is, can I somehow modify the key entry in WriteMethod to
> assign Idenity value coming from DB ? Also is there a better way to Put
> entries with idenity column (i.e. IGenerators) ?
>
> public override void Write(object key, object val)
>         {
>             Program.Log("Write " + key.ToString());
>             var kpi = (val as IBinaryObject).Deserialize<KPIDetail>();
>             int newKey = new KPIDetailsRepo().InsertOrUpdate(kpi);
>
>             // at this point the given key is not in the cache yet. However
> changing key or val object won't impact the value inserted into the cache
>              key = newKey;
>              val = (val as IBinaryObject).ToBuilder().SetField<int>("ID",
> newKey).Build();
>         }
>
> Thanks
>
>
>
> --
> View this message in context: http://apache-ignite-users.
> 70518.x6.nabble.com/How-to-write-through-when-database-
> contains-identity-column-tp10412.html
> Sent from the Apache Ignite Users mailing list archive at Nabble.com.
>



-- 
С уважением,
Машенков Андрей Владимирович
Тел. +7-921-932-61-82

Best regards,
Andrey V. Mashenkov
Cerr: +7-921-932-61-82