JDBC persistence overview and module configuration


The JDBC persistence module is a simple solution for relational database (RDBMS) data access. It mainly focuses on the efficiency, ease of use and transparency of data access. It has the following functional characteristics:

  • Lightweight encapsulation based on JDBC framework API, simple structure, easy to develop, debug and maintain;
  • Optimize batch data update, standardized result set, pre-compiled SQL statement processing;
  • Supports single-entity ORM operations without writing SQL statements;
  • Provides scaffolding tools to quickly generate data entity classes and supports chain calls;
  • Supports custom SQL through memory annotations statement or load SQL from the configuration file and execute it automatically;
  • Supports automatic assembly of result sets and value objects, and supports custom assembly rules;
  • Supports multiple data sources, and supports C3P0 and DBCP by default , JNDI connection pool configuration, supports data source expansion;
  • Supports multiple databases (such as: Oracle, MySQL, SQLServer, etc.);
  • Supports object-oriented database query encapsulation, helping to reduce Or reduce program compilation errors;
  • Support database transaction nesting;
  • Support database stored procedures*;

Maven package dependency

<dependency>
    <groupId>net.ymate.platform</groupId>
    <artifactId>ymate-platform-persistence-jdbc</artifactId>
    <version>2.0-SNAPSHOT</version>
</dependency>

Note: Add the above configuration in the project's pom.xml. This module has introduced the core package and persistence by default. Basic package dependencies, no need to repeat configuration.

Module initialization configuration

#-------------------------------------
# JDBC持久化模块初始化参数
#-------------------------------------

# 默认数据源名称,默认值为default
ymp.configs.persistence.jdbc.ds_default_name=

# 数据源列表,多个数据源名称间用'|'分隔,默认为default
ymp.configs.persistence.jdbc.ds_name_list=

# 是否显示执行的SQL语句,默认为false
ymp.configs.persistence.jdbc.ds.default.show_sql=

# 数据库表前缀名称,默认为空
ymp.configs.persistence.jdbc.ds.default.table_prefix=

# 数据源适配器,可选值为已知适配器名称或自定义适配置类名称,默认为default,目前支持已知适配器[default|dbcp|c3p0|jndi|...]
ymp.configs.persistence.jdbc.ds.default.adapter_class=

# 数据库类型,可选参数,默认值将通过连接字符串分析获得,目前支持[mysql|oracle|sqlserver|db2|sqlite|postgresql|hsqldb|h2]
ymp.configs.persistence.jdbc.ds.default.type=

# 数据库方言,可选参数,自定义方言将覆盖默认配置
ymp.configs.persistence.jdbc.ds.default.dialect_class=

# 数据库连接驱动,可选参数,框架默认将根据数据库类型进行自动匹配
ymp.configs.persistence.jdbc.ds.default.driver_class=

# 数据库连接字符串,必填参数
ymp.configs.persistence.jdbc.ds.default.connection_url=

# 数据库访问用户名称,必填参数
ymp.configs.persistence.jdbc.ds.default.username=

# 数据库访问密码,可选参数,经过默认密码处理器加密后的admin字符串为wRI2rASW58E
ymp.configs.persistence.jdbc.ds.default.password=

# 数据库访问密码是否已加密,默认为false
ymp.configs.persistence.jdbc.ds.default.password_encrypted=

# 数据库密码处理器,可选参数,用于对已加密数据库访问密码进行解密,默认为空
ymp.configs.persistence.jdbc.ds.default.password_class=

Supplementary description of configuration parameters:

The database connection string and user name of the data source are required. Others are optional parameters. The simplest configuration is as follows:

ymp.configs.persistence.jdbc.ds.default.connection_url =jdbc:mysql://localhost:3306/mydb

ymp.configs.persistence.jdbc.ds.default.username=root

In order to avoid clear text passwords appearing in the configuration file , the YMP framework provides a default database password processor, or implements it by itself through the IPasswordProcessor interface;

net.ymate.platform.core.support.impl.DefaultPasswordProcessor