Search in sources :

Example 11 with CompilationUnit

use of org.mybatis.generator.api.dom.java.CompilationUnit in project generator by mybatis.

the class GenerateTestSourceFiles method run.

private void run(File outputDirectory) throws IOException, InstantiationException, IllegalAccessException {
    setupOutputDirectry(outputDirectory);
    List<CompilationUnitGenerator> generators = new ArrayList<CompilationUnitGenerator>();
    gatherGenerators(generators);
    List<CompilationUnit> cus = new ArrayList<CompilationUnit>();
    for (CompilationUnitGenerator generator : generators) {
        cus.addAll(generator.generate());
    }
    for (CompilationUnit cu : cus) {
        writeCompilationUnit(outputDirectory, cu);
    }
}
Also used : CompilationUnit(org.mybatis.generator.api.dom.java.CompilationUnit) ArrayList(java.util.ArrayList)

Example 12 with CompilationUnit

use of org.mybatis.generator.api.dom.java.CompilationUnit in project generator by mybatis.

the class Test1Generator method generate.

public List<CompilationUnit> generate() {
    FullyQualifiedJavaType cls = new FullyQualifiedJavaType(BASE_PACKAGE + ".SomeClass");
    List<CompilationUnit> answer = new ArrayList<CompilationUnit>();
    TopLevelClass tlcMain = generateFieldTypeMain();
    TopLevelClass tlcSub1 = generateFieldTypeSub1();
    TopLevelClass tlcTcSub1 = generateTestClassSub1();
    TopLevelClass tlcSub2 = generateFieldTypeSub2();
    answer.add(tlcMain);
    answer.add(tlcSub1);
    answer.add(tlcTcSub1);
    answer.add(tlcSub2);
    TopLevelClass topLvlClass = new TopLevelClass(cls);
    topLvlClass.setVisibility(JavaVisibility.PUBLIC);
    topLvlClass.addImportedType(tlcTcSub1.getType());
    Field field = new Field("main", tlcMain.getType());
    field.setVisibility(JavaVisibility.PRIVATE);
    topLvlClass.addField(field);
    field = new Field("tcSub1", tlcTcSub1.getType());
    field.setVisibility(JavaVisibility.PRIVATE);
    topLvlClass.addField(field);
    field = new Field("sub1", tlcSub1.getType());
    field.setVisibility(JavaVisibility.PRIVATE);
    topLvlClass.addField(field);
    field = new Field("sub2", tlcSub2.getType());
    field.setVisibility(JavaVisibility.PRIVATE);
    topLvlClass.addField(field);
    Method m = new Method();
    m.setVisibility(JavaVisibility.PUBLIC);
    m.setName("executeMain");
    m.addBodyLine("main.mainMethod();");
    topLvlClass.addMethod(m);
    m = new Method();
    m.setVisibility(JavaVisibility.PUBLIC);
    m.setName("setMain");
    m.addParameter(new Parameter(tlcMain.getType(), "main"));
    m.addBodyLine("this.main = main;");
    topLvlClass.addMethod(m);
    m = new Method();
    m.setVisibility(JavaVisibility.PUBLIC);
    m.setName("getMain");
    m.setReturnType(tlcMain.getType());
    m.addBodyLine("return main;");
    topLvlClass.addMethod(m);
    m = new Method();
    m.setVisibility(JavaVisibility.PUBLIC);
    m.setName("executeSub1");
    m.addBodyLine("sub1.sub1Method();");
    topLvlClass.addMethod(m);
    m = new Method();
    m.setVisibility(JavaVisibility.PUBLIC);
    m.setName("setSub1");
    m.addParameter(new Parameter(tlcSub1.getType(), "sub1"));
    m.addBodyLine("this.sub1 = sub1;");
    topLvlClass.addMethod(m);
    m = new Method();
    m.setVisibility(JavaVisibility.PUBLIC);
    m.setName("getSub1");
    m.setReturnType(tlcSub1.getType());
    m.addBodyLine("return sub1;");
    topLvlClass.addMethod(m);
    m = new Method();
    m.setVisibility(JavaVisibility.PUBLIC);
    m.setName("executeSub2");
    m.addBodyLine("sub2.sub2Method();");
    topLvlClass.addMethod(m);
    m = new Method();
    m.setVisibility(JavaVisibility.PUBLIC);
    m.setName("setSub2");
    m.addParameter(new Parameter(tlcSub2.getType(), "sub2"));
    m.addBodyLine("this.sub2 = sub2;");
    topLvlClass.addMethod(m);
    m = new Method();
    m.setVisibility(JavaVisibility.PUBLIC);
    m.setName("getSub2");
    m.setReturnType(tlcSub2.getType());
    m.addBodyLine("return sub2;");
    topLvlClass.addMethod(m);
    answer.add(topLvlClass);
    return answer;
}
Also used : CompilationUnit(org.mybatis.generator.api.dom.java.CompilationUnit) Field(org.mybatis.generator.api.dom.java.Field) FullyQualifiedJavaType(org.mybatis.generator.api.dom.java.FullyQualifiedJavaType) TopLevelClass(org.mybatis.generator.api.dom.java.TopLevelClass) ArrayList(java.util.ArrayList) Parameter(org.mybatis.generator.api.dom.java.Parameter) Method(org.mybatis.generator.api.dom.java.Method)

