All Projects → chengdedeng → Perseus

chengdedeng / Perseus

⚡️database read and write separation of java

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Perseus

Spring Boot Mybatis Rw
基于mybatis,springboot开箱即用的读写分离插件
Stars: ✭ 347 (+182.11%)
Mutual labels:  transaction, datasource
ddal
DDAL(Distributed Data Access Layer) is a simple solution to access database shard.
Stars: ✭ 33 (-73.17%)
Mutual labels:  transaction, datasource
Ethjs Provider Signer
A simple web3 standard provider that signs eth_sendTransaction payloads.
Stars: ✭ 65 (-47.15%)
Mutual labels:  transaction
Radon
RadonDB is an open source, cloud-native MySQL database for building global, scalable cloud services
Stars: ✭ 1,584 (+1187.8%)
Mutual labels:  transaction
Stock Management System
An Introductory Stock Management System built on PHP, jQuery with AJAX in MVC pattern.
Stars: ✭ 95 (-22.76%)
Mutual labels:  transaction
Rocketmq trans message
基于rocketmq上加入了事务消息的功能
Stars: ✭ 67 (-45.53%)
Mutual labels:  transaction
Bitcoin in a nutshell
Книга о том, как действительно работает Bitcoin
Stars: ✭ 98 (-20.33%)
Mutual labels:  transaction
Laravel Transactional Model Events
Add eloquent model events fired after a transaction is committed or rolled back
Stars: ✭ 52 (-57.72%)
Mutual labels:  transaction
Bytetcc Sample
Stars: ✭ 119 (-3.25%)
Mutual labels:  transaction
Tupl
The Unnamed Persistence Library
Stars: ✭ 83 (-32.52%)
Mutual labels:  transaction
Gkvdb
[mirror] Go语言开发的基于DRH(Deep-Re-Hash)深度哈希分区算法的高性能高可用Key-Value嵌入式事务数据库。基于纯Go语言实现,具有优异的跨平台性,良好的高可用及文件IO复用设计,高效的底层数据库文件操作性能,支持原子操作、批量操作、事务操作、多表操作、多表事务、随机遍历等特性。
Stars: ✭ 109 (-11.38%)
Mutual labels:  transaction
Nativescript Purchase
💰 A NativeScript plugin for making in-app purchases!
Stars: ✭ 80 (-34.96%)
Mutual labels:  transaction
Datasource
Simplifies the setup of UITableView data sources using type-safe descriptors for cells and sections. Animated diffing built-in.
Stars: ✭ 72 (-41.46%)
Mutual labels:  datasource
Rexlin600.github.io
系列博客、涵盖领域广、不定时更新、欢迎加入
Stars: ✭ 102 (-17.07%)
Mutual labels:  transaction
Diskqueue
A thread-safe, multi-process(ish) persistent queue library for .Net and Mono
Stars: ✭ 66 (-46.34%)
Mutual labels:  transaction
Java Interview
At the beginning, it was the repository with questions from Java interviews. Currently, it's more like knowledge base with useful links.
Stars: ✭ 114 (-7.32%)
Mutual labels:  transaction
Dynamic Datasource Starter
springboot 动态切换数据的基本思想与实现方法
Stars: ✭ 63 (-48.78%)
Mutual labels:  datasource
Neb.js
Stars: ✭ 80 (-34.96%)
Mutual labels:  transaction
Cointrol
฿ Bitcoin trading bot with a real-time dashboard for Bitstamp.
Stars: ✭ 1,351 (+998.37%)
Mutual labels:  transaction
Lottor
distributed transaction service based on reliable msg,基于可靠消息的柔性分布式事务实现方案。
Stars: ✭ 122 (-0.81%)
Mutual labels:  transaction

Join the chat at https://gitter.im/chengdedeng/perseus

中文文档

Project description

The read/write separation of databases is a basic requirement, it is usually comes in three ways:

  1. multi-data source,hard-code.
  2. Extended ORM.
  3. Implement protocol of database by middleware.

First is simplest,but developer need to do a lot of work and easy to make mistakes;although the third program is transparent for developer and don't restrict the programming language, but it's most difficult of development and the scope of the database support is fewer. This project is based on the program II, select Mybatis and Spring of most popular framework in java, so it is only applicable to the Mybatis + Spring implementation of the Java project.

