首页 文章

如何在apache中配置oracle数据库点燃.NET

提问于
浏览
4

我正在尝试使用Oracle数据库配置apache Ignite的直写和读取属性 . 我在许多地方搜索过像Ignite oficial文档,也在GitHub的点燃示例中搜索,但是在C#中编写的信息或示例并不多,我正在开发我的应用程序的lenguaje .

我想要的是从持久性存储(在本例中是Oracle数据库)中检索尚未加载的缓存(Ignite)中的特定数据 . 以类似的方式,我需要在缓存上的所有更改都反映在数据库中 .

我使用数据库的配置(ip,端口,用户名,传递,数据库)绑定到create和spring.xml,但是如果它应该这样做的话我就无法工作 .

提前致谢,对不起我的英语 .

1 回答

  • 2

    1)实现 ICacheStore 接口(或继承 CacheStoreAdapter 辅助类)

    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)实施商店工厂:

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

    3)配置缓存以使用存储:

    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.
    }
    

    Ignite.NET的文档(在C#中):https://apacheignite-net.readme.io/docs/persistent-store

    C#示例在完整下载包中提供:https://ignite.apache.org/download.cgi#binaries(单击apache-ignite-fabric-1.9.0-bin.zip,下载,解压缩,打开平台\ dotnet \ examples \ Apache.Ignite.Examples.sln)

    博客文章解释C#中的缓存存储实现:https://ptupitsyn.github.io/Entity-Framework-Cache-Store/

    在.NET中使用Oracle DB:Connecting to Oracle Database through C#?

相关问题