com.jfinal.plugin.activerecord.generator.MetaBuilder Java Examples
The following examples show how to use
com.jfinal.plugin.activerecord.generator.MetaBuilder.
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: _JFCodeGenerator.java From sdb-mall with Apache License 2.0 | 6 votes |
public TableMeta getTableMeta(String tableName) { if (tablemetaMap == null) { DataSource dataSource = _JFinalGenerator.getDataSource(); MetaBuilder metaBuilder = new MetaBuilder(dataSource); metaBuilder.setDialect(new MysqlDialect()); metaBuilder.addExcludedTable(_JFinalGenerator.excludedTable); List<TableMeta> tableMetas = metaBuilder.build(); new DataGenerator(dataSource, null).rebuildColumnMetas(tableMetas); if (tableMetas.size() == 0) { System.out.println("TableMeta 数量为 0,不生成任何文件"); return null; } Kv kv = Kv.create(); for (TableMeta tableMeta : tableMetas) { kv.set(tableMeta.name, tableMeta); } tablemetaMap = kv; } return (TableMeta) tablemetaMap.get(tableName); }
Example #2
Source File: _JFinalGenerator.java From sdb-mall with Apache License 2.0 | 5 votes |
public static void main(String[] args) { String rootPath = PathKit.getWebRootPath(); // base model 所使用的包名 String baseModelPackageName = "io."+PK_NAME+".model.base"; // base model 文件保存路径 String baseModelOutputDir = rootPath + "/src/main/java/io/"+PK_NAME+"/model/base"; // model 所使用的包名 (MappingKit 默认使用的包名) String modelPackageName = "io."+PK_NAME+".model"; // model 文件保存路径 (MappingKit 与 DataDictionary 文件默认保存路径) String modelOutputDir = baseModelOutputDir + "/.."; // 创建生成器 Generator gernerator = new Generator(getDataSource(), baseModelPackageName, baseModelOutputDir, modelPackageName, modelOutputDir); MetaBuilder mataBuilder = new MetaBuilder(getDataSource()); mataBuilder.addExcludedTable(excludedTable); gernerator.setMetaBuilder(mataBuilder); // 添加不需要生成的表名 // gernerator.addExcludedTable("order_coupon"); // 设置是否在 Model 中生成 dao 对象 gernerator.setGenerateDaoInModel(true); // 设置是否生成字典文件 gernerator.setGenerateDataDictionary(false); // 设置需要被移除的表名前缀用于生成modelName。例如表名 "osc_user",移除前缀 "osc_"后生成的model名为 "User"而非 OscUser gernerator.setRemovedTableNamePrefixes("tb_"); gernerator.generate(); //代码生成 _JFCodeGenerator.me.generate(); }
Example #3
Source File: CodeGenHelpler.java From jboot with Apache License 2.0 | 5 votes |
public static MetaBuilder createMetaBuilder() { MetaBuilder metaBuilder = new MetaBuilder(getDatasource()); metaBuilder.setGenerateRemarks(true); DataSourceConfig datasourceConfig = Jboot.config(DataSourceConfig.class, "jboot.datasource"); switch (datasourceConfig.getType()) { case DataSourceConfig.TYPE_MYSQL: metaBuilder.setDialect(new MysqlDialect()); break; case DataSourceConfig.TYPE_ORACLE: metaBuilder.setDialect(new OracleDialect()); break; case DataSourceConfig.TYPE_SQLSERVER: metaBuilder.setDialect(new SqlServerDialect()); break; case DataSourceConfig.TYPE_SQLITE: metaBuilder.setDialect(new Sqlite3Dialect()); break; case DataSourceConfig.TYPE_ANSISQL: metaBuilder.setDialect(new AnsiSqlDialect()); break; case DataSourceConfig.TYPE_POSTGRESQL: metaBuilder.setDialect(new PostgreSqlDialect()); break; default: throw new JbootIllegalConfigException("only support datasource type : mysql、orcale、sqlserver、sqlite、ansisql and postgresql, please check your jboot.properties. "); } return metaBuilder; }
Example #4
Source File: SystemGenerator.java From jpress with GNU Lesser General Public License v3.0 | 4 votes |
public static void main(String[] args) { String dbTables = "user,attachment,menu,option,payment_record,permission,role,utm," + "wechat_menu,wechat_reply," + "member,member_group,member_dist_amount,member_joined_record,member_price," + "user_address,user_amount,user_amount_statement,user_amount_payout," + "coupon,coupon_code,coupon_used_record," + "user_cart,user_order,user_order_item,user_order_delivery,user_order_invoice," + "user_openid,user_favorite,user_tag," + "payment_record"; String optionsTables = "coupon,member,member_group,product,product_category,user_address," + "user_amount_statement,user_amount_payout,user_cart,user_order,user_order_item,user_order_delivery,user_order_invoice," + "payment_record,user_openid,member_joined_record,user_favorite,user_tag"; JbootApplication.setBootArg("jboot.datasource.url", "jdbc:mysql://127.0.0.1:3306/jpress3"); JbootApplication.setBootArg("jboot.datasource.user", "root"); JbootApplication.setBootArg("jboot.datasource.password", "123456"); String modelPackage = "io.jpress.model"; String baseModelPackage = modelPackage + ".base"; String modelDir = PathKit.getWebRootPath() + "/../jpress-model/src/main/java/" + modelPackage.replace(".", "/"); String baseModelDir = PathKit.getWebRootPath() + "/../jpress-model/src/main/java/" + baseModelPackage.replace(".", "/"); System.out.println("start generate...dir:" + modelDir); Set<String> genTableNames = StrUtil.splitToSet(dbTables, ","); MetaBuilder metaBuilder = CodeGenHelpler.createMetaBuilder(); metaBuilder.setGenerateRemarks(true); List<TableMeta> tableMetas = metaBuilder.build(); tableMetas.removeIf(tableMeta -> genTableNames != null && !genTableNames.contains(tableMeta.name.toLowerCase())); new BaseModelGenerator(baseModelPackage, baseModelDir).generate(tableMetas); new ModelGenerator(modelPackage, baseModelPackage, modelDir).generate(tableMetas); String servicePackage = "io.jpress.service"; String apiPath = PathKit.getWebRootPath() + "/../jpress-service-api/src/main/java/" + servicePackage.replace(".", "/"); String providerPath = PathKit.getWebRootPath() + "/../jpress-service-provider/src/main/java/" + servicePackage.replace(".", "/") + "/provider"; new ServiceApiGenerator(servicePackage, modelPackage, apiPath).generate(tableMetas); new ServiceProviderGenerator(servicePackage, modelPackage, providerPath).generate(tableMetas); Set<String> optionsTableNames = StrUtil.splitToSet(optionsTables, ","); if (optionsTableNames != null && optionsTableNames.size() > 0) { tableMetas.removeIf(tableMeta -> !optionsTableNames.contains(tableMeta.name.toLowerCase())); new BaseOptionsModelGenerator(baseModelPackage, baseModelDir).generate(tableMetas); } }
Example #5
Source File: AddonGenerator.java From jpress with GNU Lesser General Public License v3.0 | 4 votes |
private void genCode() { JbootApplication.setBootArg("jboot.datasource.url", dbUrl); JbootApplication.setBootArg("jboot.datasource.user", dbUser); JbootApplication.setBootArg("jboot.datasource.password", dbPassword); String baseModelPackage = modelPackage + ".base"; String modelDir = basePath + "/src/main/java/" + modelPackage.replace(".", "/"); String baseModelDir = basePath + "/src/main/java/" + baseModelPackage.replace(".", "/"); System.out.println("start generate... dir:" + modelDir); MetaBuilder metaBuilder = CodeGenHelpler.createMetaBuilder(); metaBuilder.setGenerateRemarks(true); List<TableMeta> tableMetas = metaBuilder.build(); Set<String> genTableNames = StrUtil.splitToSet(dbTables, ","); tableMetas.removeIf(tableMeta -> genTableNames != null && !genTableNames.contains(tableMeta.name.toLowerCase())); new BaseModelGenerator(baseModelPackage, baseModelDir).generate(tableMetas); new ModelGenerator(modelPackage, baseModelPackage, modelDir).generate(tableMetas); String apiPath = basePath + "/src/main/java/" + servicePackage.replace(".", "/"); String providerPath = basePath + "/src/main/java/" + servicePackage.replace(".", "/") + "/provider"; new ServiceApiGenerator(servicePackage, modelPackage, apiPath).generate(tableMetas); new ServiceProviderGenerator(servicePackage, modelPackage, providerPath).generate(tableMetas); if (genUI) { new AddonUIGenerator(basePath, addonName, modelPackage, tableMetas) .genControllers() .genEdit() .genList(); } Set<String> optionsTableNames = StrUtil.splitToSet(optionsTables, ","); if (optionsTableNames != null && optionsTableNames.size() > 0) { tableMetas.removeIf(tableMeta -> !optionsTableNames.contains(tableMeta.name.toLowerCase())); new BaseOptionsModelGenerator(baseModelPackage, baseModelDir).generate(tableMetas); } }
Example #6
Source File: ModuleGenerator.java From jpress with GNU Lesser General Public License v3.0 | 2 votes |
private void genCode() { String modelModuleName = "/module-" + moduleName + "-model"; String serviceApiModuleName = "/module-" + moduleName + "-service-api"; String serviceProviderModuleName = "/module-" + moduleName + "-service-provider"; JbootApplication.setBootArg("jboot.datasource.url", dbUrl); JbootApplication.setBootArg("jboot.datasource.user", dbUser); JbootApplication.setBootArg("jboot.datasource.password", dbPassword); String baseModelPackage = modelPackage + ".base"; String modelDir = basePath + modelModuleName + "/src/main/java/" + modelPackage.replace(".", "/"); String baseModelDir = basePath + modelModuleName + "/src/main/java/" + baseModelPackage.replace(".", "/"); System.out.println("start generate... dir:" + modelDir); Set<String> genTableNames = StrUtil.splitToSet(dbTables, ","); MetaBuilder mb = CodeGenHelpler.createMetaBuilder(); mb.setGenerateRemarks(true); List<TableMeta> tableMetas = mb.build(); tableMetas.removeIf(tableMeta -> genTableNames != null && !genTableNames.contains(tableMeta.name.toLowerCase())); new BaseModelGenerator(baseModelPackage, baseModelDir).generate(tableMetas); new ModelGenerator(modelPackage, baseModelPackage, modelDir).generate(tableMetas); String apiPath = basePath + serviceApiModuleName + "/src/main/java/" + servicePackage.replace(".", "/"); String providerPath = basePath + serviceProviderModuleName + "/src/main/java/" + servicePackage.replace(".", "/") + "/provider"; new ServiceApiGenerator(servicePackage, modelPackage, apiPath).generate(tableMetas); new ServiceProviderGenerator(servicePackage, modelPackage, providerPath).generate(tableMetas); if (genUI) { new ModuleUIGenerator(moduleName, modelPackage, tableMetas).genListener().genControllers().genEdit().genList(); } Set<String> optionsTableNames = StrUtil.splitToSet(optionsTables, ","); if (optionsTableNames != null && optionsTableNames.size() > 0) { tableMetas.removeIf(tableMeta -> !optionsTableNames.contains(tableMeta.name.toLowerCase())); new BaseOptionsModelGenerator(baseModelPackage, baseModelDir).generate(tableMetas); } }