com.jfinal.plugin.activerecord.generator.TableMeta Java Examples

The following examples show how to use com.jfinal.plugin.activerecord.generator.TableMeta. 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: AppJbootServiceImplGenerator.java    From jboot-admin with Apache License 2.0 6 votes vote down vote up
@Override
public void generate(List<TableMeta> tableMetas) {
    System.out.println("Generate base model ...");
    System.out.println("Base Model Output Dir: " + baseModelOutputDir);

    Engine engine = Engine.create("forServiceImpl");
    engine.setSourceFactory(new ClassPathSourceFactory());
    engine.addSharedMethod(new StrKit());
    engine.addSharedObject("getterTypeMap", getterTypeMap);
    engine.addSharedObject("javaKeyword", javaKeyword);

    for (TableMeta tableMeta : tableMetas) {
        genBaseModelContent(tableMeta);
    }
    writeToFile(tableMetas);
}
 
Example #2
Source File: ServiceProviderGenerator.java    From jpress with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * base model 覆盖写入
 */
@Override
protected void writeToFile(TableMeta tableMeta) throws IOException {
    File dir = new File(baseModelOutputDir);
    if (!dir.exists()) {
        dir.mkdirs();
    }

    String target = baseModelOutputDir + File.separator + tableMeta.modelName + "ServiceProvider" + ".java";

    File targetFile = new File(target);
    if (targetFile.exists()) {
        return;
    }


    FileWriter fw = new FileWriter(target);
    try {
        fw.write(tableMeta.baseModelContent);
    } finally {
        fw.close();
    }
}
 
Example #3
Source File: ServiceProviderGenerator.java    From jpress with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void generate(List<TableMeta> tableMetas) {
    System.out.println("Generate base model ...");
    System.out.println("Base Model Output Dir: " + baseModelOutputDir);

    Engine engine = Engine.create("forServiceImpl");
    engine.setSourceFactory(new ClassPathSourceFactory());
    engine.addSharedMethod(new StrKit());
    engine.addSharedObject("getterTypeMap", getterTypeMap);
    engine.addSharedObject("javaKeyword", javaKeyword);

    for (TableMeta tableMeta : tableMetas) {
        genBaseModelContent(tableMeta);
    }
    writeToFile(tableMetas);
}
 
Example #4
Source File: ServiceApiGenerator.java    From jpress with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * base model 覆盖写入
 */
@Override
protected void writeToFile(TableMeta tableMeta) throws IOException {
    File dir = new File(baseModelOutputDir);
    if (!dir.exists()) {
        dir.mkdirs();
    }

    String target = baseModelOutputDir + File.separator + tableMeta.modelName + "Service" + ".java";

    File targetFile = new File(target);
    if (targetFile.exists()) {
        return;
    }

    FileWriter fw = new FileWriter(target);
    try {
        fw.write(tableMeta.baseModelContent);
    } finally {
        fw.close();
    }
}
 
Example #5
Source File: ServiceApiGenerator.java    From jpress with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void generate(List<TableMeta> tableMetas) {
    System.out.println("Generate base model ...");
    System.out.println("Base Model Output Dir: " + baseModelOutputDir);

    Engine engine = Engine.create("forService");
    engine.setSourceFactory(new ClassPathSourceFactory());
    engine.addSharedMethod(new StrKit());
    engine.addSharedObject("getterTypeMap", getterTypeMap);
    engine.addSharedObject("javaKeyword", javaKeyword);

    for (TableMeta tableMeta : tableMetas) {
        genBaseModelContent(tableMeta);
    }
    writeToFile(tableMetas);
}
 
Example #6
Source File: JbootServiceInterfaceGenerator.java    From jboot with Apache License 2.0 6 votes vote down vote up
/**
 * base model 覆盖写入
 */
@Override
protected void writeToFile(TableMeta tableMeta) throws IOException {
    File dir = new File(baseModelOutputDir);
    if (!dir.exists()) {
        dir.mkdirs();
    }

    String target = baseModelOutputDir + File.separator + tableMeta.modelName + "Service" + ".java";

    File targetFile = new File(target);
    if (targetFile.exists()) {
        return;
    }

    FileWriter fw = new FileWriter(target);
    try {
        fw.write(tableMeta.baseModelContent);
    } finally {
        fw.close();
    }
}
 
