Hi Chetan,

I'm not sure about #1 and #3 - why do you add all entities as a list with a
single key? Typically this is not how Ignite is used.
Proper way is to add each entity (Car) as a separate cache entry, with
unique key (id), like in #2.

As soon as you have all data in cache, each Car with a unique id, and you
have an SQL listener set up, event handler can look like this:

static void Changed(object sender, RecordChangedEventArgs<Car> e)
{
    var ignite = Ignition.GetIgnite();
    var cache = ignite.GetCache<int, Car>("cars");

    switch (e.ChangeType)
    {
        case ChangeType.Update:
            cache.Put(e.ID, e);
            break;
        case ChangeType.Delete:
            cache.Remove(e.ID);
            break;
    }
}

Let me know if this makes sense.

Thanks,
Pavel


On Wed, Jun 7, 2017 at 11:41 AM, Chetan D <ccheta...@gmail.com> wrote:

> Hi Pavel,
>
> I am using the same car program which you have written in blog and i have
> some doubts on that.
>
> I have the following scenarios which i have doubts on.
>
> 1.#region using put
>                     List<car> directcar = new List<car>();
>                     while (rdr.Read())
>                     {
>                         directcar.Add(new car(rdr["Name"].ToString(),
> Convert.ToDouble(rdr["Power"])));
>                     }
>                     cache.Put(1, directcar);
>                     #endregion put
> Here i am creating a cache and adding list of values with a single key
>
> 2.Using data streamer
>  //using (var ldr = ignite.GetDataStreamer<int, car>(cacheCfg.Name))
>                     //{
>                     // //ldr.PerNodeBufferSize = 1024;
>
>
>                     // while (rdr.Read())
>                     // {
>                     // ldr.AddData((int)rdr[0], new
> car(rdr["Name"].ToString(),Convert.ToDouble(rdr["Power"])));
>
>                     // Console.WriteLine("LDR" + ldr.ToString());
>
>                     // }
>
>                     //}
> here i am using datastreamer and adding each values with a key
>
> 3. #region adding all elements as list with single key using get
> datastremer
>                     using (var ldr = ignite.GetDataStreamer<int,
> List<car>>(cacheCfg.Name))
>                     {
>                         List<car> cars = new List<car>();
>
>                         while (rdr.Read())
>                         {
>                             cars.Add(new car(rdr["Name"].ToString(),
> Convert.ToDouble(rdr["Power"])));
>                         }
>                         ldr.AddData(1, cars);
>                         Console.WriteLine("LDR" + ldr.ToString());
>
>                     }
>                     #region reading from cache
>                     foreach (ICacheEntry<int, List<car>> car in cache)
>                     {
>                         foreach (car cars in car.Value)
>                         {
>                             Console.WriteLine(cars.ToString());
>                         }
>                         Console.WriteLine(car.Value.ToList());
>
>
>                     }
>                     #endregion
> here i am using data streamer to add list of values with a single key.
>
> so now when this application is running and all the cache data has been
> loaded i have added a new record in my table.
>
> so for that i have added a listener like this
>
>  var mapper = new ModelToTableMapper<car>();
>                 mapper.AddMapping(c => c.ID, "ID");
>                 mapper.AddMapping(c => c.Name, "Name");
>                 mapper.AddMapping(c => c.Power, "Power");
>                 mapper.AddMapping(c => c.IsAvailable, "IsAvailable");
>
>
>
>                 using (var dep = new SqlTableDependency<car>(ad.sqlconnection,
> "Cars", mapper))
>                 {
>                     dep.OnChanged += Changed;
>                     dep.Start();
>
>                     Console.WriteLine("Press a key to exit");
>                     Console.ReadKey();
>
>                     dep.Stop();
>                 }
>                 #endregion
>   static void Changed(object sender, RecordChangedEventArgs<car> e)
>         {
>             if (e.ChangeType != ChangeType.None)
>             {
>                 var changedEntity = e.Entity;
>                 Console.WriteLine("DML operation: " + e.ChangeType);
>                 Console.WriteLine("ID: " + changedEntity.ID);
>                 Console.WriteLine("Name: " + changedEntity.Name);
>                 Console.WriteLine("Power: " + changedEntity.Power);
>                 Console.WriteLine("IsAvailable: " +
> changedEntity.IsAvailable);
>
>                 Console.WriteLine("<----------
> ------------------------------------------------------------
> ---------------->");
> }
>
> so my question is when a new record has been added to my table i get a
> event triggered and will get the value which is inserted.
>
> so now how to add the new value to existing cache say by using
> datastreamer which works on list i need to add this row to end of list in
> existing cache.
>
> Delete
> when record is deleted i get a event and i need to delete that record from
> existing cache.
>
> Update
> when a column of table is updated say NAME column i need to update that
> particular column value in cache.
>
> can you please help me how to implement this.
>
>             }
>

Reply via email to