Search in sources :

Example 1 with Field

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

the class RecordWithBLOBsGenerator method getCompilationUnits.

@Override
public List<CompilationUnit> getCompilationUnits() {
    FullyQualifiedTable table = introspectedTable.getFullyQualifiedTable();
    progressCallback.startTask(getString("Progress.9", //$NON-NLS-1$
    table.toString()));
    Plugin plugins = context.getPlugins();
    CommentGenerator commentGenerator = context.getCommentGenerator();
    TopLevelClass topLevelClass = new TopLevelClass(introspectedTable.getRecordWithBLOBsType());
    topLevelClass.setVisibility(JavaVisibility.PUBLIC);
    commentGenerator.addJavaFileComment(topLevelClass);
    String rootClass = getRootClass();
    if (introspectedTable.getRules().generateBaseRecordClass()) {
        topLevelClass.setSuperClass(introspectedTable.getBaseRecordType());
    } else {
        topLevelClass.setSuperClass(introspectedTable.getPrimaryKeyType());
    }
    commentGenerator.addModelClassComment(topLevelClass, introspectedTable);
    if (introspectedTable.isConstructorBased()) {
        addParameterizedConstructor(topLevelClass);
        if (!introspectedTable.isImmutable()) {
            addDefaultConstructor(topLevelClass);
        }
    }
    for (IntrospectedColumn introspectedColumn : introspectedTable.getBLOBColumns()) {
        if (RootClassInfo.getInstance(rootClass, warnings).containsProperty(introspectedColumn)) {
            continue;
        }
        Field field = getJavaBeansField(introspectedColumn, context, introspectedTable);
        if (plugins.modelFieldGenerated(field, topLevelClass, introspectedColumn, introspectedTable, Plugin.ModelClassType.RECORD_WITH_BLOBS)) {
            topLevelClass.addField(field);
            topLevelClass.addImportedType(field.getType());
        }
        Method method = getJavaBeansGetter(introspectedColumn, context, introspectedTable);
        if (plugins.modelGetterMethodGenerated(method, topLevelClass, introspectedColumn, introspectedTable, Plugin.ModelClassType.RECORD_WITH_BLOBS)) {
            topLevelClass.addMethod(method);
        }
        if (!introspectedTable.isImmutable()) {
            method = getJavaBeansSetter(introspectedColumn, context, introspectedTable);
            if (plugins.modelSetterMethodGenerated(method, topLevelClass, introspectedColumn, introspectedTable, Plugin.ModelClassType.RECORD_WITH_BLOBS)) {
                topLevelClass.addMethod(method);
            }
        }
    }
    List<CompilationUnit> answer = new ArrayList<CompilationUnit>();
    if (context.getPlugins().modelRecordWithBLOBsClassGenerated(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) 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)

Example 2 with Field

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

the class SimpleModelGenerator method getCompilationUnits.

@Override
public List<CompilationUnit> getCompilationUnits() {
    FullyQualifiedTable table = introspectedTable.getFullyQualifiedTable();
    //$NON-NLS-1$
    progressCallback.startTask(getString("Progress.8", table.toString()));
    Plugin plugins = context.getPlugins();
    CommentGenerator commentGenerator = context.getCommentGenerator();
    FullyQualifiedJavaType type = new FullyQualifiedJavaType(introspectedTable.getBaseRecordType());
    TopLevelClass topLevelClass = new TopLevelClass(type);
    topLevelClass.setVisibility(JavaVisibility.PUBLIC);
    commentGenerator.addJavaFileComment(topLevelClass);
    FullyQualifiedJavaType superClass = getSuperClass();
    if (superClass != null) {
        topLevelClass.setSuperClass(superClass);
        topLevelClass.addImportedType(superClass);
    }
    commentGenerator.addModelClassComment(topLevelClass, introspectedTable);
    List<IntrospectedColumn> introspectedColumns = introspectedTable.getAllColumns();
    if (introspectedTable.isConstructorBased()) {
        addParameterizedConstructor(topLevelClass);
        if (!introspectedTable.isImmutable()) {
            addDefaultConstructor(topLevelClass);
        }
    }
    String rootClass = getRootClass();
    for (IntrospectedColumn introspectedColumn : introspectedColumns) {
        if (RootClassInfo.getInstance(rootClass, warnings).containsProperty(introspectedColumn)) {
            continue;
        }
        Field field = getJavaBeansField(introspectedColumn, context, introspectedTable);
        if (plugins.modelFieldGenerated(field, topLevelClass, introspectedColumn, introspectedTable, Plugin.ModelClassType.BASE_RECORD)) {
            topLevelClass.addField(field);
            topLevelClass.addImportedType(field.getType());
        }
        Method method = getJavaBeansGetter(introspectedColumn, context, introspectedTable);
        if (plugins.modelGetterMethodGenerated(method, topLevelClass, introspectedColumn, introspectedTable, Plugin.ModelClassType.BASE_RECORD)) {
            topLevelClass.addMethod(method);
        }
        if (!introspectedTable.isImmutable()) {
            method = getJavaBeansSetter(introspectedColumn, context, introspectedTable);
            if (plugins.modelSetterMethodGenerated(method, topLevelClass, introspectedColumn, introspectedTable, Plugin.ModelClassType.BASE_RECORD)) {
                topLevelClass.addMethod(method);
            }
        }
    }
    List<CompilationUnit> answer = new ArrayList<CompilationUnit>();
    if (context.getPlugins().modelBaseRecordClassGenerated(topLevelClass, introspectedTable)) {
        answer.add(topLevelClass);
    }
    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) 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) Field(org.mybatis.generator.api.dom.java.Field) JavaBeansUtil.getJavaBeansField(org.mybatis.generator.internal.util.JavaBeansUtil.getJavaBeansField) IntrospectedColumn(org.mybatis.generator.api.IntrospectedColumn) FullyQualifiedTable(org.mybatis.generator.api.FullyQualifiedTable) Plugin(org.mybatis.generator.api.Plugin)

