Search in sources :

Example 21 with TopLevelClass

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

the class Test1Generator method generateTestClassSub1.

private TopLevelClass generateTestClassSub1() {
    FullyQualifiedJavaType fqjt = new FullyQualifiedJavaType(BASE_PACKAGE + ".sub1.SomeClass");
    TopLevelClass tlc = new TopLevelClass(fqjt);
    tlc.setVisibility(JavaVisibility.PUBLIC);
    Method m = new Method();
    m.setVisibility(JavaVisibility.PUBLIC);
    m.setName("testClassMethod");
    m.addBodyLine("System.out.println(\"testClass sub1 method\");");
    tlc.addMethod(m);
    return tlc;
}
Also used : FullyQualifiedJavaType(org.mybatis.generator.api.dom.java.FullyQualifiedJavaType) TopLevelClass(org.mybatis.generator.api.dom.java.TopLevelClass) Method(org.mybatis.generator.api.dom.java.Method)

Example 22 with TopLevelClass

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

the class DAOGenerator method getTopLevelClassShell.

protected TopLevelClass getTopLevelClassShell() {
    FullyQualifiedJavaType interfaceType = new FullyQualifiedJavaType(introspectedTable.getDAOInterfaceType());
    FullyQualifiedJavaType implementationType = new FullyQualifiedJavaType(introspectedTable.getDAOImplementationType());
    CommentGenerator commentGenerator = context.getCommentGenerator();
    TopLevelClass answer = new TopLevelClass(implementationType);
    answer.setVisibility(JavaVisibility.PUBLIC);
    answer.setSuperClass(daoTemplate.getSuperClass());
    answer.addImportedType(daoTemplate.getSuperClass());
    answer.addSuperInterface(interfaceType);
    answer.addImportedType(interfaceType);
    for (FullyQualifiedJavaType fqjt : daoTemplate.getImplementationImports()) {
        answer.addImportedType(fqjt);
    }
    commentGenerator.addJavaFileComment(answer);
    // add constructor from the template
    answer.addMethod(daoTemplate.getConstructorClone(commentGenerator, implementationType, introspectedTable));
    // add any fields from the template
    for (Field field : daoTemplate.getFieldClones(commentGenerator, introspectedTable)) {
        answer.addField(field);
    }
    // add any methods from the template
    for (Method method : daoTemplate.getMethodClones(commentGenerator, introspectedTable)) {
        answer.addMethod(method);
    }
    return answer;
}
Also used : Field(org.mybatis.generator.api.dom.java.Field) CommentGenerator(org.mybatis.generator.api.CommentGenerator) FullyQualifiedJavaType(org.mybatis.generator.api.dom.java.FullyQualifiedJavaType) TopLevelClass(org.mybatis.generator.api.dom.java.TopLevelClass) Method(org.mybatis.generator.api.dom.java.Method)

Example 23 with TopLevelClass

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

the class PrimaryKeyGenerator method getCompilationUnits.

@Override
public List<CompilationUnit> getCompilationUnits() {
    FullyQualifiedTable table = introspectedTable.getFullyQualifiedTable();
    progressCallback.startTask(getString("Progress.7", //$NON-NLS-1$
    table.toString()));
    Plugin plugins = context.getPlugins();
    CommentGenerator commentGenerator = context.getCommentGenerator();
    TopLevelClass topLevelClass = new TopLevelClass(introspectedTable.getPrimaryKeyType());
    topLevelClass.setVisibility(JavaVisibility.PUBLIC);
    commentGenerator.addJavaFileComment(topLevelClass);
    String rootClass = getRootClass();
    if (rootClass != null) {
        topLevelClass.setSuperClass(new FullyQualifiedJavaType(rootClass));
        topLevelClass.addImportedType(topLevelClass.getSuperClass());
    }
    for (IntrospectedColumn introspectedColumn : introspectedTable.getPrimaryKeyColumns()) {
        if (RootClassInfo.getInstance(rootClass, warnings).containsProperty(introspectedColumn)) {
            continue;
        }
        Field field = getJavaBeansField(introspectedColumn, context, introspectedTable);
        if (plugins.modelFieldGenerated(field, topLevelClass, introspectedColumn, introspectedTable, Plugin.ModelClassType.PRIMARY_KEY)) {
            topLevelClass.addField(field);
            topLevelClass.addImportedType(field.getType());
        }
        Method method = getJavaBeansGetter(introspectedColumn, context, introspectedTable);
        if (plugins.modelGetterMethodGenerated(method, topLevelClass, introspectedColumn, introspectedTable, Plugin.ModelClassType.PRIMARY_KEY)) {
            topLevelClass.addMethod(method);
        }
        method = getJavaBeansSetter(introspectedColumn, context, introspectedTable);
        if (plugins.modelSetterMethodGenerated(method, topLevelClass, introspectedColumn, introspectedTable, Plugin.ModelClassType.PRIMARY_KEY)) {
            topLevelClass.addMethod(method);
        }
    }
    List<CompilationUnit> answer = new ArrayList<CompilationUnit>();
    if (context.getPlugins().modelPrimaryKeyClassGenerated(topLevelClass, introspectedTable)) {
        answer.add(topLevelClass);
    }
    return answer;
}
Also used : CompilationUnit(org.mybatis.generator.api.dom.java.CompilationUnit) Field(org.mybatis.generator.api.dom.java.Field) JavaBeansUtil.getJavaBeansField(org.mybatis.generator.internal.util.JavaBeansUtil.getJavaBeansField) IntrospectedColumn(org.mybatis.generator.api.IntrospectedColumn) CommentGenerator(org.mybatis.generator.api.CommentGenerator) FullyQualifiedJavaType(org.mybatis.generator.api.dom.java.FullyQualifiedJavaType) FullyQualifiedTable(org.mybatis.generator.api.FullyQualifiedTable) TopLevelClass(org.mybatis.generator.api.dom.java.TopLevelClass) ArrayList(java.util.ArrayList) Messages.getString(org.mybatis.generator.internal.util.messages.Messages.getString) Method(org.mybatis.generator.api.dom.java.Method) Plugin(org.mybatis.generator.api.Plugin)

Aggregations

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