如何将Corda节点扩展为与H2以外的数据库一起使用? [英] How can the Corda node be extended to work with databases other than H2?

查看:84
本文介绍了如何将Corda节点扩展为与H2以外的数据库一起使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在PostgreSQL上运行Corda。 Corda如何扩展以与其他数据库一起使用?将数据库驱动程序添加为Gradle依赖关系并尝试连接到其他数据库是否足够?

I have run Corda with PostgreSQL. How can Corda be extended to work with other databases? Is it enough to add the database driver as a Gradle dependency and try connecting to other databases?

推荐答案

Corda使用Hibernate 5.x

Corda uses Hibernate 5.x with HikariCP JDBC connection pool.

所有查询都是由Hibernate生成的,希望从 finance 模块( CashSelection 使用JDBC PreparedStatement 和特定于每个数据库供应商的SQL构造)。

All queries are generated by Hibernate, expect one query from the finance module (CashSelection uses a JDBC PreparedStatement with SQL constructs specific to each database vendor).

配置数据库

在运行时,节点在其节点中查找JDBC设置。 conf 文件。默认情况下,它连接到嵌入式H2服务器(请参见Corda源代码中的文件 /node/src/main/resources/reference.conf )。

At runtime, a node looks up the JDBC settings in its node.conf file. By default, it connects to the embedded H2 server (see the file /node/src/main/resources/reference.conf in the Corda source code).

要与其他数据库一起使用Corda(*)或使用非默认设置进行连接, node.conf 文件需要设置节点的数据源属性:

To use Corda with other databases(*) or connect with non-default settings, the node.conf file needs to set the node's data source properties:

dataSourceProperties = {
    dataSourceClassName = "org.postgresql.ds.PGSimpleDataSource"
    dataSource.url = "jdbc:postgresql://[HOST]:[PORT]/postgres"
    dataSource.user = [USER]
    dataSource.password = [PASSWORD]
}
database = {
    transactionIsolationLevel = READ_COMMITTED
}
jarDirs = [PATH_TO_JDBC_DRIVER_DIR]

,其中 dataSourceProperties 是典型的JDBC设置, database 条目包含特定于Hibernate的设置,而 jarDirs 是包含驱动程序的目录的路径列表(例如 jarDirs = ['/ Librar y / postgres-lib'] )。

where dataSourceProperties are the typical JDBC settings, the database entry contains Hibernate specific settings, and jarDirs is a list of paths to the directories containing the driver (e.g. jarDirs = ['/Library/postgres-lib']).

在deployNodes中配置数据库

您可以通过在 deployNodes 中传递设置来避免手动配置数据库设置。例如:

You can avoid configuring the database settings manually by passing the settings in deployNodes. For example:

node {
    name "O=Bank C,L=Tokyo,C=JP"
    p2pPort 10010
    webPort 10011
    rpcSettings {
        address("localhost:10036")
        adminAddress("localhost:10037")
    }
    cordapps = ["$project.group:finance:$corda_release_version"]
    rpcUsers = ext.rpcUsers
    extraConfig = [
        ‘dataSourceProperties.dataSource.url’ : ‘jdbc:postgresql://localhost:32774/postgres’,
        ‘dataSourceProperties.dataSourceClassName’ : ‘org.postgresql.ds.PGSimpleDataSource’,
        ‘dataSourceProperties.dataSource.user’ : ‘postgres’,
        ‘dataSourceProperties.dataSource.password’ : ‘postgres’,
        ‘jarDirs’ : [ ‘/Library/Java/postgres’ ]
    ]
}

添加驱动程序

一旦添加了这些设置,JDBC驱动程序需要添加到 extraConfig.jarDirs

Once these settings have been added, the JDBC driver needs to be added to the location specified in extraConfig.jarDirs after the node has been deployed.

另一种方法是在 node / build.gradle (对于PostgreSQL已经完成)。每当编译/构建节点时,它都将立即包含驱动程序。

The alternative is to add the JDBC driver dependency in node/build.gradle (as it is done for PostgreSQL). Whenever a node is compiled/built, it will contain the driver out-of-the-box.

(*)Corda Open Source随H2文件数据库一起提供,并具有对Postgres和Sql Server的实验性支持。 Corda Enterprise对其他数据库(包括Sql Server,AzureSQL,Postgres和Oracle数据库)进行了更广泛的测试支持。尽管使用了Hibernate / JDBC,但某些查询可能仍需要修改才能与所有受支持的数据库兼容。 Corda Enterprise支持此兼容性。

(*) Corda Open Source is shipped with the H2 file database, and has experimental support for Postgres and Sql Server. Corda Enterprise has wider tested support for other databases including Sql Server, AzureSQL, Postgres, and Oracle databases. Despite using Hibernate/JDBC, some queries may require modification in order to be compatible across all supported databases. This compatibility is supported by Corda Enterprise.

这篇关于如何将Corda节点扩展为与H2以外的数据库一起使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