当前位置:   article > 正文

异步编程实战之r2dbc

异步编程实战之r2dbc

 一, 添加依赖

  1. <dependency>
  2. <groupId>com.baomidou</groupId>
  3. <artifactId>mybatis-plus-generator</artifactId>
  4. <version>3.5.2</version>
  5. </dependency>
  6. <dependency>
  7. <groupId>com.baomidou</groupId>
  8. <artifactId>mybatis-plus</artifactId>
  9. <version>3.5.1</version>
  10. </dependency>
  11. <dependency>
  12. <groupId>org.freemarker</groupId>
  13. <artifactId>freemarker</artifactId>
  14. <version>2.3.31</version>
  15. </dependency>

二, 数据库连接配置

  1. spring.r2dbc.username=root
  2. spring.r2dbc.password=cl8q!a#jrkYgMBHu
  3. spring.r2dbc.url=r2dbcs:mysql://172.16.1.187:2883/ob_test?userSSL=false&useUnicode=true&characterEncoding=UTF-8&sslMode=DISABLED&serverTimeZone=GMT%2B8

三, 编写模版文件

controller模板

  1. package ${package.Controller};
  2. import io.swagger.annotations.ApiResponse;
  3. import com.shuinfo.ods_poc.vo.${entity}.${entity}SaveReq;
  4. import org.springframework.web.bind.annotation.RequestBody;
  5. import org.springframework.web.bind.annotation.RequestMapping;
  6. import org.springframework.web.bind.annotation.RestController;
  7. <#if superControllerClassPackage??>
  8. import ${superControllerClassPackage};
  9. </#if>
  10. import lombok.extern.slf4j.Slf4j;
  11. import org.springframework.beans.factory.annotation.Autowired;
  12. import org.springframework.web.bind.annotation.PutMapping;
  13. import io.swagger.v3.oas.annotations.Operation;
  14. import com.fasterxml.jackson.annotation.JsonView;
  15. import com.shuinfo.ods_poc.view.TestView;
  16. import com.shuinfo.ods_poc.vo.R;
  17. import ${package.Service}.${table.serviceName};
  18. import com.shuinfo.ods_poc.vo.${entity}.${entity}SaveResp;
  19. import reactor.core.publisher.Mono;
  20. import org.springframework.web.bind.annotation.*;
  21. /**
  22. * <p>
  23. * ${table.comment!} 前端控制器
  24. * @author ${author}
  25. * @since ${date}
  26. */
  27. @RestController
  28. @RequestMapping("<#if package.ModuleName?? && package.ModuleName != "">/${package.ModuleName}</#if>/<#if controllerMappingHyphenStyle>${controllerMappingHyphen}<#else>${table.entityPath}</#if>")
  29. @Slf4j
  30. public class ${table.controllerName} {
  31. @Autowired
  32. private ${table.serviceName} ${table.serviceName?uncap_first};
  33. @PutMapping("/save")
  34. @Operation(summary = "保存数据")
  35. @JsonView(value = TestView.class)
  36. @ApiResponse(code = 200, message = "返回数据", response = R.class)
  37. public Mono<R<${entity}SaveResp>> save(@RequestBody ${entity}SaveReq req){
  38. return ${table.serviceName?uncap_first}.save(req).map(R::successRespons);
  39. }
  40. @GetMapping("/delete")
  41. @Operation(summary = "根据单号删除数据")
  42. @JsonView(value = TestView.class)
  43. @ApiResponse(code = 200, message = "返回数据", response = R.class)
  44. public Mono<String> delete(@RequestParam("orderNo") String orderNo){
  45. return ${table.serviceName?uncap_first}.delete(orderNo);
  46. }
  47. }

dao模版:

  1. package ${package.Mapper};
  2. import org.springframework.data.r2dbc.repository.R2dbcRepository;
  3. import ${package.Entity}.${entity};
  4. public interface ${table.mapperName} extends R2dbcRepository<${entity}, Long> {
  5. }