Example #7
Source File: JbootServiceInterfaceGenerator.java    From jboot with Apache License 2.0 6 votes vote down vote up
@Override
public void generate(List<TableMeta> tableMetas) {
    System.out.println("Generate base model ...");
    System.out.println("Base Model Output Dir: " + baseModelOutputDir);

    Engine engine = Engine.create("forService");
    engine.setSourceFactory(new ClassPathSourceFactory());
    engine.addSharedMethod(new StrKit());
    engine.addSharedObject("getterTypeMap", getterTypeMap);
    engine.addSharedObject("javaKeyword", javaKeyword);

    for (TableMeta tableMeta : tableMetas) {
        genBaseModelContent(tableMeta);
    }
    writeToFile(tableMetas);
}
 
Example #8
Source File: JbootServiceImplGenerator.java    From jboot with Apache License 2.0 6 votes vote down vote up
/**
 * base model 覆盖写入
 */
protected void writeToFile(TableMeta tableMeta) throws IOException {
    File dir = new File(outputDir);
    if (!dir.exists()) {
        dir.mkdirs();
    }

    String target =outputDir + File.separator + tableMeta.modelName + "Service" + StrKit.firstCharToUpperCase(implName) + ".java";

    File targetFile = new File(target);
    if (targetFile.exists()) {
        return;
    }


    FileWriter fw = new FileWriter(target);
    try {
        fw.write(tableMeta.baseModelContent);
    } finally {
        fw.close();
    }
}
 
Example #9
Source File: _JFCodeGenerator.java    From sdb-mall with Apache License 2.0 6 votes vote down vote up
public void generate(){
    DataSource dataSource = _JFinalGenerator.getDataSource();

    MyMetaBuilder metaBuilder = new MyMetaBuilder(dataSource);
    metaBuilder.setDialect(new MysqlDialect());
    metaBuilder.addExcludedTable(_JFinalGenerator.excludedTable);
    List<TableMeta> tableMetas = metaBuilder.build();
    for (TableMeta tableMeta : tableMetas
            ) {
        if (serviceGenerate) {
            _JFCodeGenerator.me.service(tableMeta.modelName, tableMeta.name);
            _JFCodeGenerator.me.serviceImpl(tableMeta.modelName, tableMeta.name);
            _JFCodeGenerator.me.dao(tableMeta.modelName, tableMeta.name);
            _JFCodeGenerator.me.controller(tableMeta.modelName);
            _JFCodeGenerator.me.vue(tableMeta.modelName, tableMeta);
            _JFCodeGenerator.me.vueAddUpdate(tableMeta.modelName, tableMeta);
        }
    }
}
 
Example #10
Source File: AppJbootServiceImplGenerator.java    From jboot-admin with Apache License 2.0 6 votes vote down vote up
/**
 * base model 覆盖写入
 */
@Override
protected void writeToFile(TableMeta tableMeta) throws IOException {
    File dir = new File(baseModelOutputDir);
    if (!dir.exists()) {
        dir.mkdirs();
    }

    String target = baseModelOutputDir + File.separator + tableMeta.modelName + "ServiceImpl" + ".java";

    File targetFile = new File(target);
    if (targetFile.exists()) {
        return;
    }


    FileWriter fw = new FileWriter(target);
    try {
        fw.write(tableMeta.baseModelContent);
    } finally {
        fw.close();
    }
}
 
Example #11
Source File: _JFCodeGenerator.java    From sdb-mall with Apache License 2.0 6 votes vote down vote up
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 #12
Source File: ServiceProviderGenerator.java    From jpress with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
protected void genBaseModelContent(TableMeta tableMeta) {
    Kv data = Kv.by("serviceImplPackageName", baseModelPackageName);
    data.set("generateChainSetter", generateChainSetter);
    data.set("tableMeta", tableMeta);
    data.set("basePackage", basePackage);
    data.set("modelPackage", modelPackage);

    Engine engine = Engine.use("forServiceImpl");
    tableMeta.baseModelContent = engine.getTemplate(template).renderToString(data);
}
 
