package com.sifang.modules.sys.common.utils;


import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.activerecord.DbKit;
import com.jfinal.plugin.druid.DruidPlugin;
import com.sifang.modules.sys.common.global.Global;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

import javax.sql.DataSource;


public class JFinalDb implements ApplicationContextAware {
  public void setApplicationContext(ApplicationContext ctx) throws BeansException {

    (new ActiveRecordPlugin(DbKit.MAIN_CONFIG_NAME, ctx.getBean(DataSource.class))).start();

    String url = Global.getConfig("jdbc.smart.url");
    String username = Global.getConfig("jdbc.smart.username");
    String password = Global.getConfig("jdbc.smart.password");
    DruidPlugin druid = new DruidPlugin(url, username, password);
    druid.start();

    ActiveRecordPlugin arp = new ActiveRecordPlugin(DbKey.DB_YOUKUA, druid);
    arp.setShowSql(false);
    arp.start();
  }
}
