Search in sources :

Example 41 with Method

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

the class AbstractDAOTemplate method getConstructorClone.

/**
     * Gets the constructor clone.
     *
     * @param commentGenerator
     *            the comment generator
     * @param type
     *            the type
     * @param introspectedTable
     *            the introspected table
     * @return the constructor clone
     */
public final Method getConstructorClone(CommentGenerator commentGenerator, FullyQualifiedJavaType type, IntrospectedTable introspectedTable) {
    configure();
    Method answer = new Method();
    answer.setConstructor(true);
    answer.setName(type.getShortName());
    answer.setVisibility(constructorTemplate.getVisibility());
    for (Parameter parm : constructorTemplate.getParameters()) {
        answer.addParameter(parm);
    }
    for (String bodyLine : constructorTemplate.getBodyLines()) {
        answer.addBodyLine(bodyLine);
    }
    for (FullyQualifiedJavaType fqjt : constructorTemplate.getExceptions()) {
        answer.addException(fqjt);
    }
    commentGenerator.addGeneralMethodComment(answer, introspectedTable);
    return answer;
}
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 42 with Method

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

the class GenericCIDAOTemplate method configureConstructorTemplate.

@Override
protected void configureConstructorTemplate() {
    Method constructor = new Method();
    constructor.setConstructor(true);
    constructor.setVisibility(JavaVisibility.PUBLIC);
    constructor.addParameter(//$NON-NLS-1$
    new Parameter(sqlMapClientType, "sqlMapClient"));
    //$NON-NLS-1$
    constructor.addBodyLine("super();");
    //$NON-NLS-1$
    constructor.addBodyLine("this.sqlMapClient = sqlMapClient;");
    setConstructorTemplate(constructor);
}
Also used : Parameter(org.mybatis.generator.api.dom.java.Parameter) Method(org.mybatis.generator.api.dom.java.Method)

Example 43 with Method

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

the class GenericSIDAOTemplate method configureMethods.

@Override
protected void configureMethods() {
    Method method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    //$NON-NLS-1$
    method.setName("setSqlMapClient");
    //$NON-NLS-1$
    method.addParameter(new Parameter(sqlMapClientType, "sqlMapClient"));
    //$NON-NLS-1$
    method.addBodyLine("this.sqlMapClient = sqlMapClient;");
    addMethod(method);
    method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    //$NON-NLS-1$
    method.setName("getSqlMapClient");
    method.setReturnType(sqlMapClientType);
    //$NON-NLS-1$
    method.addBodyLine("return sqlMapClient;");
    addMethod(method);
}
Also used : Parameter(org.mybatis.generator.api.dom.java.Parameter) Method(org.mybatis.generator.api.dom.java.Method)

Example 44 with Method

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

the class SelectByExampleWithoutBLOBsMethodGenerator method addImplementationElements.

@Override
public void addImplementationElements(TopLevelClass topLevelClass) {
    Set<FullyQualifiedJavaType> importedTypes = new TreeSet<FullyQualifiedJavaType>();
    Method method = getMethodShell(importedTypes);
    if (generateForJava5) {
        method.addSuppressTypeWarningsAnnotation();
    }
    StringBuilder sb = new StringBuilder();
    sb.append(method.getReturnType().getShortName());
    //$NON-NLS-1$
    sb.append(" list = ");
    sb.append(daoTemplate.getQueryForListMethod(introspectedTable.getIbatis2SqlMapNamespace(), introspectedTable.getSelectByExampleStatementId(), //$NON-NLS-1$
    "example"));
    method.addBodyLine(sb.toString());
    //$NON-NLS-1$
    method.addBodyLine("return list;");
    if (context.getPlugins().clientSelectByExampleWithoutBLOBsMethodGenerated(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)

Example 45 with Method

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

the class SelectByExampleWithoutBLOBsMethodGenerator 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().generateBaseRecordClass()) {
            fqjt = new FullyQualifiedJavaType(introspectedTable.getBaseRecordType());
        } else if (introspectedTable.getRules().generatePrimaryKeyClass()) {
            fqjt = new FullyQualifiedJavaType(introspectedTable.getPrimaryKeyType());
        } else {
            //$NON-NLS-1$
            throw new RuntimeException(getString("RuntimeError.12"));
        }
        importedTypes.add(fqjt);
        returnType.addTypeArgument(fqjt);
    }
    method.setReturnType(returnType);
    method.setName(getDAOMethodNameCalculator().getSelectByExampleWithoutBLOBsMethodName(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)

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