Function

  1. The transaction is routed to the master database and does't distinguish whether transaction is readonly. Due to readonly don't really start the transaction, just activate the transaction synchronization, so don't be DynamicDataSourceTransactionManager to intercept, so setting to be hit by the default(master database), and the execution of all queries in a read only transaction will reuse the same JDBCConnection(SqlSession).
  2. The select query is routed to the slave database, insert/update/delete SQL routing to the main master database.
  3. Support select query to force routing to master database (as far as possible, bypassing business logic optimization).
  4. Support batch operations in mybatis-spring.

Stability

The project is widely used in the author's company, hundreds of projects, and has been well developed, with detailed configuration and test code in the test code.

Core configuration

General configuration

    <bean id="dataSource" class="info.yangguo.perseus.DynamicDataSource">
        <property name="master" ref="master"/>
        <property name="slaves">
            <list>
                <ref bean="slave1"/>
                <ref bean="slave2"/>
            </list>
        </property>
    </bean>

    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource"/>
        <property name="typeAliasesPackage" value="info.yangguo.perseus.test.domain"/>
        <property name="configLocation" value="classpath:sqlMapConfig.xml"/>
        <property name="mapperLocations" value="classpath:info/yangguo/perseus/test/dao/*.xml"/>
    </bean>

    <bean class="info.yangguo.perseus.MapperScannerConfigurer">
        <property name="basePackage" value="info.yangguo.perseus.test.dao"/>
        <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>
    </bean>

    <bean id="transactionManager"
          class="info.yangguo.perseus.DynamicDataSourceTransactionManager">
        <property name="dataSource" ref="dataSource"/>
    </bean>
    <tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true"/>

Batch operation configuration

    <bean id="dataSource" class="info.yangguo.perseus.DynamicDataSource">
        <property name="master" ref="master"/>
        <property name="slaves">
            <list>
                <ref bean="slave1"/>
                <ref bean="slave2"/>
            </list>
        </property>
    </bean>

    <!-- transaction manager, use JtaTransactionManager for global tx -->
    <bean id="transactionManager"
          class="info.yangguo.perseus.DynamicDataSourceTransactionManager">
        <property name="dataSource" ref="dataSource"/>
    </bean>

    <!-- enable transaction demarcation with annotations -->
    <tx:annotation-driven/>

    <!-- simplest possible SqlSessionFactory configuration -->
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource"/>
        <property name="mapperLocations" value="classpath:EmployeeMapper.xml"/>
    </bean>
    <!-- item reader  -->
    <bean id="pagingNoNestedItemReader" class="info.yangguo.perseus.DynamicMyBatisPagingItemReader">
        <property name="sqlSessionFactory" ref="sqlSessionFactory"/>
        <property name="sqlSessionTemplate" ref="dynamicSqlSession"/>
        <property name="queryId" value="getEmployeeNoNestedPaging"/>
        <property name="pageSize" value="5"/>
    </bean>

    <bean id="pagingNestedItemReader" class="info.yangguo.perseus.DynamicMyBatisPagingItemReader">
        <property name="sqlSessionFactory" ref="sqlSessionFactory"/>
        <property name="sqlSessionTemplate" ref="dynamicSqlSession"/>
        <property name="queryId" value="getEmployeeNestedPaging"/>
        <property name="pageSize" value="5"/>
    </bean>

    <bean id="cursorNoNestedItemReader" class="info.yangguo.perseus.DynamicMyBatisCursorItemReader">
        <property name="sqlSessionFactory" ref="sqlSessionFactory"/>
        <property name="queryId" value="getEmployeeNoNestedCursor"/>
    </bean>

    <bean id="cursorNestedItemReader" class="info.yangguo.perseus.DynamicMyBatisCursorItemReader">
        <property name="sqlSessionFactory" ref="sqlSessionFactory"/>
        <property name="queryId" value="getEmployeeNestedCursor"/>
    </bean>

    <bean id="writer" class="org.mybatis.spring.batch.MyBatisBatchItemWriter">
        <property name="sqlSessionFactory" ref="sqlSessionFactory"/>
        <property name="statementId" value="updateEmployee"/>
    </bean>

    <bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate">
        <constructor-arg index="0" ref="sqlSessionFactory"/>
        <constructor-arg index="1" value="BATCH"/>
    </bean>
    <bean id="dynamicSqlSession" class="info.yangguo.perseus.DynamicSqlSessionTemplate">
        <constructor-arg index="0" ref="sqlSession"/>
    </bean>
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].