Search in sources :

Example 36 with Parameter

use of org.mybatis.generator.api.dom.java.Parameter 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 37 with Parameter

use of org.mybatis.generator.api.dom.java.Parameter 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 38 with Parameter

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

the class TestResourceGenerator method simpleInterfaceWithAllGeneratedItems.

public static String simpleInterfaceWithAllGeneratedItems() {
    Interface itf = new Interface(new FullyQualifiedJavaType("org.mybatis.test.SimpleInterface"));
    itf.setVisibility(JavaVisibility.PUBLIC);
    Method method = new Method("count");
    method.setReturnType(FullyQualifiedJavaType.getIntInstance());
    commentGenerator.addMethodComment(method);
    itf.addMethod(method);
    method = new Method("add");
    method.addParameter(new Parameter(FullyQualifiedJavaType.getIntInstance(), "a"));
    method.addParameter(new Parameter(FullyQualifiedJavaType.getIntInstance(), "b"));
    method.setReturnType(FullyQualifiedJavaType.getIntInstance());
    commentGenerator.addMethodComment(method);
    itf.addMethod(method);
    return itf.getFormattedContent();
}
Also used : FullyQualifiedJavaType(org.mybatis.generator.api.dom.java.FullyQualifiedJavaType) Parameter(org.mybatis.generator.api.dom.java.Parameter) Method(org.mybatis.generator.api.dom.java.Method) Interface(org.mybatis.generator.api.dom.java.Interface)

Example 39 with Parameter

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

the class UpdateByPrimaryKeyWithoutBLOBsMethodGenerator method getMethodShell.

private Method getMethodShell(Set<FullyQualifiedJavaType> importedTypes) {
    FullyQualifiedJavaType parameterType = new FullyQualifiedJavaType(introspectedTable.getBaseRecordType());
    importedTypes.add(parameterType);
    Method method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setReturnType(FullyQualifiedJavaType.getIntInstance());
    method.setName(getDAOMethodNameCalculator().getUpdateByPrimaryKeyWithoutBLOBsMethodName(introspectedTable));
    //$NON-NLS-1$
    method.addParameter(new Parameter(parameterType, "record"));
    for (FullyQualifiedJavaType fqjt : daoTemplate.getCheckedExceptions()) {
        method.addException(fqjt);
        importedTypes.add(fqjt);
    }
    context.getCommentGenerator().addGeneralMethodComment(method, introspectedTable);
    return method;
}
Also used : FullyQualifiedJavaType(org.mybatis.generator.api.dom.java.FullyQualifiedJavaType) Parameter(org.mybatis.generator.api.dom.java.Parameter) Method(org.mybatis.generator.api.dom.java.Method)

Example 40 with Parameter

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

the class UpdateByExampleSelectiveMethodGenerator method getMethodShell.

private Method getMethodShell(Set<FullyQualifiedJavaType> importedTypes) {
    FullyQualifiedJavaType parameterType;
    if (introspectedTable.getRules().generateRecordWithBLOBsClass()) {
        parameterType = new FullyQualifiedJavaType(introspectedTable.getRecordWithBLOBsType());
    } else if (introspectedTable.getRules().generateBaseRecordClass()) {
        parameterType = new FullyQualifiedJavaType(introspectedTable.getBaseRecordType());
    } else {
        parameterType = new FullyQualifiedJavaType(introspectedTable.getPrimaryKeyType());
    }
    importedTypes.add(parameterType);
    Method method = new Method();
    method.setVisibility(getExampleMethodVisibility());
    method.setReturnType(FullyQualifiedJavaType.getIntInstance());
    method.setName(getDAOMethodNameCalculator().getUpdateByExampleSelectiveMethodName(introspectedTable));
    //$NON-NLS-1$
    method.addParameter(new Parameter(parameterType, "record"));
    method.addParameter(new Parameter(new FullyQualifiedJavaType(introspectedTable.getExampleType()), //$NON-NLS-1$
    "example"));
    for (FullyQualifiedJavaType fqjt : daoTemplate.getCheckedExceptions()) {
        method.addException(fqjt);
        importedTypes.add(fqjt);
    }
    context.getCommentGenerator().addGeneralMethodComment(method, introspectedTable);
    return method;
}
Also used : FullyQualifiedJavaType(org.mybatis.generator.api.dom.java.FullyQualifiedJavaType) Parameter(org.mybatis.generator.api.dom.java.Parameter) Method(org.mybatis.generator.api.dom.java.Method)

Aggregations

Parameter (org.mybatis.generator.api.dom.java.Parameter)68 Method (org.mybatis.generator.api.dom.java.Method)66 FullyQualifiedJavaType (org.mybatis.generator.api.dom.java.FullyQualifiedJavaType)55 TreeSet (java.util.TreeSet)20 IntrospectedColumn (org.mybatis.generator.api.IntrospectedColumn)17 Field (org.mybatis.generator.api.dom.java.Field)11 ArrayList (java.util.ArrayList)7 InnerClass (org.mybatis.generator.api.dom.java.InnerClass)5 TopLevelClass (org.mybatis.generator.api.dom.java.TopLevelClass)5 Messages.getString (org.mybatis.generator.internal.util.messages.Messages.getString)4 CompilationUnit (org.mybatis.generator.api.dom.java.CompilationUnit)3 CommentGenerator (org.mybatis.generator.api.CommentGenerator)2 FullyQualifiedTable (org.mybatis.generator.api.FullyQualifiedTable)2 Interface (org.mybatis.generator.api.dom.java.Interface)2 DAOMethodNameCalculator (org.mybatis.generator.api.DAOMethodNameCalculator)1 Rules (org.mybatis.generator.internal.rules.Rules)1