Esempio n. 1
1
 /** 配置插件 */
 public void configPlugin(Plugins me) {
   logger.info("配置插件开始..");
   DruidPlugin dp =
       new DruidPlugin(PropKit.get("jdbcUrl"), PropKit.get("user"), PropKit.get("password"));
   WallFilter wf = new WallFilter();
   wf.setDbType("mysql");
   dp.addFilter(wf);
   me.add(dp);
   // 配置Ecache插件
   me.add(new EhCachePlugin());
   // 配置ActiveRecord插件
   ActiveRecordPlugin arp = new ActiveRecordPlugin(dp);
   me.add(arp);
   arp.setDevMode(true);
   arp.setShowSql(true);
   // 此项目并没有用到jfinal2.2的javabean与model的合体,感兴趣的可以参照jfinal官网的demo
   arp.addMapping("blog", Blog.class); // 映射blog 表到 Blog模型
   arp.addMapping("user", User.class); // 用户
   arp.addMapping("qquser", Qquser.class); // qq用户
   arp.addMapping("blogcategory", Blogcategory.class); // 博客分类
   arp.addMapping("userlogininfo", Userlogininfo.class); // 用户登陆信息
   arp.addMapping("advice", Advice.class); // 建议
   arp.addMapping("role", Role.class); // 角色
   arp.addMapping("userrole", Userrole.class); // 用户角色中间表
   arp.addMapping("picrecommend", Picrecommend.class); // 首页图片推荐--推荐尺寸为630*350
   arp.addMapping("beauty", Beauty.class); // 美图
   arp.addMapping("gonggao", Gonggao.class); // 公告
   arp.addMapping("iplog", Iplog.class); // ip和URL日志
   arp.addMapping("video", Video.class); // 视频模块
   arp.addMapping("resourceslog", Resourceslog.class); // 系统资源监控日志
   arp.addMapping("link", Link.class); // 友情链接
   logger.info("配置插件结束..");
 }
Esempio n. 2
0
  /** 配置插件 */
  @Override
  public void configPlugin(Plugins me) {
    /** 配置Druid数据库连接池插件* */
    DruidPlugin dp =
        new DruidPlugin(
            ReadPropertity.getProperty("jdbcUrl"),
            ReadPropertity.getProperty("user"),
            ReadPropertity.getProperty("password"));
    dp.addFilter(new StatFilter());
    dp.setMaxActive(150);
    WallFilter wall = new WallFilter();
    wall.setDbType(ReadPropertity.getProperty("dbType"));
    dp.addFilter(wall);
    me.add(dp);

    /** 配置ActiveRecord插件* */
    ActiveRecordPlugin arp = new ActiveRecordPlugin(dp);
    me.add(arp);

    /** 加载EhCache插件* */
    me.add(new EhCachePlugin());

    arp.addMapping("admin", Admin.class);
    arp.addMapping("category", Category.class);
    arp.addMapping("article", Article.class);
    arp.addMapping("links", Links.class);
    arp.addMapping("website", Website.class);
    arp.addMapping("tags", Tags.class);
    arp.addMapping("gbook", Gbook.class);
  }
 public void initARP() throws Exception {
   String jdbcConfig = System.getProperty("user.dir") + "/WebContent/WEB-INF/jdbc.properties";
   Properties properties = new Properties();
   try {
     properties.load(new FileInputStream(new File(jdbcConfig)));
     druidPlugin =
         new DruidPlugin(
             properties.getProperty("jdbcUrl").toString(),
             properties.getProperty("user").toString(),
             properties.getProperty("password").toString());
   } catch (Exception e) {
     logger.error(e.getMessage(), e);
     return;
   }
   arp = new ActiveRecordPlugin(druidPlugin);
   List<Class<? extends Model<?>>> modelClasses = getMappingClasses();
   if (!modelClasses.isEmpty()) {
     for (Class<? extends Model<?>> clazz : modelClasses) {
       TableBind tableBind = clazz.getAnnotation(TableBind.class);
       String modelTable = tableBind.tableName();
       String modelPk = tableBind.pkName();
       arp.addMapping(modelTable, modelPk, clazz);
     }
   }
   druidPlugin.start();
   arp.start();
 }