Example #13
Source File: ServiceApiGenerator.java    From jpress with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
protected void genBaseModelContent(TableMeta tableMeta) {
    Kv data = Kv.by("baseModelPackageName", baseModelPackageName);
    data.set("generateChainSetter", generateChainSetter);
    data.set("tableMeta", tableMeta);
    data.set("modelPacket", modelPacket);
    data.set("basePackage", basePackage);

    Engine engine = Engine.use("forService");
    tableMeta.baseModelContent = engine.getTemplate(template).renderToString(data);
}
 
Example #14
Source File: ModuleUIGenerator.java    From jpress with GNU Lesser General Public License v3.0 5 votes vote down vote up
public ModuleUIGenerator(String moduleName, String modelPackage, List<TableMeta> tableMetaList) {

        this.tableMetaList = tableMetaList;
        this.moduleName = moduleName;
        this.modelPackage = modelPackage;
        modulePackage = modelPackage.substring(0, modelPackage.lastIndexOf("."));

        basePath = PathKit.getWebRootPath() + "/../module-" + moduleName;
        webPath = basePath + "/module-" + moduleName + "-web";

        String upcasedModuleName = StrKit.firstCharToUpperCase(moduleName);

        String moduleListenerPakcage = modelPackage.substring(0, modelPackage.lastIndexOf("."));
        String controllerPackage = modelPackage.substring(0, modelPackage.lastIndexOf(".")) + ".controller";


        moduleListenerOutputDir = webPath + "/src/main/java/" + moduleListenerPakcage.replace(".", "/");
        controllerOutputDir = webPath + "/src/main/java/" + controllerPackage.replace(".", "/");
        htmlOutputDir = webPath + "/src/main/webapp/WEB-INF/views/admin/" + moduleName;

        data = Kv.by("moduleName", moduleName);//product
        data.set("upcasedModuleName", upcasedModuleName);//Product
        data.set("modulePackage", modulePackage);//io.jpress.module.product
        data.set("modelPackage", modelPackage);//io.jpress.module.product.model
        data.set("moduleListenerPakcage", moduleListenerPakcage);//io.jpress.module.product
        data.set("controllerPackage", controllerPackage);//io.jpress.module.product.controller

        engine.setSourceFactory(new ClassPathSourceFactory());
        engine.addSharedMethod(new StrKit());

    }
 
Example #15
Source File: AppJbootServiceImplGenerator.java    From jboot-admin with Apache License 2.0 5 votes vote down vote up
@Override
protected void genBaseModelContent(TableMeta tableMeta) {
    Kv data = Kv.by("serviceImplPackageName", baseModelPackageName);
    data.set("generateChainSetter", generateChainSetter);
    data.set("tableMeta", tableMeta);
    data.set("basePackage", servicePackage);
    data.set("modelPackage", modelPacket);

    Engine engine = Engine.use("forServiceImpl");
    tableMeta.baseModelContent = engine.getTemplate(template).renderToString(data);
}
 
Example #16
Source File: AddonUIGenerator.java    From jpress with GNU Lesser General Public License v3.0 5 votes vote down vote up
public AddonUIGenerator(String basePath, String moduleName, String modelPackage, List<TableMeta> tableMetaList) {

        this.basePath = basePath;

        this.tableMetaList = tableMetaList;
        this.moduleName = moduleName;
        this.modelPackage = modelPackage;
        this.modulePackage = modelPackage.substring(0, modelPackage.lastIndexOf("."));

        modulePackage = modelPackage.substring(0, modelPackage.lastIndexOf("."));

        String moduleListenerPakcage = modelPackage.substring(0, modelPackage.lastIndexOf("."));
        String controllerPackage = modelPackage.substring(0, modelPackage.lastIndexOf(".")) + ".controller";


        controllerOutputDir = basePath + "/src/main/java/" + controllerPackage.replace(".", "/");
        htmlOutputDir = basePath + "/src/main/webapp/views/";

        data = Kv.by("moduleName", moduleName);//product
        data.set("upcasedModuleName", StrKit.firstCharToUpperCase(moduleName));//Product
        data.set("modulePackage", modulePackage);//io.jpress.module.product
        data.set("modelPackage", modelPackage);//io.jpress.module.product.model
        data.set("moduleListenerPakcage", moduleListenerPakcage);//io.jpress.module.product
        data.set("controllerPackage", controllerPackage);//io.jpress.module.product.controller

        engine.setSourceFactory(new ClassPathSourceFactory());
        engine.addSharedMethod(new StrKit());

    }
 