Example 3 with Field

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

the class TestResourceGenerator method simpleClassWithGeneratedAndCustomItems.

public static String simpleClassWithGeneratedAndCustomItems() {
    TopLevelClass tlc = new TopLevelClass(new FullyQualifiedJavaType("org.mybatis.test.SimpleClass"));
    tlc.setVisibility(JavaVisibility.PUBLIC);
    Field field = new Field("description", FullyQualifiedJavaType.getStringInstance());
    field.setVisibility(JavaVisibility.PRIVATE);
    commentGenerator.addFieldComment(field);
    tlc.addField(field);
    Method method = new Method("getDescription");
    method.setReturnType(FullyQualifiedJavaType.getStringInstance());
    method.addBodyLine("return description;");
    method.setVisibility(JavaVisibility.PUBLIC);
    commentGenerator.addMethodComment(method);
    tlc.addMethod(method);
    method = new Method("setDescription");
    method.addParameter(new Parameter(FullyQualifiedJavaType.getStringInstance(), "description"));
    method.addBodyLine("this.description = description;");
    method.setVisibility(JavaVisibility.PUBLIC);
    commentGenerator.addMethodComment(method);
    tlc.addMethod(method);
    // no comments on these items - they should survive a merge
    FullyQualifiedJavaType bigDecimal = new FullyQualifiedJavaType("java.math.BigDecimal");
    tlc.addImportedType(bigDecimal);
    field = new Field("amount", bigDecimal);
    field.setVisibility(JavaVisibility.PRIVATE);
    tlc.addField(field);
    method = new Method("getAmount");
    method.setReturnType(bigDecimal);
    method.addBodyLine("return amount;");
    method.setVisibility(JavaVisibility.PUBLIC);
    tlc.addMethod(method);
    method = new Method("setAmount");
    method.addParameter(new Parameter(bigDecimal, "amount"));
    method.addBodyLine("this.amount = amount;");
    method.setVisibility(JavaVisibility.PUBLIC);
    tlc.addMethod(method);
    return tlc.getFormattedContent();
}
Also used : Field(org.mybatis.generator.api.dom.java.Field) FullyQualifiedJavaType(org.mybatis.generator.api.dom.java.FullyQualifiedJavaType) TopLevelClass(org.mybatis.generator.api.dom.java.TopLevelClass) Parameter(org.mybatis.generator.api.dom.java.Parameter) Method(org.mybatis.generator.api.dom.java.Method)

