【问题标题】:How to configure an oracle database in apache ignite .NET如何在 apache ignite .NET 中配置 oracle 数据库
【发布时间】:2017-08-18 18:53:21
【问题描述】:

我正在尝试使用 Oracle 数据库配置 apache Ignite 的直写和直读属性。我搜索了很多地方,比如 Ignite 官方文档,也在 GitHub 上的 ignite 示例中, 但是没有太多用 C# 编码的信息或示例,这是我开发应用程序的语言。

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

我将 create 和 spring.xml 与数据库的配置(ip、端口、用户名、通行证、数据库)绑定在一起,但如果这是应该的方式,我无法使其工作。

在此先感谢,对不起我的英语。

【问题讨论】:

    标签: c# .net oracle ignite


    【解决方案1】:

    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) 配置缓存使用store:

    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#?

    【讨论】:

    • 感谢您的回答,但我不明白您在哪里设置了oracle 数据库的连接参数,我的意思是,您将url、用户名和密码放在哪里。你能解释一下那部分吗?谢谢!
    • 我已经添加了更多细节,尽管它不在 Ignite.NET 的主题范围内。有关 Oracle 详细信息,请参阅此问题:stackoverflow.com/questions/12568100/…
    • 谢谢!我会试试的。
    猜你喜欢
    • 2018-12-17
    • 1970-01-01
    • 2018-03-03
    • 1970-01-01
    • 2023-02-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多