Exemplo n.º 1
1
  /**
   * model
   *
   * @param me
   */
  @Override
  public void configPlugin(Plugins me) {

    componentSscan(basePackage);

    IDataSourceProvider iDataSourceProvider = setDataSource();
    try {
      me.add((IPlugin) iDataSourceProvider);
    } catch (Exception e) {
      throw new RuntimeException("is not IPlugin type");
    }
    ActiveRecordPlugin arp = new ActiveRecordPlugin(iDataSourceProvider);

    addActiveRecord(arp); // 加入附加的活动记录
    Scan driven = new Scan();
    for (String pake : basePackage) {
      Set<Class<?>> clazzs = driven.getClasses(pake);

      for (Class<?> clazz : clazzs) {
        LOG.info(clazz.getName());
        Class superClass = clazz.getSuperclass();
        Class<?> jfClz = com.jfinal.plugin.activerecord.Model.class;
        if (superClass == jfClz || superClass.getSuperclass() == jfClz) {
          M model = clazz.getAnnotation(M.class);
          if (null != model) {
            arp.addMapping(model.value(), model.id(), (Class<? extends Model<?>>) clazz);
          }
        }
      }
    }
    me.add(arp);
  }
Exemplo n.º 2
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("配置插件结束..");
 }
Exemplo n.º 3
0
  /** 配置插件 */
  public void configPlugin(Plugins me) {

    // 配置C3p0数据库连接池插件
    C3p0Plugin c3 =
        new C3p0Plugin(getProperty("url"), getProperty("username"), getProperty("password").trim());
    c3.setDriverClass(getProperty("driverClassName"));
    me.add(c3);

    // 配置ActiveRecord插件

    ActiveRecordPlugin arp = new ActiveRecordPlugin(c3);
    arp.addMapping("kk_product", Goods.class);
    arp.addMapping("kk_manager", Manager.class);
    arp.addMapping("kk_res", Res.class);
    arp.addMapping("kk_user", User.class);
    arp.addMapping("kk_shop", Shop.class);
    arp.addMapping("kk_product_img", GoodsImg.class);
    arp.addMapping("kk_order", Order.class);
    arp.addMapping("kk_order_cache", OrderCache.class);
    arp.addMapping("kk_product_fb", FBGoods.class);
    arp.setShowSql(false);
    me.add(arp);

    // 配置极光推送插件
    JPush jpush = new JPush();
    me.add(jpush);
  }
Exemplo n.º 4
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);
  }
Exemplo n.º 5
0
 @Override
 public void configPlugin(Plugins me) {
   DruidPlugin druidPlugin =
       new DruidPlugin(getProperty("jdbcURL"), getProperty("username"), getProperty("password"));
   me.add(druidPlugin);
   ActiveRecordPlugin arp = new ActiveRecordPlugin(druidPlugin);
   me.add(arp);
 }
Exemplo n.º 6
0
  public void configPlugin(Plugins plugins) {
    plugins.add(new MessagePlugin());
    plugins.add(new EhCachePlugin());

    if (Jpress.isInstalled()) {
      DruidPlugin druidPlugin = createDruidPlugin();
      plugins.add(druidPlugin);

      ActiveRecordPlugin activeRecordPlugin = createRecordPlugin(druidPlugin);
      plugins.add(activeRecordPlugin);
    }
  }
Exemplo n.º 7
0
 /** Config plugin */
 public void configPlugin(Plugins me) {
   String[] dses = this.getDataSource();
   for (String ds : dses) {
     if (!this.getDbActiveState(ds)) {
       continue;
     }
     DruidEncryptPlugin drp = this.getDruidPlugin(ds);
     me.add(drp);
     ActiveRecordPlugin arp = this.getActiveRecordPlugin(ds, drp);
     me.add(arp);
     configTablesMapping(ds, arp);
   }
   // config others
   configMorePlugins(me);
 }