serviceImpl模版:

  1. package ${package.Service};
  2. import lombok.extern.slf4j.Slf4j;
  3. import org.springframework.beans.BeanUtils;
  4. import org.springframework.beans.factory.annotation.Autowired;
  5. import org.springframework.stereotype.Service;
  6. import ${package.Mapper}.${table.mapperName};
  7. import ${package.Entity}.${entity};
  8. import com.shuinfo.ods_poc.vo.${entity}.${entity}SaveReq;
  9. import com.shuinfo.ods_poc.vo.${entity}.${entity}SaveResp;
  10. import reactor.core.publisher.Mono;
  11. import org.apache.commons.lang3.StringUtils;
  12. import org.springframework.data.r2dbc.core.R2dbcEntityTemplate;
  13. /**
  14. * <p>
  15. * ${table.comment!} 服务实现类
  16. * @author ${author}
  17. * @since ${date}
  18. */
  19. @Service
  20. @Slf4j
  21. public class ${table.serviceName}{
  22. @Autowired
  23. private ${table.mapperName} ${table.mapperName?uncap_first};
  24. @Autowired
  25. private R2dbcEntityTemplate r2dbcEntityTemplate;
  26. public Mono<${entity}SaveResp> save(${entity}SaveReq req) {
  27. ${entity}SaveResp resp = new ${entity}SaveResp();
  28. if(req == null || StringUtils.isEmpty(req.getOrderNo())){
  29. return Mono.just(resp);
  30. }
  31. ${entity} ${entity?uncap_first} = new ${entity}();
  32. BeanUtils.copyProperties(req,${entity?uncap_first});
  33. return ${table.mapperName?uncap_first}.save(${entity?uncap_first}).log().map(entity -> {
  34. resp.set${entity}(entity);
  35. return resp;
  36. });
  37. }
  38. public Mono<String> delete(String orderNo) {
  39. if(StringUtils.isEmpty(orderNo)){
  40. return Mono.just("订单号不能为空!");
  41. }
  42. String sql = "delete from `${table.name}` where order_no = :orderNo";
  43. return r2dbcEntityTemplate.getDatabaseClient().sql(sql).bind("orderNo",orderNo)
  44. .then().thenReturn("删除成功!");
  45. }
  46. }

