Search in sources :

Example 61 with Method

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

the class SelectByExampleWithBLOBsMethodGenerator method getMethodShell.

private Method getMethodShell(Set<FullyQualifiedJavaType> importedTypes) {
    FullyQualifiedJavaType type = new FullyQualifiedJavaType(introspectedTable.getExampleType());
    importedTypes.add(type);
    importedTypes.add(FullyQualifiedJavaType.getNewListInstance());
    Method method = new Method();
    method.setVisibility(getExampleMethodVisibility());
    FullyQualifiedJavaType returnType = FullyQualifiedJavaType.getNewListInstance();
    if (generateForJava5) {
        FullyQualifiedJavaType fqjt;
        if (introspectedTable.getRules().generateRecordWithBLOBsClass()) {
            fqjt = new FullyQualifiedJavaType(introspectedTable.getRecordWithBLOBsType());
        } else {
            // the blob fields must be rolled up into the base class
            fqjt = new FullyQualifiedJavaType(introspectedTable.getBaseRecordType());
        }
        importedTypes.add(fqjt);
        returnType.addTypeArgument(fqjt);
    }
    method.setReturnType(returnType);
    method.setName(getDAOMethodNameCalculator().getSelectByExampleWithBLOBsMethodName(introspectedTable));
    //$NON-NLS-1$
    method.addParameter(new Parameter(type, "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)

Example 62 with Method

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

the class TestResourceGenerator method simpleInterfaceWithGeneratedAndCustomItems.

public static String simpleInterfaceWithGeneratedAndCustomItems() {
    Interface itf = new Interface(new FullyQualifiedJavaType("org.mybatis.test.SimpleInterface"));
    itf.setVisibility(JavaVisibility.PUBLIC);
    Method method = new Method("subtract");
    method.addParameter(new Parameter(FullyQualifiedJavaType.getIntInstance(), "a"));
    method.addParameter(new Parameter(FullyQualifiedJavaType.getIntInstance(), "b"));
    method.setReturnType(FullyQualifiedJavaType.getIntInstance());
    commentGenerator.addMethodComment(method);
    itf.addMethod(method);
    method = new Method("nonGeneratedMethod");
    method.setReturnType(FullyQualifiedJavaType.getIntInstance());
    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 63 with Method

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

the class AbstractJavaGenerator method getGetter.

public static Method getGetter(Field field) {
    Method method = new Method();
    method.setName(getGetterMethodName(field.getName(), field.getType()));
    method.setReturnType(field.getType());
    method.setVisibility(JavaVisibility.PUBLIC);
    StringBuilder sb = new StringBuilder();
    //$NON-NLS-1$
    sb.append("return ");
    sb.append(field.getName());
    sb.append(';');
    method.addBodyLine(sb.toString());
    return method;
}
Also used : Method(org.mybatis.generator.api.dom.java.Method)

Example 64 with Method

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

the class AbstractJavaGenerator method addDefaultConstructor.

protected void addDefaultConstructor(TopLevelClass topLevelClass) {
    Method method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setConstructor(true);
    method.setName(topLevelClass.getType().getShortName());
    //$NON-NLS-1$
    method.addBodyLine("super();");
    context.getCommentGenerator().addGeneralMethodComment(method, introspectedTable);
    topLevelClass.addMethod(method);
}
Also used : Method(org.mybatis.generator.api.dom.java.Method)

Example 65 with Method

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

the class DeleteByExampleMethodGenerator method addImplementationElements.

@Override
public void addImplementationElements(TopLevelClass topLevelClass) {
    Set<FullyQualifiedJavaType> importedTypes = new TreeSet<FullyQualifiedJavaType>();
    Method method = getMethodShell(importedTypes);
    StringBuilder sb = new StringBuilder();
    //$NON-NLS-1$
    sb.append("int rows = ");
    sb.append(daoTemplate.getDeleteMethod(introspectedTable.getIbatis2SqlMapNamespace(), introspectedTable.getDeleteByExampleStatementId(), //$NON-NLS-1$
    "example"));
    method.addBodyLine(sb.toString());
    //$NON-NLS-1$
    method.addBodyLine("return rows;");
    if (context.getPlugins().clientDeleteByExampleMethodGenerated(method, topLevelClass, introspectedTable)) {
        topLevelClass.addImportedTypes(importedTypes);
        topLevelClass.addMethod(method);
    }
}
Also used : TreeSet(java.util.TreeSet) FullyQualifiedJavaType(org.mybatis.generator.api.dom.java.FullyQualifiedJavaType) Method(org.mybatis.generator.api.dom.java.Method)

Aggregations

Method (org.mybatis.generator.api.dom.java.Method)121 FullyQualifiedJavaType (org.mybatis.generator.api.dom.java.FullyQualifiedJavaType)97 Parameter (org.mybatis.generator.api.dom.java.Parameter)66 TreeSet (java.util.TreeSet)51 IntrospectedColumn (org.mybatis.generator.api.IntrospectedColumn)29 Field (org.mybatis.generator.api.dom.java.Field)20 TopLevelClass (org.mybatis.generator.api.dom.java.TopLevelClass)17 ArrayList (java.util.ArrayList)14 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 Plugin (org.mybatis.generator.api.Plugin)7 InnerClass (org.mybatis.generator.api.dom.java.InnerClass)7 JavaBeansUtil.getJavaBeansField (org.mybatis.generator.internal.util.JavaBeansUtil.getJavaBeansField)7 Interface (org.mybatis.generator.api.dom.java.Interface)2 PrimitiveTypeWrapper (org.mybatis.generator.api.dom.java.PrimitiveTypeWrapper)2 DAOMethodNameCalculator (org.mybatis.generator.api.DAOMethodNameCalculator)1 Rules (org.mybatis.generator.internal.rules.Rules)1