How to set up oracle database in apache ignite.NET

I am trying to configure the end-to-end and end-to-end properties of apache Ignite with an Oracle database. I searched in many places, for example the Ignite oficial documentation, also in the ignition examples on GitHub, but in C # there is not much information or examples that are lenguaje in which I develop my application.

I want to get specific cache data (Ignite) from a persistent store (in this case, an Oracle database) that is not yet loaded. Similarly, I need all the cache changes to be reflected in the database.

I linked spring.xml to create with the database configuration (ip, port, username, pass, database), but I can’t get it to work if that’s how it should be done.

Thanks in advance and sorry for my English.

+4
source share
1 answer

1) Deploy an interface ICacheStore(or inherit a CacheStoreAdapterhelper class)

public class OracleStore : CacheStoreAdapter
{
    public override object Load(object key)
    {
        using (var con = new OracleConnection
        {
            ConnectionString = "User Id=<username>;Password=<password>;Data Source=<datasource>"
        })
        {
            con.Open();

            var cmd = con.CreateCommand();
            cmd.CommandText = "SELECT * FROM MyTable WHERE ID=@id";
            cmd.Parameters.Add("@id", OracleType.Int32);
            cmd.Parameters["@id"].Value = key;

            using (var reader = cmd.ExecuteReader())
            {
                // Read data, return as object
            }
        }
    }

    public override void Write(object key, object val)
    {
        oracleDb.UpdateRow(key, val);
    }

    public override void Delete(object key)
    {
        oracleDb.DeleteRow(key);
    }
}

2) Implement factory storage:

public class OracleStoreFactory : IFactory<OracleStore>
{
    public OracleStore CreateInstance()
    {
        return new OracleStore();
    }
}

3) Configure cache to use storage:

using (var ignite = Ignition.Start())
{
    var cacheCfg = new CacheConfiguration
    {
        ReadThrough = true,
        WriteThrough = true,
        KeepBinaryInStore = false,  // Depends on your case
        CacheStoreFactory = new OracleStoreFactory()
    };

    var cache = ignite.CreateCache<int, MyClass>(cacheCfg);

    cache.Get(1);  // OracleStore.Load is called.
}

Documentation for Ignite.NET (in C #): https://apacheignite-net.readme.io/docs/persistent-store

C # examples are available in the full download package: https://ignite.apache.org/download.cgi#binaries (click apache-ignite-fabric-1.9.0-bin. Zip, download, unzip, open the \ dotnet \ examples platforms \ Apache.Ignite.Examples.sln)

Blog post explaining cache storage implementation in C #: https://ptupitsyn.imtqy.com/Entity-Framework-Cache-Store/

Oracle DB .NET: Oracle #?

+2

Source: https://habr.com/ru/post/1673211/


All Articles