com.jfinal.plugin.activerecord.ActiveRecordPlugin Java Examples
The following examples show how to use
com.jfinal.plugin.activerecord.ActiveRecordPlugin.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AppConfig.java From jfinal-api-scaffold with MIT License | 6 votes |
/** * 插件配置 */ @Override public void configPlugin(Plugins me) { // C3p0Plugin cp = new C3p0Plugin(loadPropertyFile("jdbc.properties")); // me.add(cp); //初始化连接池插件 loadPropertyFile("jdbc.properties"); HikariCPPlugin hcp = new HikariCPPlugin(getProperty("jdbcUrl"), getProperty("user"), getProperty("password"), getProperty("driverClass"), getPropertyToInt("maxPoolSize")); me.add(hcp); ActiveRecordPlugin arp = new ActiveRecordPlugin(hcp); me.add(arp); arp.addMapping("t_user", User.USER_ID, User.class);//用户表 arp.addMapping("t_register_code", RegisterCode.MOBILE, RegisterCode.class); //注册验证码对象 arp.addMapping("t_feedback", FeedBack.class); //意见反馈表 }
Example #2
Source File: JFinalConfigExt.java From jfinal-ext3 with Apache License 2.0 | 6 votes |
/** * 获取ActiveRecordPlugin * @param dp DruidPlugin * @return */ private ActiveRecordPlugin getActiveRecordPlugin(String ds, DruidPlugin dp){ ActiveRecordPlugin arp = new ActiveRecordPlugin(ds, dp); arp.setShowSql(this.getPropertyToBoolean("db.showsql")); // auto mapping if (!this.geRuned) { try { Class<?> clazz = Class.forName(this.getModelPackage()+"."+ds.toUpperCase()+this.getMappingKitClassName()); Method mapping = clazz.getMethod("mapping", ActiveRecordPlugin.class); mapping.invoke(clazz, arp); } catch (ClassNotFoundException | NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { throw (new RuntimeException(String.valueOf(e) + ",may be your table is not contain `PrimaryKey`.")); } } return arp; }
Example #3
Source File: InstallController.java From jpress with GNU Lesser General Public License v3.0 | 6 votes |
private void initActiveRecordPlugin() { DataSourceConfig config = InstallManager.me().getDataSourceConfig(); // 在只有 jboot.properties 但是没有 install.lock 的情况下 // jboot 启动的时候会出初始化 jboot.properties 里配置的插件 // 此时,会出现 config already exist 的异常 if (DbKit.getConfig(DataSourceConfig.NAME_DEFAULT) == null) { config.setName(DataSourceConfig.NAME_DEFAULT); } else { config.setName(StrUtil.uuid()); } DataSourceConfigManager.me().addConfig(config); ActiveRecordPlugin arPlugin = ArpManager.me().createRecordPlugin(config); arPlugin.start(); }
Example #4
Source File: AddonManager.java From jpress with GNU Lesser General Public License v3.0 | 6 votes |
private void clearStopedTableMapping(ActiveRecordPlugin arp) throws Exception { List<com.jfinal.plugin.activerecord.Table> tables = getTableList(arp); if (tables == null || tables.isEmpty()) { return; } Field modelToTableMapField = TableMapping.class.getDeclaredField("modelToTableMap"); modelToTableMapField.setAccessible(true); Map<Class<? extends Model<?>>, com.jfinal.plugin.activerecord.Table> modelToTableMap = (Map<Class<? extends Model<?>>, com.jfinal.plugin.activerecord.Table>) modelToTableMapField.get(TableMapping.me()); if (modelToTableMap == null || modelToTableMap.isEmpty()) { return; } for (com.jfinal.plugin.activerecord.Table table : tables) { modelToTableMap.remove(table.getModelClass()); } }
Example #5
Source File: Test.java From my_curd with Apache License 2.0 | 5 votes |
static void init() { Prop jdbcProp = PropKit.use("config-dev.txt"); DruidPlugin dp = new DruidPlugin(jdbcProp.get("oa.jdbc.url"), jdbcProp.get("oa.jdbc.user"), jdbcProp.get("oa.jdbc.password"), jdbcProp.get("oa.jdbc.driver")); dp.start(); ActiveRecordPlugin arp = new ActiveRecordPlugin(ActivitiConfig.DATASOURCE_NAME, dp); arp.setDialect(new MysqlDialect()); arp.setShowSql(true); arp.start(); ActivitiPlugin ap = new ActivitiPlugin(); ap.start(); }
Example #6
Source File: ZrLogConfig.java From zrlog with Apache License 2.0 | 5 votes |
/** * 配置JFinal提供过简易版本的ORM(其实这里是叫Active+Record)。 * * @param dataSourceProvider * @return */ private ActiveRecordPlugin getActiveRecordPlugin(IDataSourceProvider dataSourceProvider) { ActiveRecordPlugin arp = new ActiveRecordPlugin("c3p0Plugin" + new Random().nextInt(), dataSourceProvider); arp.addMapping(User.TABLE_NAME, "userId", User.class); arp.addMapping(Log.TABLE_NAME, "logId", Log.class); arp.addMapping(Type.TABLE_NAME, "typeId", Type.class); arp.addMapping(Link.TABLE_NAME, "linkId", Link.class); arp.addMapping(Comment.TABLE_NAME, "commentId", Comment.class); arp.addMapping(LogNav.TABLE_NAME, "navId", LogNav.class); arp.addMapping(WebSite.TABLE_NAME, "siteId", WebSite.class); arp.addMapping(Plugin.TABLE_NAME, "pluginId", Plugin.class); arp.addMapping(Tag.TABLE_NAME, "tagId", Tag.class); return arp; }
Example #7
Source File: AddonManager.java From jpress with GNU Lesser General Public License v3.0 | 5 votes |
private List<com.jfinal.plugin.activerecord.Table> getTableList(ActiveRecordPlugin arp) { try { Field tableListField = ActiveRecordPlugin.class.getDeclaredField("tableList"); tableListField.setAccessible(true); return (List<com.jfinal.plugin.activerecord.Table>) tableListField.get(arp); } catch (Exception ex) { LogKit.error(ex.toString(), ex); } return null; }
Example #8
Source File: AddonManager.java From jpress with GNU Lesser General Public License v3.0 | 5 votes |
private void startActiveRecordPlugin(AddonInfo addonInfo) { List<Class<? extends JbootModel>> modelClasses = addonInfo.getModels(); if (modelClasses != null && !modelClasses.isEmpty()) { ActiveRecordPlugin arp = addonInfo.getOrCreateArp(); List<com.jfinal.plugin.activerecord.Table> tableList = getTableList(arp); for (Class<? extends JbootModel> c : modelClasses) { Table tableAnnotation = c.getAnnotation(Table.class); boolean needAddMapping = true; if (tableList != null && !tableList.isEmpty()) { for (com.jfinal.plugin.activerecord.Table t : tableList) { if (t.getName().equals(AnnotationUtil.get(tableAnnotation.tableName()))) { needAddMapping = false; break; } } } if (needAddMapping) { if (StrUtil.isNotBlank(tableAnnotation.primaryKey())) { arp.addMapping(AnnotationUtil.get(tableAnnotation.tableName()), AnnotationUtil.get(tableAnnotation.primaryKey()), (Class<? extends Model<?>>) c); } else { arp.addMapping(AnnotationUtil.get(tableAnnotation.tableName()), (Class<? extends Model<?>>) c); } } } addonInfo.setArp(arp); arp.start(); } }
Example #9
Source File: SystemModelMapping.java From my_curd with Apache License 2.0 | 5 votes |
public static void mapping(ActiveRecordPlugin arp) { // 系统用户表 arp.addMapping("sys_user", "id", SysUser.class); // 角色 arp.addMapping("sys_role", "id", SysRole.class); // 系统菜单 arp.addMapping("sys_menu", "id", SysMenu.class); // 用户角色中间表 arp.addMapping("sys_user_role", "sysUserId,sysRoleId", SysUserRole.class); // 角色菜单中间表 arp.addMapping("sys_role_menu", "sysRoleId,sysMenuId", SysRoleMenu.class); // 菜单按钮 arp.addMapping("sys_button", "id", SysButton.class); // 角色 菜单按钮中间表 arp.addMapping("sys_role_button", "sysRoleId,sysButtonId", SysRoleButton.class); // 组织机构表 arp.addMapping("sys_org", "id", SysOrg.class); // 字典表 arp.addMapping("sys_dict", "id", SysDict.class); // 字典分组表 arp.addMapping("sys_dict_group", "id", SysDictGroup.class); // 通知消息 arp.addMapping("sys_notice", "id", SysNotice.class); // 通知消息从表 arp.addMapping("sys_notice_detail", "id", SysNoticeDetail.class); // 通知分类 arp.addMapping("sys_notice_type", "id", SysNoticeType.class); // 系统通知类型角色中间表 arp.addMapping("sys_notice_type_sys_role", "sysNoticeTypeId,sysRoleId", SysNoticeTypeSysRole.class); // 系统访问日志 arp.addMapping("sys_visit_log", "id", SysVisitLog.class); // 定时任务日志 arp.addMapping("sys_task_log", "id", SysTaskLog.class); // 系统设置项 arp.addMapping("sys_setting", "id", SysSetting.class); }
Example #10
Source File: ExampleModelMapping.java From my_curd with Apache License 2.0 | 5 votes |
public static void mapping(ActiveRecordPlugin arp) { // 例子 单表结构 arp.addMapping("ex_single_table", "id", ExSingleTable.class); // 员工教育经历 arp.addMapping("ex_staff_education", "id", ExStaffEducation.class); // 员工工作经历 arp.addMapping("ex_staff_experience", "id", ExStaffExperience.class); // 员工家人 arp.addMapping("ex_staff_family", "id", ExStaffFamily.class); // 一线员工 arp.addMapping("ex_staff", "id", ExStaff.class); }
Example #11
Source File: _MappingKit.java From sdb-mall with Apache License 2.0 | 5 votes |
public static void mapping(ActiveRecordPlugin arp) { arp.addMapping("area", "id", Area.class); arp.addMapping("campaign", "id", Campaign.class); arp.addMapping("cart", "id", Cart.class); arp.addMapping("delivery_corp", "code", DeliveryCorp.class); // Composite Primary Key order: favorite_goods,favorite_user arp.addMapping("favorite_goods", "favorite_goods,favorite_user", FavoriteGoods.class); arp.addMapping("goods", "sn", Goods.class); arp.addMapping("groupon", "id", Groupon.class); // Composite Primary Key order: groupon_id,user_id arp.addMapping("groupon_team", "groupon_id,user_id", GrouponTeam.class); arp.addMapping("logistics", "tracking_no", Logistics.class); arp.addMapping("order_detail", "detail_id", OrderDetail.class); arp.addMapping("order_master", "order_id", OrderMaster.class); arp.addMapping("product", "sn", Product.class); arp.addMapping("product_category", "id", ProductCategory.class); arp.addMapping("receiver", "id", Receiver.class); arp.addMapping("schedule_job", "job_id", ScheduleJob.class); arp.addMapping("schedule_job_log", "log_id", ScheduleJobLog.class); arp.addMapping("sn", "type", Sn.class); arp.addMapping("specification", "id", Specification.class); arp.addMapping("sys_captcha", "uuid", SysCaptcha.class); arp.addMapping("sys_config", "id", SysConfig.class); arp.addMapping("sys_log", "id", SysLog.class); arp.addMapping("sys_menu", "menu_id", SysMenu.class); arp.addMapping("sys_oss", "id", SysOss.class); arp.addMapping("sys_role", "role_id", SysRole.class); arp.addMapping("sys_role_menu", "id", SysRoleMenu.class); arp.addMapping("sys_user", "user_id", SysUser.class); arp.addMapping("sys_user_role", "id", SysUserRole.class); arp.addMapping("sys_user_token", "user_id", SysUserToken.class); arp.addMapping("user", "user_id", User.class); }
Example #12
Source File: DemoConfig.java From sqlhelper with GNU Lesser General Public License v3.0 | 5 votes |
/** * 配置插件 */ public void configPlugin(Plugins me) { // 配置 druid 数据库连接池插件 DruidPlugin druidPlugin = new DruidPlugin(p.get("jdbcUrl"), p.get("user"), p.get("password").trim()); me.add(druidPlugin); // 配置ActiveRecord插件 ActiveRecordPlugin arp = new ActiveRecordPlugin(druidPlugin); arp.setDialect(new JFinalCommonDialect("h2")); // 所有映射在 MappingKit 中自动化搞定 _MappingKit.mapping(arp); me.add(arp); }
Example #13
Source File: JFinalConfigExt.java From jfinal-ext3 with Apache License 2.0 | 5 votes |
/** * Config plugin */ public void configPlugin(Plugins me) { String[] dses = this.getDataSource(); for (String ds : dses) { if (!this.getDbActiveState(ds)) { continue; } DruidPlugin drp = this.getDruidPlugin(ds); me.add(drp); ActiveRecordPlugin arp = this.getActiveRecordPlugin(ds, drp); me.add(arp); } // config ModelRedisPlugin String[] caches = this.getRedisCaches(); for (String cache : caches) { if (!this.getRedisActiveState(cache)) { continue; } // conf redis plguin RedisPlugin rp = null; String redisPassword = this.getRedisPassword(cache); if (StrKit.isBlank(redisPassword)) { rp = new RedisPlugin(cache, this.getRedisHost(cache), this.getRedisPort(cache)); } else { rp = new RedisPlugin(cache, this.getRedisHost(cache), this.getRedisPort(cache), this.getRedisPassword(cache)); } me.add(rp); // conf redis model plugin ModelRedisPlugin mrp = new ModelRedisPlugin(cache, this.getRedisCacheTables(cache)); me.add(mrp); } // config others configMorePlugins(me); }
Example #14
Source File: DBKit.java From NewsRecommendSystem with MIT License | 5 votes |
public static void initalize() { try { HashMap<String, String> info = getDBInfo(); cp = new C3p0Plugin(info.get("url"), info.get("user"), info.get("password")); ActiveRecordPlugin arp = new ActiveRecordPlugin(cp); arp.addMapping("users", Users.class); arp.addMapping("news", News.class); arp.addMapping("newsmodules", Newsmodules.class); arp.addMapping("newslogs", Newslogs.class); arp.addMapping("recommendations", Recommendations.class); if(cp.start() && arp.start()) logger.info("数据库连接池插件启动成功......"); else logger.info("c3p0插件启动失败!"); logger.info("数据库初始化工作完毕!"); } catch (Exception e) { logger.error("数据库连接初始化错误!"); } return; }
Example #15
Source File: ActiveRecordConfig.java From sdb-mall with Apache License 2.0 | 5 votes |
@Bean(initMethod="start", destroyMethod="stop") public ActiveRecordPlugin init() { ActiveRecordPlugin arp = new ActiveRecordPlugin(ds); arp.addSqlTemplate("sql/all.sql"); // arp.addMapping("user", UserModel.class); arp.getEngine().setSourceFactory(new ClassPathSourceFactory()); _MappingKit.mapping(arp); return arp; }
Example #16
Source File: JbootCoreConfig.java From jboot with Apache License 2.0 | 5 votes |
@Override public void configPlugin(Plugins plugins) { List<ActiveRecordPlugin> arps = ArpManager.me().getActiveRecordPlugins(); for (ActiveRecordPlugin arp : arps) { plugins.add(arp); } JbootAppListenerManager.me().onPluginConfig(new JfinalPlugins(plugins)); }
Example #17
Source File: _MappingKit.java From NewsRecommendSystem with MIT License | 5 votes |
public static void mapping(ActiveRecordPlugin arp) { arp.addMapping("news", "id", News.class); arp.addMapping("newslogs", "id", Newslogs.class); arp.addMapping("newsmodules", "id", Newsmodules.class); arp.addMapping("recommendations", "id", Recommendations.class); arp.addMapping("users", "id", Users.class); }
Example #18
Source File: AppConfig.java From my_curd with Apache License 2.0 | 4 votes |
@SuppressWarnings("Duplicates") @Override public void configPlugin(Plugins me) { // 数据源 1 (用户权限、组织机构、主数据 等) main DruidPlugin sysDruid = new DruidPlugin(configProp.get("jdbc.url"), configProp.get("jdbc.user"), configProp.get("jdbc.password"), configProp.get("jdbc.driver")); sysDruid.setInitialSize(configProp.getInt("jdbc.initialSize")); sysDruid.setMaxActive(configProp.getInt("jdbc.maxActive")); sysDruid.setMinIdle(configProp.getInt("jdbc.minIdle")); StatFilter statFilter = new StatFilter(); WallFilter wall = new WallFilter(); wall.setDbType(configProp.get("jdbc.dbType")); sysDruid.addFilter(statFilter); sysDruid.addFilter(wall); me.add(sysDruid); ActiveRecordPlugin sysActiveRecord = new ActiveRecordPlugin(sysDruid); sysActiveRecord.setDialect(new MysqlDialect()); sysActiveRecord.setShowSql(activeProfile.equalsIgnoreCase("dev")); SystemModelMapping.mapping(sysActiveRecord); // system 模块 ExampleModelMapping.mapping(sysActiveRecord); // example 模块 me.add(sysActiveRecord); log.info("设置 数据源 sysDruid sysActiveRecord 成功"); // 数据源2 (activiti表、流程表单) my_curd_oa DruidPlugin oaDruid = new DruidPlugin(configProp.get("oa.jdbc.url"), configProp.get("oa.jdbc.user"), configProp.get("oa.jdbc.password"), configProp.get("oa.jdbc.driver")); oaDruid.setInitialSize(configProp.getInt("oa.jdbc.initialSize")); oaDruid.setMaxActive(configProp.getInt("oa.jdbc.maxActive")); oaDruid.setMinIdle(configProp.getInt("oa.jdbc.minIdle")); oaDruid.addFilter(statFilter); oaDruid.addFilter(wall); me.add(oaDruid); ActiveRecordPlugin oaActiveRecord = new ActiveRecordPlugin(ActivitiConfig.DATASOURCE_NAME,oaDruid); oaActiveRecord.setDialect(new MysqlDialect()); oaActiveRecord.setShowSql(activeProfile.equalsIgnoreCase("dev")); OaModelMapping.mapping(oaActiveRecord); me.add(oaActiveRecord); log.info("设置 数据源 oaDruid oaActiveRecord 成功"); // activiti 插件 ActivitiPlugin ap = new ActivitiPlugin(); me.add(ap); log.info("加载 Activiti 插件 成功"); // 定时任务 Cron4jPlugin cp = new Cron4jPlugin(configProp, "cron4j"); me.add(cp); log.info("加载 Corn4j 插件 成功"); // redis 插件 // RedisPlugin userRedis = new RedisPlugin("user", configProp.get("redis.host"),configProp.getInt("redis.port") // ,configProp.getInt("redis.timeout"),configProp.get("redis.password"),configProp.getInt("redis.database")); // me.add(userRedis); // log.info("加载redis 插件成功"); }
Example #19
Source File: AddonManager.java From jpress with GNU Lesser General Public License v3.0 | 4 votes |
private void stopActiveRecordPlugin(AddonInfo addonInfo) throws Exception { ActiveRecordPlugin arp = addonInfo.getArp(); if (arp != null && arp.stop()) { clearStopedTableMapping(arp); } }
Example #20
Source File: _MappingKit.java From sqlhelper with GNU Lesser General Public License v3.0 | 4 votes |
public static void mapping(ActiveRecordPlugin arp) { arp.addMapping("blog", "id", Blog.class); }
Example #21
Source File: _MappingKit.java From jfinal-ext3 with Apache License 2.0 | 4 votes |
public static void mapping(ActiveRecordPlugin arp) { arp.addMapping("zcq", "id", Zcq.class); arp.addMapping("zcq_copy_zz", "name", ZcqCopyZz.class); }
Example #22
Source File: AddonInfo.java From jpress with GNU Lesser General Public License v3.0 | 4 votes |
public ActiveRecordPlugin getArp() { return arp; }
Example #23
Source File: AddonInfo.java From jpress with GNU Lesser General Public License v3.0 | 4 votes |
public ActiveRecordPlugin getOrCreateArp() { if (arp == null) { arp = AddonUtil.createRecordPlugin(this); } return arp; }
Example #24
Source File: AddonInfo.java From jpress with GNU Lesser General Public License v3.0 | 4 votes |
public void setArp(ActiveRecordPlugin arp) { this.arp = arp; }
Example #25
Source File: AddonUtil.java From jpress with GNU Lesser General Public License v3.0 | 4 votes |
public static ActiveRecordPlugin createRecordPlugin(AddonInfo addonInfo) { DataSourceConfig config = getDatasourceConfig(addonInfo); config.setName(addonInfo.getId()); config.setNeedAddMapping(false); return ArpManager.me().createRecordPlugin(config); }
Example #26
Source File: MYSQLTableMappingKit.java From jfinal-ext3 with Apache License 2.0 | 4 votes |
public static void mapping(ActiveRecordPlugin arp) { // Composite Primary Key order: id,name //arp.addMapping("hello", "id,name", Hello.class); // Composite Primary Key order: id,name arp.addMapping("user", "id,name", User.class); }
Example #27
Source File: OaModelMapping.java From my_curd with Apache License 2.0 | 4 votes |
public static void mapping(ActiveRecordPlugin arp) { // 业务表定义信息 arp.addMapping("business_form_info", "id", BusinessFormInfo.class); // 请假流程表单 arp.addMapping("form_leave", "id", FormLeave.class); }