entity模版

  1. package ${package.Entity};
  2. import io.swagger.annotations.ApiModelProperty;
  3. <#list table.importPackages as pkg>
  4. import ${pkg};
  5. </#list>
  6. <#if swagger>
  7. import io.swagger.annotations.ApiModel;
  8. import io.swagger.annotations.ApiModelProperty;
  9. </#if>
  10. <#if entityLombokModel>
  11. import lombok.Getter;
  12. import lombok.Setter;
  13. <#if chainModel>
  14. import lombok.experimental.Accessors;
  15. </#if>
  16. </#if>
  17. /**
  18. * <p>
  19. * ${table.comment!}
  20. * </p>
  21. *
  22. * @author ${author}
  23. * @since ${date}
  24. */
  25. <#if entityLombokModel>
  26. @Getter
  27. @Setter
  28. <#if chainModel>
  29. @Accessors(chain = true)
  30. </#if>
  31. </#if>
  32. <#if table.convert>
  33. @TableName("${schemaName}${table.name}")
  34. </#if>
  35. <#if swagger>
  36. @ApiModel(value = "${entity}对象", description = "${table.comment!}")
  37. </#if>
  38. <#if superEntityClass??>
  39. public class ${entity} extends ${superEntityClass}<#if activeRecord><${entity}></#if> {
  40. <#elseif activeRecord>
  41. public class ${entity} extends Model<${entity}> {
  42. <#elseif entitySerialVersionUID>
  43. public class ${entity} implements Serializable {
  44. <#else>
  45. public class ${entity} {
  46. </#if>
  47. <#if entitySerialVersionUID>
  48. private static final long serialVersionUID = 1L;
  49. </#if>
  50. <#-- ---------- BEGIN 字段循环遍历 ---------->
  51. <#list table.fields as field>
  52. <#if field.keyFlag>
  53. <#assign keyPropertyName="${field.propertyName}"/>
  54. </#if>
  55. <#if field.comment!?length gt 0>
  56. <#if swagger>
  57. @ApiModelProperty("${field.comment}")
  58. <#else>
  59. /**
  60. * ${field.comment}
  61. */
  62. </#if>
  63. </#if>
  64. <#if field.keyFlag>
  65. <#-- 主键 -->
  66. <#if field.keyIdentityFlag>
  67. @TableId(value = "${field.annotationColumnName}", type = IdType.AUTO)
  68. <#elseif idType??>
  69. @TableId(value = "${field.annotationColumnName}", type = IdType.${idType})
  70. <#elseif field.convert>
  71. @TableId("${field.annotationColumnName}")
  72. </#if>
  73. <#-- 普通字段 -->
  74. <#elseif field.fill??>
  75. <#-- ----- 存在字段填充设置 ----->
  76. <#if field.convert>
  77. @TableField(value = "${field.annotationColumnName}", fill = FieldFill.${field.fill})
  78. <#else>
  79. @TableField(fill = FieldFill.${field.fill})
  80. </#if>
  81. <#elseif field.convert>
  82. @TableField("${field.annotationColumnName}")
  83. </#if>
  84. <#-- 乐观锁注解 -->
  85. <#if field.versionField>
  86. @Version
  87. </#if>
  88. <#-- 逻辑删除注解 -->
  89. <#if field.logicDeleteField>
  90. @TableLogic
  91. </#if>
  92. @ApiModelProperty(value = "${field.comment}")
  93. private ${field.propertyType} ${field.propertyName};
  94. </#list>
  95. <#------------ END 字段循环遍历 ---------->
  96. <#if !entityLombokModel>
  97. <#list table.fields as field>
  98. <#if field.propertyType == "boolean">
  99. <#assign getprefix="is"/>
  100. <#else>
  101. <#assign getprefix="get"/>
  102. </#if>
  103. public ${field.propertyType} ${getprefix}${field.capitalName}() {
  104. return ${field.propertyName};
  105. }
  106. <#if chainModel>
  107. public ${entity} set${field.capitalName}(${field.propertyType} ${field.propertyName}) {
  108. <#else>
  109. public void set${field.capitalName}(${field.propertyType} ${field.propertyName}) {
  110. </#if>
  111. this.${field.propertyName} = ${field.propertyName};
  112. <#if chainModel>
  113. return this;
  114. </#if>
  115. }
  116. </#list>
  117. </#if>
  118. <#if entityColumnConstant>
  119. <#list table.fields as field>
  120. public static final String ${field.name?upper_case} = "${field.name}";
  121. </#list>
  122. </#if>
  123. <#if activeRecord>
  124. @Override
  125. public Serializable pkVal() {
  126. <#if keyPropertyName??>
  127. return this.${keyPropertyName};
  128. <#else>
  129. return null;
  130. </#if>
  131. }
  132. </#if>
  133. <#if !entityLombokModel>
  134. @Override
  135. public String toString() {
  136. return "${entity}{" +
  137. <#list table.fields as field>
  138. <#if field_index==0>
  139. "${field.propertyName}=" + ${field.propertyName} +
  140. <#else>
  141. ", ${field.propertyName}=" + ${field.propertyName} +
  142. </#if>
  143. </#list>
  144. "}";
  145. }
  146. </#if>
  147. }

四, 编写入口生成主类

  1. package org.flywaydb.core.internal.database.generate;
  2. import com.baomidou.mybatisplus.generator.FastAutoGenerator;
  3. import com.baomidou.mybatisplus.generator.config.*;
  4. import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
  5. import com.baomidou.mybatisplus.generator.config.rules.DateType;
  6. import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
  7. import java.util.Collections;
  8. import java.util.HashMap;
  9. import java.util.Map;
  10. public class R2dbcGenerate {
  11. /**
  12. * 数据源配置
  13. */
  14. private static final DataSourceConfig.Builder DATA_SOURCE_CONFIG = new DataSourceConfig
  15. .Builder("jdbc:mysql://172.16.1.187:2883/ob_test?userSSL=false&useUnicode=true" +
  16. "&characterEncoding=UTF-8&sslMode=DISABLED&serverTimeZone=GMT%2B8",
  17. "root", "cl8q!a#jrkYgMBHu");
  18. private static GlobalConfig.Builder builder;
  19. /**
  20. * 执行 run
  21. */
  22. public static void main(String[] args){
  23. FastAutoGenerator.create(DATA_SOURCE_CONFIG)
  24. // 全局配置
  25. .globalConfig(builder -> builder
  26. .author("zhihao").dateType(DateType.TIME_PACK)
  27. .commentDate("yyyy-MM-dd")
  28. // 输出路径
  29. .outputDir("/Users/lizhihao/shuxin/wlc/starbuck-ods-webflux-poc/src/main/java")
  30. )
  31. // 包配置
  32. .packageConfig(builder -> builder.parent("com.shuinfo.ods_poc.test")
  33. // .packageConfig(builder -> builder.parent("com.shuinfo.ods_poc")
  34. //自定义mapper名,同dao
  35. .mapper("dao")
  36. .other("vo")
  37. // .pathInfo(Collections.singletonMap(OutputFile.other,
  38. // "/Users/lizhihao/shuxin/wlc/starbuck-ods-webflux-poc/src/main/java/com/shuinfo/ods_poc/vo"))
  39. )
  40. // 策略配置 表名
  41. .strategyConfig(builder -> builder.addInclude("main_order,order_customer,order_line," +
  42. "order_line_discount,order_payment,order_price,order_service_type_config"))
  43. /*
  44. 模板引擎配置,默认 Velocity 可选模板引擎 Beetl 或 Freemarker
  45. .templateEngine(new BeetlTemplateEngine())
  46. */
  47. .templateEngine(new FreemarkerTemplateEngine())
  48. .templateConfig(builder -> builder.disable(TemplateType.MAPPER)
  49. .disable(TemplateType.SERVICEIMPL).disable(TemplateType.XML)
  50. .disable(TemplateType.CONTROLLER)
  51. .entity("/templates/entity")
  52. .mapper("/templates/dao")
  53. .service("/templates/serviceImpl")
  54. .controller("/templates/controller")
  55. )
  56. //设置自定义的模块类及模版文件
  57. .injectionConfig(builder ->
  58. builder.beforeOutputFile((tableInfo, objectMap) -> {
  59. //自定义入参对象
  60. Map<String,String> map = new HashMap<>(10);
  61. map.put(tableInfo.getEntityName()+"SaveReq.java", "/templates/req.ftl");
  62. map.put(tableInfo.getEntityName()+"SaveResp.java", "/templates/resp.ftl");
  63. builder.customFile(map);
  64. System.out.println("tableInfo: " + tableInfo.getEntityName() + " objectMap: " + objectMap.size());
  65. })
  66. )
  67. .execute();
  68. }
  69. }

五, 编写DataSourceConfig

  1. /*
  2. * Copyright (c) 2011-2021, baomidou (jobob@qq.com).
  3. * <p>
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. * <p>
  8. * https://www.apache.org/licenses/LICENSE-2.0
  9. * <p>
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package org.flywaydb.core.internal.database.generate;
  17. import com.baomidou.mybatisplus.annotation.DbType;
  18. import com.baomidou.mybatisplus.core.toolkit.StringUtils;
  19. import com.baomidou.mybatisplus.generator.config.IConfigBuilder;
  20. import com.baomidou.mybatisplus.generator.config.IDbQuery;
  21. import com.baomidou.mybatisplus.generator.config.IKeyWordsHandler;
  22. import com.baomidou.mybatisplus.generator.config.ITypeConvert;
  23. import com.baomidou.mybatisplus.generator.config.converts.MySqlTypeConvert;
  24. import com.baomidou.mybatisplus.generator.config.converts.TypeConverts;
  25. import com.baomidou.mybatisplus.generator.config.querys.DbQueryDecorator;
  26. import com.baomidou.mybatisplus.generator.config.querys.DbQueryRegistry;
  27. import org.slf4j.Logger;
  28. import org.slf4j.LoggerFactory;
  29. import javax.sql.DataSource;
  30. import java.sql.Connection;
  31. import java.sql.DriverManager;
  32. import java.sql.SQLException;
  33. import java.util.Optional;
  34. /**
  35. * 数据库配置
  36. *
  37. * @author YangHu, hcl, hubin
  38. * @since 2016/8/30
  39. */
  40. public class DataSourceConfig {
  41. protected final Logger logger = LoggerFactory.getLogger(DataSourceConfig.class);
  42. private DataSourceConfig() {
  43. }
  44. /**
  45. * 数据库信息查询
  46. */
  47. private IDbQuery dbQuery;
  48. /**
  49. * schemaName
  50. */
  51. private String schemaName;
  52. /**
  53. * 类型转换
  54. */
  55. private ITypeConvert typeConvert;
  56. /**
  57. * 关键字处理器
  58. *
  59. * @since 3.3.2
  60. */
  61. private IKeyWordsHandler keyWordsHandler;
  62. /**
  63. * 驱动连接的URL
  64. */
  65. private String url;
  66. /**
  67. * 数据库连接用户名
  68. */
  69. private String username;
  70. /**
  71. * 数据库连接密码
  72. */
  73. private String password;
  74. /**
  75. * 数据源实例
  76. *
  77. * @since 3.5.0
  78. */
  79. private DataSource dataSource;
  80. /**
  81. * 数据库连接
  82. *
  83. * @since 3.5.0
  84. */
  85. private Connection connection;
  86. /**
  87. * 获取数据库查询
  88. */
  89. public IDbQuery getDbQuery() {
  90. if (null == dbQuery) {
  91. DbType dbType = getDbType();
  92. DbQueryRegistry dbQueryRegistry = new DbQueryRegistry();
  93. // 默认 MYSQL
  94. dbQuery = Optional.ofNullable(dbQueryRegistry.getDbQuery(dbType))
  95. .orElseGet(() -> dbQueryRegistry.getDbQuery(DbType.MYSQL));
  96. }
  97. return dbQuery;
  98. }
  99. /**
  100. * 判断数据库类型
  101. *
  102. * @return 类型枚举值
  103. */
  104. public DbType getDbType() {
  105. return this.getDbType(this.url.toLowerCase());
  106. }
  107. /**
  108. * 判断数据库类型
  109. *
  110. * @param str url
  111. * @return 类型枚举值,如果没找到,则返回 null
  112. */
  113. private DbType getDbType(String str) {
  114. if (str.contains(":mysql:") || str.contains(":cobar:")) {
  115. return DbType.MYSQL;
  116. } else if (str.contains(":oracle:")) {
  117. return DbType.ORACLE;
  118. } else if (str.contains(":postgresql:")) {
  119. return DbType.POSTGRE_SQL;
  120. } else if (str.contains(":sqlserver:")) {
  121. return DbType.SQL_SERVER;
  122. } else if (str.contains(":db2:")) {
  123. return DbType.DB2;
  124. } else if (str.contains(":mariadb:")) {
  125. return DbType.MARIADB;
  126. } else if (str.contains(":sqlite:")) {
  127. return DbType.SQLITE;
  128. } else if (str.contains(":h2:")) {
  129. return DbType.H2;
  130. } else if (str.contains(":kingbase:") || str.contains(":kingbase8:")) {
  131. return DbType.KINGBASE_ES;
  132. } else if (str.contains(":dm:")) {
  133. return DbType.DM;
  134. } else if (str.contains(":zenith:")) {
  135. return DbType.GAUSS;
  136. } else if (str.contains(":oscar:")) {
  137. return DbType.OSCAR;
  138. } else if (str.contains(":firebird:")) {
  139. return DbType.FIREBIRD;
  140. } else if (str.contains(":xugu:")) {
  141. return DbType.XU_GU;
  142. } else if (str.contains(":clickhouse:")) {
  143. return DbType.CLICK_HOUSE;
  144. } else if (str.contains(":sybase:")) {
  145. return DbType.SYBASE;
  146. } else {
  147. return DbType.OTHER;
  148. }
  149. }
  150. /**
  151. * 获取数据库字段类型转换
  152. */
  153. public ITypeConvert getTypeConvert() {
  154. if (null == typeConvert) {
  155. DbType dbType = getDbType();
  156. // 默认 MYSQL
  157. typeConvert = TypeConverts.getTypeConvert(dbType);
  158. if (null == typeConvert) {
  159. typeConvert = MySqlTypeConvert.INSTANCE;
  160. }
  161. }
  162. return typeConvert;
  163. }
  164. /**
  165. * 创建数据库连接对象
  166. * 这方法建议只调用一次,毕竟只是代码生成,用一个连接就行。
  167. *
  168. * @return Connection
  169. * @see DbQueryDecorator#getConnection()
  170. */
  171. public Connection getConn() {
  172. try {
  173. if (connection != null && !connection.isClosed()) {
  174. return connection;
  175. } else {
  176. synchronized (this) {
  177. if (dataSource != null) {
  178. connection = dataSource.getConnection();
  179. } else {
  180. this.connection = DriverManager.getConnection(url, username, password);
  181. }
  182. }
  183. }
  184. String schema = StringUtils.isNotBlank(schemaName) ? schemaName : getDefaultSchema();
  185. if (StringUtils.isNotBlank(schema)) {
  186. schemaName = schema;
  187. try {
  188. connection.setSchema(schemaName);
  189. } catch (Throwable t) {
  190. logger.error("There may be exceptions in the driver and version of the database, " + t.getMessage());
  191. }
  192. }
  193. } catch (SQLException e) {
  194. throw new RuntimeException(e);
  195. }
  196. return connection;
  197. }
  198. /**
  199. * 获取数据库默认schema
  200. *
  201. * @return 默认schema
  202. * @since 3.5.0
  203. */
  204. protected String getDefaultSchema() {
  205. DbType dbType = getDbType();
  206. String schema = null;
  207. if (DbType.POSTGRE_SQL == dbType) {
  208. //pg 默认 schema=public
  209. schema = "public";
  210. } else if (DbType.KINGBASE_ES == dbType) {
  211. //kingbase 默认 schema=PUBLIC
  212. schema = "PUBLIC";
  213. } else if (DbType.DB2 == dbType) {
  214. //db2 默认 schema=current schema
  215. schema = "current schema";
  216. } else if (DbType.ORACLE == dbType) {
  217. //oracle 默认 schema=username
  218. schema = this.username.toUpperCase();
  219. }
  220. return schema;
  221. }
  222. public String getSchemaName() {
  223. return schemaName;
  224. }
  225. public IKeyWordsHandler getKeyWordsHandler() {
  226. return keyWordsHandler;
  227. }
  228. public String getUrl() {
  229. return url;
  230. }
  231. public String getUsername() {
  232. return username;
  233. }
  234. public String getPassword() {
  235. return password;
  236. }
  237. /**
  238. * 数据库配置构建者
  239. *
  240. * @author nieqiurong 2020/10/10.
  241. * @since 3.5.0
  242. */
  243. public static class Builder implements IConfigBuilder<DataSourceConfig> {
  244. private final DataSourceConfig dataSourceConfig;
  245. private Builder() {
  246. this.dataSourceConfig = new DataSourceConfig();
  247. }
  248. /**
  249. * 构造初始化方法
  250. *
  251. * @param url 数据库连接地址
  252. * @param username 数据库账号
  253. * @param password 数据库密码
  254. */
  255. public Builder(String url, String username, String password) {
  256. this();
  257. if (StringUtils.isBlank(url)) {
  258. throw new RuntimeException("无法创建文件,请正确输入 url 配置信息!");
  259. }
  260. this.dataSourceConfig.url = url;
  261. this.dataSourceConfig.username = username;
  262. this.dataSourceConfig.password = password;
  263. }
  264. /**
  265. * 构造初始化方法
  266. *
  267. * @param dataSource 外部数据源实例
  268. */
  269. public Builder(DataSource dataSource) {
  270. this();
  271. this.dataSourceConfig.dataSource = dataSource;
  272. try {
  273. Connection conn = dataSource.getConnection();
  274. this.dataSourceConfig.url = conn.getMetaData().getURL();
  275. this.dataSourceConfig.schemaName = conn.getSchema();
  276. this.dataSourceConfig.connection = conn;
  277. this.dataSourceConfig.username = conn.getMetaData().getUserName();
  278. } catch (SQLException ex) {
  279. throw new RuntimeException("构建数据库配置对象失败!", ex);
  280. }
  281. }
  282. /**
  283. * 设置数据库查询实现
  284. *
  285. * @param dbQuery 数据库查询实现
  286. * @return this
  287. */
  288. public Builder dbQuery(IDbQuery dbQuery) {
  289. this.dataSourceConfig.dbQuery = dbQuery;
  290. return this;
  291. }
  292. /**
  293. * 设置数据库schema
  294. *
  295. * @param schemaName 数据库schema
  296. * @return this
  297. */
  298. public Builder schema(String schemaName) {
  299. this.dataSourceConfig.schemaName = schemaName;
  300. return this;
  301. }
  302. /**
  303. * 设置类型转换器
  304. *
  305. * @param typeConvert 类型转换器
  306. * @return this
  307. */
  308. public Builder typeConvert(ITypeConvert typeConvert) {
  309. this.dataSourceConfig.typeConvert = typeConvert;
  310. return this;
  311. }
  312. /**
  313. * 设置数据库关键字处理器
  314. *
  315. * @param keyWordsHandler 关键字处理器
  316. * @return this
  317. */
  318. public Builder keyWordsHandler(IKeyWordsHandler keyWordsHandler) {
  319. this.dataSourceConfig.keyWordsHandler = keyWordsHandler;
  320. return this;
  321. }
  322. /**
  323. * 构建数据库配置
  324. *
  325. * @return 数据库配置
  326. */
  327. @Override
  328. public DataSourceConfig build() {
  329. return this.dataSourceConfig;
  330. }
  331. }
  332. }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家小花儿/article/detail/202753
推荐阅读
相关标签
  

闽ICP备14008679号