Exemplo n.º 8
0
  /** configPlugin(配置插件) */
  public void configPlugin(Plugins me) {
    // 配置C3p0数据库连接池插件
    // C3p0Plugin c3p0Plugin = new C3p0Plugin(PropKit.get("jdbcUrl"),
    // PropKit.get("user"), PropKit.get("password").trim());
    // me.add(c3p0Plugin);
    HikariCPPlugin hcp =
        new HikariCPPlugin(
            PropKit.get("jdbcUrl"),
            PropKit.get("user"),
            PropKit.get("password").trim(),
            PropKit.get("driverClass"),
            PropKit.getInt("maxPoolSize"));
    me.add(hcp);
    // 配置ActiveRecord插件
    ActiveRecordPlugin arp = new ActiveRecordPlugin(hcp);
    arp.setShowSql(true);
    me.add(arp);
    arp.addMapping("direct_answer", DirectAnswer.class);
    arp.addMapping("direct_content", DirectContent.class);
    arp.addMapping("direct_evaluate", DirectEvaluate.class);
    arp.addMapping("direct_type", DirectType.class);
    arp.addMapping("user", User.class);
    arp.addMapping("user_direct", UserDirect.class);
    arp.addMapping("direct_seeding", DirectSeeding.class);

    /** ************************************** 集群redis */
    // 用于缓存bbs模块的redis服务
    RedisPlugin seedingRedis =
        new RedisPlugin(
            PropKit.get("redisname"),
            PropKit.get("redislocalhost"),
            PropKit.getInt("redispoit"),
            PropKit.getInt("redistimeout")); // 七天失效
    //		RedisPlugin seedingRedis = new RedisPlugin("direct", "10.163.197.17",6379,25200);  //七天失效
    JedisPoolConfig jpl = seedingRedis.getJedisPoolConfig();
    // 连接超时
    jpl.setMaxWaitMillis(1000 * 3);
    // 最大空闲连接数, 默认8个
    jpl.setMaxIdle(20);
    // 设置最小空闲连接数或者说初始化连接数
    jpl.setMinIdle(10);
    // 多长空闲时间之后回收空闲连接
    jpl.setMinEvictableIdleTimeMillis(60000);
    // 最大连接
    jpl.setMaxTotal(100);
    jpl.setTestOnBorrow(true);
    me.add(seedingRedis);
  }
Exemplo n.º 9
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());
 }
Exemplo n.º 10
0
  @Override
  public void configPlugin(Plugins me) {
    // TODO Auto-generated method stub
    C3p0Plugin cp = new C3p0Plugin("jdbc:mysql://192.168.1.89/agreept", "agree", "123456");
    me.add(cp);
    ActiveRecordPlugin arp = new ActiveRecordPlugin(cp);
    me.add(arp);
    arp.addMapping("var_map_info", "var_zh_name", Map.class);

    /*C3p0Plugin cp = new C3p0Plugin("jdbc:oracle:thin:@localhost:1521:orcl",
            "pdcm", "pdcm");

    cp.setDriverClass("oracle.jdbc.driver.OracleDriver");
    me.add(cp);
    ActiveRecordPlugin arp = new ActiveRecordPlugin(cp);
    me.add(arp);

    arp.setDialect(new OracleDialect());

    arp.setContainerFactory(new CaseInsensitiveContainerFactory());
    arp.addMapping("BLOG", "ID", Map.class);*/
  }
Exemplo n.º 11
0
 @Override
 public void configPlugin(Plugins me) {
   log.info("C3p0初始化,链接数据库");
   C3p0Plugin cp = new C3p0Plugin("jdbc:mysql://localhost:3306/BFMS", "root", "123456");
   me.add(cp);
   ActiveRecordPlugin arp = new ActiveRecordPlugin(cp);
   me.add(arp);
   log.info("配置Model和数据库表映射");
   arp.addMapping("City", City.class);
   arp.addMapping("CityRecord", CityRecord.class);
   arp.addMapping("CityRfc", CityRfc.class);
   arp.addMapping("County", County.class);
   arp.addMapping("CountyRecord", CountyRecord.class);
   arp.addMapping("Project", Project.class);
   arp.addMapping("ProvinceRecord", ProvinceRecord.class);
   arp.addMapping("ProvinceRfc", ProvinceRfc.class);
   arp.addMapping("Subject", Subject.class);
   arp.addMapping("User", User.class);
   log.info("配置RecordLog数据库表映射");
   arp.addMapping("ProvinceRecordLog", ProvinceRecordLog.class);
   arp.addMapping("CityRecordLog", CityRecordLog.class);
   arp.addMapping("CountyRecordLog", CountyRecordLog.class);
 }
Exemplo n.º 12
0
  /** 配置插件 */
  public void configPlugin(Plugins me) {
    // 配置数据库连接池插件
    DruidPlugin druid =
        new DruidPlugin(
            getProperty("jdbcUrl"), getProperty("user"), getProperty("password").trim());
    me.add(druid);

    AutoTableBindPlugin atb = new AutoTableBindPlugin(druid, SimpleNameStyles.UP_UNDERLINE);
    atb.addScanPackages("cn.brent.console.webapp.model");
    me.add(atb);

    // shiro权限管理
    ShiroPlugin shiro = new ShiroPlugin(routes);
    me.add(shiro);

    // 复杂SQL用xml管理 获取:SqlKit.sql("xx.xx")
    SqlInXmlPlugin sqlInXml = new SqlInXmlPlugin();
    me.add(sqlInXml);

    // 缓存插件
    EhCachePlugin ehcahe = new EhCachePlugin();
    me.add(ehcahe);
  }
Exemplo n.º 13
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());
  }