c# - 如何在 apache ignite .NET 中配置 oracle 数据库

标签 c# .net oracle ignite

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

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

我将 create 和 spring.xml 与数据库的配置(ip、端口、用户名、密码、数据库)绑定(bind)在一起,但如果这是应该完成的方式,我无法让它工作。

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

最佳答案

1)实现ICacheStore接口(interface)(或继承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,下载,解压,打开platforms\dotnet\examples\Apache.Ignite.Examples.sln)

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

在 .NET 中使用 Oracle 数据库:Connecting to Oracle Database through C#?

关于c# - 如何在 apache ignite .NET 中配置 oracle 数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43023136/

相关文章:

c++ - 为什么原生 C++ 项目有 TargetFrameworkVersion?

C# 对象引用未设置为对象的实例

java - Oracle 时间戳到 BST 时间的转换

linux - 在 Oracle 触发器代码中使用 'exec' 失败

c# - 如何有效地使用内存附加到 C# 中的大型 XML 文件

c# - 在 Winform 中打开 Crystal 报表

c# - 在 .NET 4.5.1 中设置 ASP.NET Identity ConnectionString 属性

c# - WPF 图像转换

.net - Winforms - Load 和 Activated 事件的顺序

sql - regexp_substr中的by子句连接