12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- package com.cn.config;
- import com.jfinal.config.Constants;
- import com.jfinal.config.JFinalConfig;
- import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
- import com.jfinal.plugin.druid.DruidPlugin;
- import org.apache.commons.lang3.StringUtils;
- import org.jim.common.utils.Prop;
- import org.jim.common.utils.PropUtil;
- import org.jim.server.model.*;
- /**
- * @author Darren
- * @date 2020/1/30 19:30
- */
- public class PropertyDataBaseConfigBuilder {
- private static Prop prop;
- private PropertyDataBaseConfigBuilder() {
- }
- public static void init(String file){
- if(StringUtils.isEmpty(file)){
- throw new RuntimeException("file is Empty!");
- }
- prop = PropUtil.use(file);
- //创建 Druid 数据库连接池 (jfinal)
- DruidPlugin druidPlugin = new DruidPlugin(
- prop.get("jdbcUrl"), prop.get("user"), prop.get("password"),prop.get("driverClass")
- );
- //设置连接池相关数据
- druidPlugin.set(prop.getInt("initialSize"),prop.getInt("minIdle"),prop.getInt("maxActive"));
- druidPlugin.setConnectionInitSql("set names utf8mb4");
- ActiveRecordPlugin arp = new ActiveRecordPlugin(druidPlugin);
- //设置实体 表 关系映射
- arp.addMapping("sw_group","group_id", ChatGroup.class);
- arp.addMapping("sw_conversation","id", Conversation.class);
- arp.addMapping("sw_conversation_record","id", ConversationRecord.class);
- arp.addMapping("sw_customer_department_middle","id", CustomerDepartmentMiddle.class);
- arp.addMapping("sw_role_department_middle","id", RoleDepartmentMiddle.class);
- arp.addMapping("sw_service_account","id", ServiceAccount.class);
- arp.addMapping(
- "sw_service_account_role_department_middle"
- ,"id"
- , ServiceAccountRoleDepartmentMiddle.class
- );
- arp.addMapping("sw_visitor_department_middle","id",VisitorDepartmentMiddle.class);
- arp.addMapping("sw_auto_reply_message","id",AutoReplyMessage.class);
- // 与 jfinal web 环境唯一的不同是要手动调用一次相关插件的start()方法
- druidPlugin.start();
- arp.start();
- //设置开发者模式
- // arp.setDevMode(true);
- //设置打印sql
- // arp.setShowSql(true);
- }
- }
|