Esempio n. 4
0
 /** 配置插件 */
 public void configPlugin(Plugins me) {
   // [ copy from @ mike 的适配器 :) ]
   String dbname, username, password, host, port, driver;
   driver = getProperty("driverClass");
   if (isLocal) {
     dbname = getProperty("dbname");
     username = getProperty("username");
     port = getProperty("port");
     host = getProperty("host");
     password = getProperty("password");
   } else {
     JSONObject credentials =
         JSONObject.parseObject(json)
             .getJSONArray("mysql-5.1")
             .getJSONObject(0)
             .getJSONObject("credentials");
     host = credentials.getString("host");
     port = credentials.getString("port");
     dbname = credentials.getString("name");
     username = credentials.getString("username");
     password = credentials.getString("password");
   }
   DruidPlugin druidPlugin =
       new DruidPlugin(
           "jdbc:mysql://" + host + ":" + port + "/" + dbname, username, password, driver);
   druidPlugin.setInitialSize(3).setMaxActive(10);
   me.add(druidPlugin);
   // 配置ActiveRecord插件
   ActiveRecordPlugin arp = new ActiveRecordPlugin(druidPlugin);
   if (isLocal) {
     arp.setShowSql(true);
   }
   arp.addMapping("module", Module.class)
       .addMapping("topic", Topic.class)
       .addMapping("post", Post.class);
   arp.addMapping("reply", Reply.class).addMapping("sub_module", SubModule.class);
   me.add(arp);
   // 缓存插件
   me.add(new EhCachePlugin());
 }
Esempio n. 5
0
  /** 配置插件 */
  public void configPlugin(Plugins me) {
    log.info("configPlugin 配置Druid数据库连接池连接属性");
    DruidPlugin druidPlugin =
        new DruidPlugin(
            (String) PropertiesPlugin.getParamMapValue(DictKeys.db_connection_jdbcUrl),
            (String) PropertiesPlugin.getParamMapValue(DictKeys.db_connection_userName),
            (String) PropertiesPlugin.getParamMapValue(DictKeys.db_connection_passWord),
            (String) PropertiesPlugin.getParamMapValue(DictKeys.db_connection_driverClass));

    log.info("configPlugin 配置Druid数据库连接池大小");
    druidPlugin.set(
        (Integer) PropertiesPlugin.getParamMapValue(DictKeys.db_initialSize),
        (Integer) PropertiesPlugin.getParamMapValue(DictKeys.db_minIdle),
        (Integer) PropertiesPlugin.getParamMapValue(DictKeys.db_maxActive));

    log.info("configPlugin 配置ActiveRecord插件");
    ActiveRecordPlugin arpMain = new ActiveRecordPlugin(DictKeys.db_dataSource_main, druidPlugin);
    // arp.setTransactionLevel(4);//事务隔离级别
    arpMain.setDevMode(getPropertyToBoolean(DictKeys.config_devMode, false)); // 设置开发模式
    arpMain.setShowSql(getPropertyToBoolean(DictKeys.config_devMode, false)); // 是否显示SQL

    log.info("configPlugin 数据库类型判断");
    String db_type = (String) PropertiesPlugin.getParamMapValue(DictKeys.db_type_key);
    if (db_type.equals(DictKeys.db_type_postgresql)) {
      log.info("configPlugin 使用数据库类型是 postgresql");
      arpMain.setDialect(new PostgreSqlDialect());
      arpMain.setContainerFactory(
          new CaseInsensitiveContainerFactory(true)); // 配置属性名(字段名)大小写不敏感容器工厂

    } else if (db_type.equals(DictKeys.db_type_mysql)) {
      log.info("configPlugin 使用数据库类型是 mysql");
      arpMain.setDialect(new MysqlDialect());
      arpMain.setContainerFactory(
          new CaseInsensitiveContainerFactory(true)); // 配置属性名(字段名)大小写不敏感容器工厂

    } else if (db_type.equals(DictKeys.db_type_oracle)) {
      log.info("configPlugin 使用数据库类型是 oracle");
      druidPlugin.setValidationQuery(
          "select 1 FROM DUAL"); // 指定连接验证语句(用于保存数据库连接池), 这里不加会报错误:invalid oracle validationQuery.
                                 // select 1, may should be : select 1 FROM DUAL
      arpMain.setDialect(new OracleDialect());
      arpMain.setContainerFactory(
          new CaseInsensitiveContainerFactory(true)); // 配置属性名(字段名)大小写不敏感容器工厂
    }

    log.info("configPlugin 添加druidPlugin插件");
    me.add(druidPlugin); // 多数据源继续添加

    log.info("configPlugin 表扫描注册");
    Map<String, ActiveRecordPlugin> arpMap = new HashMap<String, ActiveRecordPlugin>();
    arpMap.put(DictKeys.db_dataSource_main, arpMain); // 多数据源继续添加
    new TablePlugin(arpMap).start();
    me.add(arpMain); // 多数据源继续添加

    log.info("I18NPlugin 国际化键值对加载");
    me.add(new I18NPlugin());

    log.info("EhCachePlugin EhCache缓存");
    me.add(new EhCachePlugin());

    log.info("SqlXmlPlugin 解析并缓存 xml sql");
    me.add(new SqlXmlPlugin());
  }