You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ignite.apache.org by crenique <cr...@gmail.com> on 2018/08/13 17:31:34 UTC
Map C# class to Cassandra persistence settings
Hello,
I am integrating Cassandra to ignite.NET.
I followed an example, and managed to make a cache be persisted to Cassandra
with primitive data types.
https://apacheignite-mix.readme.io/v2.6/docs/examples
But is it possible to map C# key/value type classes to the Cassandra
persistence settings ?
<persistence keyspace="test1" table="my_table">
<keyPersistence class="java.lang.Integer" strategy="PRIMITIVE"/>
<valuePersistence class="org.apache.ignite.tests.pojos.Person"
strategy="POJO"/>
</persistence>
This is our C# ignite cache key/value type classes.
------- Cache key type ---------------
public class StateDataKey : IBinarizable
{
[QuerySqlField]
public string CacheKey { get; set; }
[QuerySqlField]
[AffinityKeyMapped]
public long AffinityKey { get; set; }
public StateDataKey() { }
public StateDataKey(string szStateKey, long lAffinityKey)
{
CacheKey = szStateKey;
AffinityKey = lAffinityKey;
}
public void WriteBinary(IBinaryWriter writer)
{
writer.WriteString(nameof(CacheKey), CacheKey);
writer.WriteLong(nameof(AffinityKey), AffinityKey);
}
public void ReadBinary(IBinaryReader reader)
{
CacheKey = reader.ReadString(nameof(CacheKey));
AffinityKey = reader.ReadLong(nameof(AffinityKey));
}
public override string ToString()
{
return string.Format("StateDataKey [Key={0}, Affinity={1}]",
CacheKey, AffinityKey);
}
}
------- Cache value type ---------------
public class StateData : IBinarizable
{
[QuerySqlField(IsIndexed = true)]
public DateTime LastUpdated { get; set; }
[QuerySqlField(IsIndexed = true)]
public DateTime LastPersisted { get; set; }
[QuerySqlField]
public byte[] Data { get; set; }
public StateData() { }
public StateData(byte[] btStateData)
{
LastUpdated = DateTime.UtcNow;
LastPersisted = DateTime.MinValue;
Data = btStateData;
}
public void WriteBinary(IBinaryWriter writer)
{
writer.WriteTimestamp(nameof(LastUpdated), LastUpdated);
writer.WriteTimestamp(nameof(LastPersisted), LastPersisted);
writer.WriteByteArray(nameof(Data), Data);
}
public void ReadBinary(IBinaryReader reader)
{
LastUpdated = reader.ReadTimestamp(nameof(LastUpdated)) ??
DateTime.UtcNow;
LastPersisted = reader.ReadTimestamp(nameof(LastPersisted)) ??
DateTime.UtcNow;
Data = reader.ReadByteArray(nameof(Data));
}
}
--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/
Re: Map C# class to Cassandra persistence settings
Posted by "ilya.kasnacheev" <il...@gmail.com>.
Hello!
Be the first to try!
Note that you should probably a) enable simple binary name mapping[1] (i.e.
use class="Person"), b) use Java types for primitives[2] (or their Java
wrapper classes).
1.
https://apacheignite-net.readme.io/docs/platform-interoperability#section-default-behavior
2.
https://apacheignite-net.readme.io/docs/platform-interoperability#section-type-compatibility
Regards,
--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/