Example 13 with CompilationUnit

use of org.mybatis.generator.api.dom.java.CompilationUnit in project generator by mybatis.

the class SimpleInterfaceGenerator method generate.

@Override
public List<CompilationUnit> generate() {
    List<CompilationUnit> answer = new ArrayList<CompilationUnit>();
    Interface interfaze = generateInterface();
    answer.add(interfaze);
    answer.add(generateClass(interfaze));
    return answer;
}
Also used : CompilationUnit(org.mybatis.generator.api.dom.java.CompilationUnit) ArrayList(java.util.ArrayList) Interface(org.mybatis.generator.api.dom.java.Interface)

Example 14 with CompilationUnit

use of org.mybatis.generator.api.dom.java.CompilationUnit in project generator by mybatis.

the class JavaMapperGenerator method getCompilationUnits.

@Override
public List<CompilationUnit> getCompilationUnits() {
    progressCallback.startTask(getString(//$NON-NLS-1$
    "Progress.17", introspectedTable.getFullyQualifiedTable().toString()));
    CommentGenerator commentGenerator = context.getCommentGenerator();
    FullyQualifiedJavaType type = new FullyQualifiedJavaType(introspectedTable.getMyBatis3JavaMapperType());
    Interface interfaze = new Interface(type);
    interfaze.setVisibility(JavaVisibility.PUBLIC);
    commentGenerator.addJavaFileComment(interfaze);
    String rootInterface = introspectedTable.getTableConfigurationProperty(PropertyRegistry.ANY_ROOT_INTERFACE);
    if (!stringHasValue(rootInterface)) {
        rootInterface = context.getJavaClientGeneratorConfiguration().getProperty(PropertyRegistry.ANY_ROOT_INTERFACE);
    }
    if (stringHasValue(rootInterface)) {
        FullyQualifiedJavaType fqjt = new FullyQualifiedJavaType(rootInterface);
        interfaze.addSuperInterface(fqjt);
        interfaze.addImportedType(fqjt);
    }
    addCountByExampleMethod(interfaze);
    addDeleteByExampleMethod(interfaze);
    addDeleteByPrimaryKeyMethod(interfaze);
    addInsertMethod(interfaze);
    addInsertSelectiveMethod(interfaze);
    addSelectByExampleWithBLOBsMethod(interfaze);
    addSelectByExampleWithoutBLOBsMethod(interfaze);
    addSelectByPrimaryKeyMethod(interfaze);
    addUpdateByExampleSelectiveMethod(interfaze);
    addUpdateByExampleWithBLOBsMethod(interfaze);
    addUpdateByExampleWithoutBLOBsMethod(interfaze);
    addUpdateByPrimaryKeySelectiveMethod(interfaze);
    addUpdateByPrimaryKeyWithBLOBsMethod(interfaze);
    addUpdateByPrimaryKeyWithoutBLOBsMethod(interfaze);
    List<CompilationUnit> answer = new ArrayList<CompilationUnit>();
    if (context.getPlugins().clientGenerated(interfaze, null, introspectedTable)) {
        answer.add(interfaze);
    }
    List<CompilationUnit> extraCompilationUnits = getExtraCompilationUnits();
    if (extraCompilationUnits != null) {
        answer.addAll(extraCompilationUnits);
    }
    return answer;
}
Also used : CompilationUnit(org.mybatis.generator.api.dom.java.CompilationUnit) CommentGenerator(org.mybatis.generator.api.CommentGenerator) FullyQualifiedJavaType(org.mybatis.generator.api.dom.java.FullyQualifiedJavaType) ArrayList(java.util.ArrayList) Messages.getString(org.mybatis.generator.internal.util.messages.Messages.getString) Interface(org.mybatis.generator.api.dom.java.Interface)