Example #17
Source File: AppMetaBuilder.java    From jboot-admin with Apache License 2.0 5 votes vote down vote up
@Override
protected void buildPrimaryKey(TableMeta tableMeta) throws SQLException {
    if (tableMeta.name.toLowerCase().endsWith("_view")) {
        tableMeta.primaryKey = "id";
    } else {
        super.buildPrimaryKey(tableMeta);
    }
}
 
Example #18
Source File: JbootServiceInterfaceGenerator.java    From jboot with Apache License 2.0 5 votes vote down vote up
@Override
protected void genBaseModelContent(TableMeta tableMeta) {
    Kv data = Kv.by("baseModelPackageName", baseModelPackageName);
    data.set("generateChainSetter", generateChainSetter);
    data.set("tableMeta", tableMeta);
    data.set("modelPacket", modelPacket);
    data.set("basePackage", basePackage);

    Engine engine = Engine.use("forService");
    tableMeta.baseModelContent = engine.getTemplate(template).renderToString(data);
}
 
Example #19
Source File: JbootServiceImplGenerator.java    From jboot with Apache License 2.0 5 votes vote down vote up
protected void writeToFile(List<TableMeta> tableMetas) {
    try {
        for (TableMeta tableMeta : tableMetas) {
            writeToFile(tableMeta);
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
 
Example #20
Source File: JbootServiceImplGenerator.java    From jboot with Apache License 2.0 5 votes vote down vote up
protected void genBaseModelContent(TableMeta tableMeta) {
        Kv data = Kv.by("serviceImplPackageName", basePackage + "." + implName);
//        data.set("generateChainSetter", generateChainSetter);
        data.set("tableMeta", tableMeta);
        data.set("basePackage", basePackage);
        data.set("modelPackage", modelPackage);
        data.set("implName", implName);

        Engine engine = Engine.use("forServiceImpl");
        tableMeta.baseModelContent = engine.getTemplate(template).renderToString(data);
    }
 
Example #21
Source File: JbootServiceImplGenerator.java    From jboot with Apache License 2.0 5 votes vote down vote up
public void generate(List<TableMeta> tableMetas) {
    System.out.println("Generate Service Impl ...");
    System.out.println("Service Impl Output Dir: " + outputDir);

    Engine engine = Engine.create("forServiceImpl");
    engine.setSourceFactory(new ClassPathSourceFactory());
    engine.addSharedMethod(new StrKit());
    engine.addSharedObject("getterTypeMap", getterTypeMap);
    engine.addSharedObject("javaKeyword", JavaKeyword.me);

    for (TableMeta tableMeta : tableMetas) {
        genBaseModelContent(tableMeta);
    }
    writeToFile(tableMetas);
}
 
Example #22
Source File: _JFCodeGenerator.java    From sdb-mall with Apache License 2.0 5 votes vote down vote up
/**
 * @param className
 * @param tableName
 */
public _JFCodeGenerator htmlRender(String className, String tableName) {
    TableMeta tablemeta = getTableMeta(tableName);

    htmlList(className, tablemeta);

    return this;
}
 
Example #23
Source File: _JFCodeGenerator.java    From sdb-mall with Apache License 2.0 5 votes vote down vote up
public void htmlList(String className, TableMeta tablemeta) {
    String packages = toPackages();
    String classNameSmall = toClassNameSmall(className);
    String basePathUrl = basePath.replace('.', '/');

    Map<String, String> columnMap = new HashMap<>();

    for (ColumnMeta columnMeta :tablemeta.columnMetas
         ) {

        String desc = StringUtils.substringBetween(columnMeta.remarks, "[", "]");
        columnMap.put(columnMeta.attrName, desc);
    }

    String primaryKey = StrKit.toCamelCase(tablemeta.primaryKey);

    jfEngine.render("/html/index.vue",
            Kv.by("tablemeta", tablemeta)
                    .set("package", packages)
                    .set("className", className)
                    .set("columnMap", columnMap)
                    .set("primaryKey", primaryKey)
                    .set("classNameSmall", classNameSmall)
                    .set("basePath", basePathUrl)
            ,
            new StringBuilder()
                    .append(viewFolder)
                    .append("/")
                    .append(classNameSmall)
                    .append("List.html")
    );
}
 
Example #24
Source File: AddonGenerator.java    From jpress with GNU Lesser General Public License v3.0 4 votes vote down vote up
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 #25
Source File: AppServiceImplGenerator.java    From jboot-admin with Apache License 2.0 4 votes vote down vote up
public static void doGenerate() {
    AppServiceImplGeneratorConfig config = Jboot.config(AppServiceImplGeneratorConfig.class);

    System.out.println(config.toString());

    if (StrKit.isBlank(config.getModelpackage())) {
        System.err.println("jboot.admin.serviceimpl.ge.modelpackage 不可为空");
        System.exit(0);
    }

    if (StrKit.isBlank(config.getServicepackage())) {
        System.err.println("jboot.admin.serviceimpl.ge.servicepackage 不可为空");
        System.exit(0);
    }

    if (StrKit.isBlank(config.getServiceimplpackage())) {
        System.err.println("jboot.admin.serviceimpl.ge.serviceimplpackage 不可为空");
        System.exit(0);
    }

    String modelPackage = config.getModelpackage();
    String servicepackage = config.getServicepackage();
    String serviceimplpackage = config.getServiceimplpackage();

    System.out.println("start generate...");
    System.out.println("generate dir:" + servicepackage);

    DataSource dataSource = CodeGenHelpler.getDatasource();

    AppMetaBuilder metaBuilder = new AppMetaBuilder(dataSource);

    if (StrKit.notBlank(config.getRemovedtablenameprefixes())) {
        metaBuilder.setRemovedTableNamePrefixes(config.getRemovedtablenameprefixes().split(","));
    }

    if (StrKit.notBlank(config.getExcludedtableprefixes())) {
        metaBuilder.setSkipPre(config.getExcludedtableprefixes().split(","));
    }

    List<TableMeta> tableMetaList = metaBuilder.build();
    CodeGenHelpler.excludeTables(tableMetaList, config.getExcludedtable());

    new AppJbootServiceImplGenerator(servicepackage , modelPackage, serviceimplpackage).generate(tableMetaList);

    System.out.println("service generate finished !!!");

}
 
Example #26
Source File: ModuleUIGenerator.java    From jpress with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void generate(int genType) {

        String targetOutputDir = "";
        if (ModuleUIGenerator.UI_MODULELISTENER == genType) {
            targetTemplate = templatesDir + templates[0];
            targetOutputDir = moduleListenerOutputDir;
            targetOutputDirFile = targetOutputDir + File.separator + StrKit.firstCharToUpperCase(moduleName) + "ModuleInitializer" + ".java";
        }

        for (TableMeta tableMeta : tableMetaList) {
            data.set("tableMeta", tableMeta);
            String lowerCaseModelName = StrKit.firstCharToLowerCase(tableMeta.modelName);
            data.set("lowerCaseModelName", lowerCaseModelName);

            if (ModuleUIGenerator.UI_CONTROLLER == genType) {
                targetTemplate = templatesDir + templates[1];
                targetOutputDir = controllerOutputDir;
                targetOutputDirFile = targetOutputDir + File.separator + "_" + tableMeta.modelName + "Controller" + ".java";
            }

            if (ModuleUIGenerator.UI_EDIT == genType) {
                targetTemplate = templatesDir + templates[2];
                targetOutputDir = htmlOutputDir;
                targetOutputDirFile = targetOutputDir + File.separator + tableMeta.name + "_edit.html";
            }
            if (ModuleUIGenerator.UI_LIST == genType) {
                targetTemplate = templatesDir + templates[3];
                targetOutputDir = htmlOutputDir;
                targetOutputDirFile = targetOutputDir + File.separator + tableMeta.name + "_list.html";
            }
            // tableMeta.columnMetas.get(0).remarks
            String content = engine.getTemplate(targetTemplate).renderToString(data);

            //
            File dir = new File(targetOutputDir);
            if (!dir.exists()) {
                dir.mkdirs();
            }
            File targetFile = new File(targetOutputDirFile);
            if (targetFile.exists()) {
                return;
            }
            try {
                FileWriter fw = new FileWriter(targetOutputDirFile);
                try {
                    fw.write(content);
                } finally {
                    fw.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
 
Example #27
Source File: SystemGenerator.java    From jpress with GNU Lesser General Public License v3.0 4 votes vote down vote up
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 #28
Source File: AddonUIGenerator.java    From jpress with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void generate(int genType) {

        String targetOutputDir = "";

        for (TableMeta tableMeta : tableMetaList) {
            data.set("tableMeta", tableMeta);
            String lowerCaseModelName = StrKit.firstCharToLowerCase(tableMeta.modelName);
            data.set("lowerCaseModelName", lowerCaseModelName);

            if (AddonUIGenerator.UI_CONTROLLER == genType) {
                targetTemplate = templatesDir + templates[0];
                targetOutputDir = controllerOutputDir;
                targetOutputDirFile = targetOutputDir + File.separator + "_" + tableMeta.modelName + "Controller" + ".java";
            }

            if (AddonUIGenerator.UI_EDIT == genType) {
                targetTemplate = templatesDir + templates[1];
                targetOutputDir = htmlOutputDir;
                targetOutputDirFile = targetOutputDir + File.separator + tableMeta.name + "_edit.html";
            }
            if (AddonUIGenerator.UI_LIST == genType) {
                targetTemplate = templatesDir + templates[2];
                targetOutputDir = htmlOutputDir;
                targetOutputDirFile = targetOutputDir + File.separator + tableMeta.name + "_list.html";
            }
            // tableMeta.columnMetas.get(0).remarks
            String content = engine.getTemplate(targetTemplate).renderToString(data);

            //
            File dir = new File(targetOutputDir);
            if (!dir.exists()) {
                dir.mkdirs();
            }
            File targetFile = new File(targetOutputDirFile);
            if (targetFile.exists()) {
                return;
            }
            try {
                FileWriter fw = new FileWriter(targetOutputDirFile);
                try {
                    fw.write(content);
                } finally {
                    fw.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
 
Example #29
Source File: AppServiceGenerator.java    From jboot-admin with Apache License 2.0 4 votes vote down vote up
public static void doGenerate() {
    AppServiceGeneratorConfig config = Jboot.config(AppServiceGeneratorConfig.class);

    System.out.println(config.toString());

    if (StrKit.isBlank(config.getModelpackage())) {
        System.err.println("jboot.admin.service.ge.modelpackage 不可为空");
        System.exit(0);
    }

    if (StrKit.isBlank(config.getServicepackage())) {
        System.err.println("jboot.admin.service.ge.servicepackage 不可为空");
        System.exit(0);
    }

    String modelPackage = config.getModelpackage();
    String servicepackage = config.getServicepackage();

    System.out.println("start generate...");
    System.out.println("generate dir:" + servicepackage);

    DataSource dataSource = CodeGenHelpler.getDatasource();

    AppMetaBuilder metaBuilder = new AppMetaBuilder(dataSource);

    if (StrKit.notBlank(config.getRemovedtablenameprefixes())) {
        metaBuilder.setRemovedTableNamePrefixes(config.getRemovedtablenameprefixes().split(","));
    }

    if (StrKit.notBlank(config.getExcludedtableprefixes())) {
        metaBuilder.setSkipPre(config.getExcludedtableprefixes().split(","));
    }

    List<TableMeta> tableMetaList = metaBuilder.build();
    CodeGenHelpler.excludeTables(tableMetaList, config.getExcludedtable());

    new JbootServiceInterfaceGenerator(servicepackage, modelPackage).generate(tableMetaList);

    System.out.println("service generate finished !!!");

}
 
Example #30
Source File: _JFCodeGenerator.java    From sdb-mall with Apache License 2.0 4 votes vote down vote up
public void rebuildColumnMetas(List<TableMeta> tableMetas) {
    super.rebuildColumnMetas(tableMetas);
}