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

import net.northking.cctp.common.db.mode.DataBaseModeAspect;
import net.northking.cctp.common.db.mode.NKDataSourceClusterProperties;
import net.northking.cctp.common.db.mode.SingleClusterDataSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 数据库读写分离配置
 *
 * @author : xiusong.xie
 * @version : 1.0
 */
@Configuration
public class NKDataSourceClusterConfiguration
{
  /**
   * 日志
   */
  private final static Logger logger = LoggerFactory.getLogger(NKDataSourceClusterConfiguration.class);

  @Bean(name = "datasource")
  public SingleClusterDataSource singleClusterDataSource(NKDataSourceClusterProperties properties)
  {
    SingleClusterDataSource dataSource = new SingleClusterDataSource();
    dataSource.setClusterProperties(properties.getClusterProperties());
    logger.info("注册公共组件提示：统一配置 数据源单一集群模式 已启用。");

    return dataSource;
  }

  /**
   * 数据库读写模式切面
   *
   * @return 数据库读写模式切面
   */
  @Bean
  public DataBaseModeAspect databaseModeAspect()
  {
    return new DataBaseModeAspect();
  }
}