Example 15 with CompilationUnit

use of org.mybatis.generator.api.dom.java.CompilationUnit in project generator by mybatis.

the class IntrospectedTableIbatis2Java2Impl method getGeneratedJavaFiles.

@Override
public List<GeneratedJavaFile> getGeneratedJavaFiles() {
    List<GeneratedJavaFile> answer = new ArrayList<GeneratedJavaFile>();
    for (AbstractJavaGenerator javaGenerator : javaModelGenerators) {
        List<CompilationUnit> compilationUnits = javaGenerator.getCompilationUnits();
        for (CompilationUnit compilationUnit : compilationUnits) {
            GeneratedJavaFile gjf = new GeneratedJavaFile(compilationUnit, context.getJavaModelGeneratorConfiguration().getTargetProject(), context.getProperty(PropertyRegistry.CONTEXT_JAVA_FILE_ENCODING), context.getJavaFormatter());
            answer.add(gjf);
        }
    }
    for (AbstractJavaGenerator javaGenerator : daoGenerators) {
        List<CompilationUnit> compilationUnits = javaGenerator.getCompilationUnits();
        for (CompilationUnit compilationUnit : compilationUnits) {
            GeneratedJavaFile gjf = new GeneratedJavaFile(compilationUnit, context.getJavaClientGeneratorConfiguration().getTargetProject(), context.getProperty(PropertyRegistry.CONTEXT_JAVA_FILE_ENCODING), context.getJavaFormatter());
            answer.add(gjf);
        }
    }
    return answer;
}
Also used : CompilationUnit(org.mybatis.generator.api.dom.java.CompilationUnit) AbstractJavaGenerator(org.mybatis.generator.codegen.AbstractJavaGenerator) ArrayList(java.util.ArrayList) GeneratedJavaFile(org.mybatis.generator.api.GeneratedJavaFile)

Aggregations

ArrayList (java.util.ArrayList)19 CompilationUnit (org.mybatis.generator.api.dom.java.CompilationUnit)19 TopLevelClass (org.mybatis.generator.api.dom.java.TopLevelClass)13 CommentGenerator (org.mybatis.generator.api.CommentGenerator)12 FullyQualifiedJavaType (org.mybatis.generator.api.dom.java.FullyQualifiedJavaType)11 FullyQualifiedTable (org.mybatis.generator.api.FullyQualifiedTable)10 Field (org.mybatis.generator.api.dom.java.Field)10 Method (org.mybatis.generator.api.dom.java.Method)10 Messages.getString (org.mybatis.generator.internal.util.messages.Messages.getString)9 IntrospectedColumn (org.mybatis.generator.api.IntrospectedColumn)7 Plugin (org.mybatis.generator.api.Plugin)7 JavaBeansUtil.getJavaBeansField (org.mybatis.generator.internal.util.JavaBeansUtil.getJavaBeansField)7 Interface (org.mybatis.generator.api.dom.java.Interface)5 Parameter (org.mybatis.generator.api.dom.java.Parameter)3 GeneratedJavaFile (org.mybatis.generator.api.GeneratedJavaFile)2 AbstractJavaGenerator (org.mybatis.generator.codegen.AbstractJavaGenerator)2 Rules (org.mybatis.generator.internal.rules.Rules)1