/*
 * Copyright (c) 京北方信息技术股份有限公司 Corporation 2021 . All rights reserved.
 *
 */
package net.northking.cctp.common.db.mode;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.core.Ordered;

/**
 * 数据库读写模式切面类
 *
 * @author : xiusong.xie
 * @version : 1.0
 */
@Aspect
public class DataBaseModeAspect implements Ordered
{

  /**
   * 设置优先级，确保当前切面的优先级高于数据库事务处理
   *
   * @return 优先级
   */
  @Override
  public int getOrder()
  {
    return 0;
  }

  @Before("@annotation(net.northking.cctp.common.db.annotation.DatabaseReadOnly)")
  public void setDatabaseReadOnly(JoinPoint joinPoint)
  {
    DataBaseModeContext.readMode();
  }

  @Before("@annotation(net.northking.cctp.common.db.annotation.DatabaseWriteOnly)")
  public void setDatabaseWriteOnly(JoinPoint joinPoint)
  {
    DataBaseModeContext.writeMode();
  }
}
