Search in sources :

Example 66 with Method

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

the class DeleteByPrimaryKeyMethodGenerator method addInterfaceElements.

@Override
public void addInterfaceElements(Interface interfaze) {
    Set<FullyQualifiedJavaType> importedTypes = new TreeSet<FullyQualifiedJavaType>();
    Method method = getMethodShell(importedTypes);
    if (context.getPlugins().clientDeleteByPrimaryKeyMethodGenerated(method, interfaze, introspectedTable)) {
        interfaze.addImportedTypes(importedTypes);
        interfaze.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 67 with Method

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

the class InsertMethodGenerator method addImplementationElements.

@Override
public void addImplementationElements(TopLevelClass topLevelClass) {
    Set<FullyQualifiedJavaType> importedTypes = new TreeSet<FullyQualifiedJavaType>();
    Method method = getMethodShell(importedTypes);
    FullyQualifiedJavaType returnType = method.getReturnType();
    StringBuilder sb = new StringBuilder();
    if (returnType != null) {
        //$NON-NLS-1$
        sb.append("Object newKey = ");
    }
    sb.append(daoTemplate.getInsertMethod(introspectedTable.getIbatis2SqlMapNamespace(), introspectedTable.getInsertStatementId(), //$NON-NLS-1$
    "record"));
    method.addBodyLine(sb.toString());
    if (returnType != null) {
        if ("Object".equals(returnType.getShortName())) {
            //$NON-NLS-1$
            // no need to cast if the return type is Object
            //$NON-NLS-1$
            method.addBodyLine("return newKey;");
        } else {
            sb.setLength(0);
            if (returnType.isPrimitive()) {
                PrimitiveTypeWrapper ptw = returnType.getPrimitiveTypeWrapper();
                //$NON-NLS-1$
                sb.append("return ((");
                sb.append(ptw.getShortName());
                //$NON-NLS-1$
                sb.append(") newKey");
                //$NON-NLS-1$
                sb.append(").");
                sb.append(ptw.getToPrimitiveMethod());
                sb.append(';');
            } else {
                //$NON-NLS-1$
                sb.append("return (");
                sb.append(returnType.getShortName());
                //$NON-NLS-1$
                sb.append(") newKey;");
            }
            method.addBodyLine(sb.toString());
        }
    }
    if (context.getPlugins().clientInsertMethodGenerated(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) PrimitiveTypeWrapper(org.mybatis.generator.api.dom.java.PrimitiveTypeWrapper)

Example 68 with Method

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

the class InsertMethodGenerator method getMethodShell.

private Method getMethodShell(Set<FullyQualifiedJavaType> importedTypes) {
    Method method = new Method();
    FullyQualifiedJavaType returnType;
    if (introspectedTable.getGeneratedKey() != null) {
        IntrospectedColumn introspectedColumn = introspectedTable.getColumn(introspectedTable.getGeneratedKey().getColumn());
        if (introspectedColumn == null) {
            // the specified column doesn't exist, so don't do the generated
            // key
            // (the warning has already been reported)
            returnType = null;
        } else {
            returnType = introspectedColumn.getFullyQualifiedJavaType();
            importedTypes.add(returnType);
        }
    } else {
        returnType = null;
    }
    method.setReturnType(returnType);
    method.setVisibility(JavaVisibility.PUBLIC);
    DAOMethodNameCalculator methodNameCalculator = getDAOMethodNameCalculator();
    method.setName(methodNameCalculator.getInsertMethodName(introspectedTable));
    FullyQualifiedJavaType parameterType = introspectedTable.getRules().calculateAllFieldsClass();
    importedTypes.add(parameterType);
    //$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 : IntrospectedColumn(org.mybatis.generator.api.IntrospectedColumn) FullyQualifiedJavaType(org.mybatis.generator.api.dom.java.FullyQualifiedJavaType) DAOMethodNameCalculator(org.mybatis.generator.api.DAOMethodNameCalculator) Parameter(org.mybatis.generator.api.dom.java.Parameter) Method(org.mybatis.generator.api.dom.java.Method)

Example 69 with Method

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

the class InsertSelectiveMethodGenerator method getMethodShell.

private Method getMethodShell(Set<FullyQualifiedJavaType> importedTypes) {
    Method method = new Method();
    FullyQualifiedJavaType returnType;
    if (introspectedTable.getGeneratedKey() != null) {
        IntrospectedColumn introspectedColumn = introspectedTable.getColumn(introspectedTable.getGeneratedKey().getColumn());
        if (introspectedColumn == null) {
            // the specified column doesn't exist, so don't do the generated
            // key
            // (the warning has already been reported)
            returnType = null;
        } else {
            returnType = introspectedColumn.getFullyQualifiedJavaType();
            importedTypes.add(returnType);
        }
    } else {
        returnType = null;
    }
    method.setReturnType(returnType);
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setName(getDAOMethodNameCalculator().getInsertSelectiveMethodName(introspectedTable));
    FullyQualifiedJavaType parameterType = introspectedTable.getRules().calculateAllFieldsClass();
    importedTypes.add(parameterType);
    //$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 : IntrospectedColumn(org.mybatis.generator.api.IntrospectedColumn) 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 70 with Method

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

the class InsertSelectiveMethodGenerator method addInterfaceElements.

@Override
public void addInterfaceElements(Interface interfaze) {
    Set<FullyQualifiedJavaType> importedTypes = new TreeSet<FullyQualifiedJavaType>();
    Method method = getMethodShell(importedTypes);
    if (context.getPlugins().clientInsertSelectiveMethodGenerated(method, interfaze, introspectedTable)) {
        interfaze.addImportedTypes(importedTypes);
        interfaze.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