GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — hsweb-framework/hsweb-datasource at master · JobosFollower/hsweb-framework

Expand file tree

/

hsweb-datasource

/
Copy path

Directory actions

More options

More options

Directory actions

More options

More options

Latest commit

 

History

History
History
 
 
/

hsweb-datasource

/
Copy path

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
hsweb-datasource-api
hsweb-datasource-api
 
 
hsweb-datasource-jta
hsweb-datasource-jta
 
 
hsweb-datasource-web
hsweb-datasource-web
 
 
README.md
README.md
 
 
pom.xml
pom.xml
 
 

README.md

Outline

动态数据源模块

提供动态数据源支持功能,支持注解方式,编程方式动态切换数据源,支持事务中切换数据源,支持跨数据库事务

目前提供JTA实现,请看:hsweb-datasource-jta

example

表达式方式:

application.yml配置

hsweb:
    datasource:
        switcher:
           test: # 只是一个标识
              # 拦截类和方法的表达式
              expression: org.hswebframework.**.*Service.find*
              # 切换数据源
              data-source-id: read_db
              # 切换数据库 从3.0.8开始支持
              #database: db_001  # select * from db_001.s_user

编程方式:

  //切换到 id为mysql_read_01的数据源
  DataSourceHolder.switcher().use("mysql_read_01");
  // ....
  //切换到 id为mysql_write_01的数据源
  DataSourceHolder.switcher().use("mysql_write_01");
  // ....
  // 切换到上一次使用的数据源 (mysql_read_01)
   DataSourceHolder.switcher().useLast();
  // ...
  // 切换到默认的数据源
  DataSourceHolder.switcher().useDefault();

注解方式:

@UseDataSource("mysql_write_01")
String insert(MyEntity);
 
@UseDataSource("mysql_read_01")
MyEntity selectByPk(String id);
 
@UseDefaultDataSource()
MyEntity selectByPk(String id);

注意: 如果没有使用hsweb-datasource-jta模块,则无法在事务中切换数据源, 你可能需要先取消掉对应方法上的事务:如在方法上注解@Transactional(propagation = Propagation.NOT_SUPPORTED)

You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.