package com.bonus.core.data.dataset.tx;

import com.bonus.core.data.dataset.rule.RoutingRule;
import org.springframework.jdbc.support.JdbcTransactionManager;
import org.springframework.transaction.TransactionDefinition;

import javax.sql.DataSource;

public class XJdbcTransactionManager extends JdbcTransactionManager {
   public XJdbcTransactionManager(DataSource dataSource) {
      super(dataSource);
   }

   protected void doBegin(Object transaction, TransactionDefinition definition) {
      RoutingRule.accessMaster();
      super.doBegin(transaction, definition);
   }

   protected void doCleanupAfterCompletion(Object transaction) {
      try {
         super.doCleanupAfterCompletion(transaction);
      } finally {
         RoutingRule.resetAccess();
      }

   }
}