Example 4 with Field

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

the class TestResourceGenerator method simpleClassWithAllGeneratedItems.

public static String simpleClassWithAllGeneratedItems() {
    TopLevelClass tlc = new TopLevelClass(new FullyQualifiedJavaType("org.mybatis.test.SimpleClass"));
    tlc.setVisibility(JavaVisibility.PUBLIC);
    Field field = new Field("id", FullyQualifiedJavaType.getIntInstance());
    field.setVisibility(JavaVisibility.PRIVATE);
    commentGenerator.addFieldComment(field);
    tlc.addField(field);
    Method method = new Method("getId");
    method.setReturnType(FullyQualifiedJavaType.getIntInstance());
    method.addBodyLine("return id;");
    method.setVisibility(JavaVisibility.PUBLIC);
    commentGenerator.addMethodComment(method);
    tlc.addMethod(method);
    method = new Method("setId");
    method.addParameter(new Parameter(FullyQualifiedJavaType.getIntInstance(), "id"));
    method.addBodyLine("this.id = id;");
    method.setVisibility(JavaVisibility.PUBLIC);
    commentGenerator.addMethodComment(method);
    tlc.addMethod(method);
    return tlc.getFormattedContent();
}
Also used : Field(org.mybatis.generator.api.dom.java.Field) FullyQualifiedJavaType(org.mybatis.generator.api.dom.java.FullyQualifiedJavaType) TopLevelClass(org.mybatis.generator.api.dom.java.TopLevelClass) Parameter(org.mybatis.generator.api.dom.java.Parameter) Method(org.mybatis.generator.api.dom.java.Method)

Example 5 with Field

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

the class GenericSIDAOTemplate method configureFields.

@Override
protected void configureFields() {
    Field field = new Field();
    field.setVisibility(JavaVisibility.PRIVATE);
    field.setType(sqlMapClientType);
    //$NON-NLS-1$
    field.setName("sqlMapClient");
    addField(field);
}
Also used : Field(org.mybatis.generator.api.dom.java.Field)

Aggregations

Field (org.mybatis.generator.api.dom.java.Field)25 Method (org.mybatis.generator.api.dom.java.Method)20 FullyQualifiedJavaType (org.mybatis.generator.api.dom.java.FullyQualifiedJavaType)19 ArrayList (java.util.ArrayList)14 TopLevelClass (org.mybatis.generator.api.dom.java.TopLevelClass)13 Parameter (org.mybatis.generator.api.dom.java.Parameter)11 Messages.getString (org.mybatis.generator.internal.util.messages.Messages.getString)11 CommentGenerator (org.mybatis.generator.api.CommentGenerator)10 CompilationUnit (org.mybatis.generator.api.dom.java.CompilationUnit)10 FullyQualifiedTable (org.mybatis.generator.api.FullyQualifiedTable)9 IntrospectedColumn (org.mybatis.generator.api.IntrospectedColumn)9 Plugin (org.mybatis.generator.api.Plugin)7 JavaBeansUtil.getJavaBeansField (org.mybatis.generator.internal.util.JavaBeansUtil.getJavaBeansField)7 InnerClass (org.mybatis.generator.api.dom.java.InnerClass)4 Rules (org.mybatis.generator.internal.rules.Rules)1