Method for realizing database dynamic switching and computer readable storage medium

The invention provides a method for realizing database dynamic switching, which comprises the following steps of analyzing a data source configuration file to form a corresponding database connectionpool; defining a set of annotations of data source switching; analyzing the annotation, and placing t...

Ausführliche Beschreibung

Gespeichert in:
Bibliographische Detailangaben
Hauptverfasser: TU JIANQUN, CHEN GUANGCONG
Format: Patent
Sprache:chi ; eng
Schlagworte:
Online-Zugang:Volltext bestellen
Tags: Tag hinzufügen
Keine Tags, Fügen Sie den ersten Tag hinzu!
Beschreibung
Zusammenfassung:The invention provides a method for realizing database dynamic switching, which comprises the following steps of analyzing a data source configuration file to form a corresponding database connectionpool; defining a set of annotations of data source switching; analyzing the annotation, and placing the database name in a local thread copy; returning the database object corresponding to the database name in the thread copy to the Spring framework to realize dynamic switching of the database. The invention further provides a computer readable storage medium, high cohesion and low coupling can beachieved without other service control codes, and the performance is not affected. On the basis, database read-write separation can be realized through configuration. 本发明提供一种实现数据库动态切换的方法,解析数据源配置文件,形成对应的数据库连接池;定义一套数据源切换的注解;解析注解,将数据库名称放在本地线程副本中;将在线程副本中的数据库名称对应的数据库对象返回给Spring框架,实现数据库的动态切换;本发明还提供一种计算机可读存储介质,无需其他业务控制代码,即可实现高内聚低耦合,且性能不受影响;在此基础上通过配置可以实现数据库读写分离。