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/

Reply via email to