also i am doing this and got the following error dont know what it is.
SqlCommand cmd = new SqlCommand("select Name,Power from Cars", con);
con.Open();
rdr = cmd.ExecuteReader();
#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(2, directcar);
got this exception
Apache.Ignite.Core.Cache.Store.CacheStoreException was unhandled
HResult=-2146233088
Message=class
org.apache.ignite.internal.processors.cache.CachePartialUpdateCheckedException:
Failed to update keys (retry update if possible).: [2]
Source=Apache.Ignite.Core
StackTrace:
at Apache.Ignite.Core.Impl.PlatformTarget.DoOutInOpX(Int32 type,
Action`1 outAction, Func`2 inErrorAction)
at Apache.Ignite.Core.Impl.Cache.CacheImpl`2.DoOutOp[T1,T2](CacheOp
op, T1 x, T2 y)
at Apache.Ignite.Core.Impl.Cache.CacheImpl`2.Put(TK key, TV val)
at Addtableentirely.Program.Main(String[] args) in
C:\Users\M1029218\Documents\Visual Studio
2015\Projects\Apacheignite\Addtableentirely\Program.cs:line 106
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly,
String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence
assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext
executionContext, ContextCallback callback, Object state, Boolean
preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext
executionContext, ContextCallback callback, Object state, Boolean
preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext
executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
HResult=-2147467262
Message=Unable to cast object of type
'System.Collections.Generic.List`1[Addtableentirely.car]' to type
'Addtableentirely.car'.
Source=Apache.Ignite.Core
StackTrace:
at
Apache.Ignite.Core.Impl.Binary.BinaryReflectiveSerializerInternal.Apache.Ignite.Core.Impl.Binary.IBinarySerializerInternal.ReadBinary[T](BinaryReader
reader, IBinaryTypeDescriptor desc, Int32 pos)
at
Apache.Ignite.Core.Impl.Binary.BinaryReader.ReadFullObject[T](Int32 pos)
at
Apache.Ignite.Core.Impl.Binary.BinaryReader.TryDeserialize[T](T& res)
at Apache.Ignite.Core.Impl.Binary.BinaryReader.Deserialize[T]()
at
Apache.Ignite.Core.Impl.Binary.BinaryReader.ReadBinaryObject[T](Boolean
doDetach)
at
Apache.Ignite.Core.Impl.Binary.BinaryReader.TryDeserialize[T](T& res)
at Apache.Ignite.Core.Impl.Binary.BinaryReader.Deserialize[T]()
at Apache.Ignite.Core.Impl.Binary.BinaryReader.ReadObject[T]()
at
Apache.Ignite.Core.Impl.Cache.Store.CacheStoreInternal`2.Invoke(IBinaryStream
stream, Ignite grid)
at
Apache.Ignite.Core.Impl.Cache.Store.CacheStore.Invoke(PlatformMemoryStream
stream, Ignite grid)
at
Apache.Ignite.Core.Impl.Unmanaged.UnmanagedCallbacks.CacheStoreInvoke(Int64
memPtr)
InnerException:
On Wed, Jun 7, 2017 at 3:08 PM, Chetan D <[email protected]> wrote:
> Hi Pavel,
>
> I got that its easy when there is a key with value but my requirement is
> such that i need to store all values of table with single key associated.
>
> The code which you sent is not working and doesnt give any error as well.
>
> you have sent it in case when an update happens.
>
> my question is when a new record has been added and that new record i need
> to insert it to cache.
>
> and also i have a column in my table in which i have updated say in this
> case name value to something else so i need to update that corresponding
> value in cache as well.
>
>
> can you tell me the difference between cache.getandreplace() and
> cache.getandput() they both are doing same thing actually.
>
>
>
> it would be helpfull if i can get answer with respect to list storage.
>
> On Wed, Jun 7, 2017 at 2:34 PM, Pavel Tupitsyn <[email protected]>
> wrote:
>
>> 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 <[email protected]> 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.
>>>
>>> }
>>>
>>
>>
>