Search in sources :

Example 21 with FullyQualifiedJavaType

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

the class AnnotatedUpdateByPrimaryKeySelectiveMethodGenerator method addMapperAnnotations.

@Override
public void addMapperAnnotations(Method method) {
    FullyQualifiedJavaType fqjt = new FullyQualifiedJavaType(introspectedTable.getMyBatis3SqlProviderType());
    StringBuilder sb = new StringBuilder();
    //$NON-NLS-1$
    sb.append("@UpdateProvider(type=");
    sb.append(fqjt.getShortName());
    //$NON-NLS-1$
    sb.append(".class, method=\"");
    sb.append(introspectedTable.getUpdateByPrimaryKeySelectiveStatementId());
    //$NON-NLS-1$
    sb.append("\")");
    method.addAnnotation(sb.toString());
}
Also used : FullyQualifiedJavaType(org.mybatis.generator.api.dom.java.FullyQualifiedJavaType)

Example 22 with FullyQualifiedJavaType

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

the class DeleteByPrimaryKeyMethodGenerator method addInterfaceElements.

@Override
public void addInterfaceElements(Interface interfaze) {
    Set<FullyQualifiedJavaType> importedTypes = new TreeSet<FullyQualifiedJavaType>();
    Method method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setReturnType(FullyQualifiedJavaType.getIntInstance());
    method.setName(introspectedTable.getDeleteByPrimaryKeyStatementId());
    if (!isSimple && introspectedTable.getRules().generatePrimaryKeyClass()) {
        FullyQualifiedJavaType type = new FullyQualifiedJavaType(introspectedTable.getPrimaryKeyType());
        importedTypes.add(type);
        //$NON-NLS-1$
        method.addParameter(new Parameter(type, "key"));
    } else {
        // no primary key class - fields are in the base class
        // if more than one PK field, then we need to annotate the
        // parameters
        // for MyBatis
        List<IntrospectedColumn> introspectedColumns = introspectedTable.getPrimaryKeyColumns();
        boolean annotate = introspectedColumns.size() > 1;
        if (annotate) {
            importedTypes.add(new FullyQualifiedJavaType(//$NON-NLS-1$
            "org.apache.ibatis.annotations.Param"));
        }
        StringBuilder sb = new StringBuilder();
        for (IntrospectedColumn introspectedColumn : introspectedColumns) {
            FullyQualifiedJavaType type = introspectedColumn.getFullyQualifiedJavaType();
            importedTypes.add(type);
            Parameter parameter = new Parameter(type, introspectedColumn.getJavaProperty());
            if (annotate) {
                sb.setLength(0);
                //$NON-NLS-1$
                sb.append("@Param(\"");
                sb.append(introspectedColumn.getJavaProperty());
                //$NON-NLS-1$
                sb.append("\")");
                parameter.addAnnotation(sb.toString());
            }
            method.addParameter(parameter);
        }
    }
    context.getCommentGenerator().addGeneralMethodComment(method, introspectedTable);
    addMapperAnnotations(method);
    if (context.getPlugins().clientDeleteByPrimaryKeyMethodGenerated(method, interfaze, introspectedTable)) {
        addExtraImports(interfaze);
        interfaze.addImportedTypes(importedTypes);
        interfaze.addMethod(method);
    }
}
Also used : IntrospectedColumn(org.mybatis.generator.api.IntrospectedColumn) TreeSet(java.util.TreeSet) 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 23 with FullyQualifiedJavaType

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

the class InsertMethodGenerator method addInterfaceElements.

@Override
public void addInterfaceElements(Interface interfaze) {
    Set<FullyQualifiedJavaType> importedTypes = new TreeSet<FullyQualifiedJavaType>();
    Method method = new Method();
    method.setReturnType(FullyQualifiedJavaType.getIntInstance());
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setName(introspectedTable.getInsertStatementId());
    FullyQualifiedJavaType parameterType;
    if (isSimple) {
        parameterType = new FullyQualifiedJavaType(introspectedTable.getBaseRecordType());
    } else {
        parameterType = introspectedTable.getRules().calculateAllFieldsClass();
    }
    importedTypes.add(parameterType);
    //$NON-NLS-1$
    method.addParameter(new Parameter(parameterType, "record"));
    context.getCommentGenerator().addGeneralMethodComment(method, introspectedTable);
    addMapperAnnotations(method);
    if (context.getPlugins().clientInsertMethodGenerated(method, interfaze, introspectedTable)) {
        addExtraImports(interfaze);
        interfaze.addImportedTypes(importedTypes);
        interfaze.addMethod(method);
    }
}
Also used : TreeSet(java.util.TreeSet) 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 24 with FullyQualifiedJavaType

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

the class SelectByExampleWithoutBLOBsMethodGenerator method addInterfaceElements.

@Override
public void addInterfaceElements(Interface interfaze) {
    Set<FullyQualifiedJavaType> importedTypes = new TreeSet<FullyQualifiedJavaType>();
    FullyQualifiedJavaType type = new FullyQualifiedJavaType(introspectedTable.getExampleType());
    importedTypes.add(type);
    importedTypes.add(FullyQualifiedJavaType.getNewListInstance());
    Method method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    FullyQualifiedJavaType returnType = FullyQualifiedJavaType.getNewListInstance();
    FullyQualifiedJavaType listType;
    if (introspectedTable.getRules().generateBaseRecordClass()) {
        listType = new FullyQualifiedJavaType(introspectedTable.getBaseRecordType());
    } else if (introspectedTable.getRules().generatePrimaryKeyClass()) {
        listType = new FullyQualifiedJavaType(introspectedTable.getPrimaryKeyType());
    } else {
        //$NON-NLS-1$
        throw new RuntimeException(getString("RuntimeError.12"));
    }
    importedTypes.add(listType);
    returnType.addTypeArgument(listType);
    method.setReturnType(returnType);
    method.setName(introspectedTable.getSelectByExampleStatementId());
    //$NON-NLS-1$
    method.addParameter(new Parameter(type, "example"));
    context.getCommentGenerator().addGeneralMethodComment(method, introspectedTable);
    addMapperAnnotations(interfaze, method);
    if (context.getPlugins().clientSelectByExampleWithoutBLOBsMethodGenerated(method, interfaze, introspectedTable)) {
        addExtraImports(interfaze);
        interfaze.addImportedTypes(importedTypes);
        interfaze.addMethod(method);
    }
}
Also used : TreeSet(java.util.TreeSet) 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 25 with FullyQualifiedJavaType

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

the class SelectByPrimaryKeyMethodGenerator method addInterfaceElements.

@Override
public void addInterfaceElements(Interface interfaze) {
    Set<FullyQualifiedJavaType> importedTypes = new TreeSet<FullyQualifiedJavaType>();
    Method method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    FullyQualifiedJavaType returnType = introspectedTable.getRules().calculateAllFieldsClass();
    method.setReturnType(returnType);
    importedTypes.add(returnType);
    method.setName(introspectedTable.getSelectByPrimaryKeyStatementId());
    if (!isSimple && introspectedTable.getRules().generatePrimaryKeyClass()) {
        FullyQualifiedJavaType type = new FullyQualifiedJavaType(introspectedTable.getPrimaryKeyType());
        importedTypes.add(type);
        //$NON-NLS-1$
        method.addParameter(new Parameter(type, "key"));
    } else {
        // no primary key class - fields are in the base class
        // if more than one PK field, then we need to annotate the
        // parameters
        // for MyBatis3
        List<IntrospectedColumn> introspectedColumns = introspectedTable.getPrimaryKeyColumns();
        boolean annotate = introspectedColumns.size() > 1;
        if (annotate) {
            importedTypes.add(new FullyQualifiedJavaType(//$NON-NLS-1$
            "org.apache.ibatis.annotations.Param"));
        }
        StringBuilder sb = new StringBuilder();
        for (IntrospectedColumn introspectedColumn : introspectedColumns) {
            FullyQualifiedJavaType type = introspectedColumn.getFullyQualifiedJavaType();
            importedTypes.add(type);
            Parameter parameter = new Parameter(type, introspectedColumn.getJavaProperty());
            if (annotate) {
                sb.setLength(0);
                //$NON-NLS-1$
                sb.append("@Param(\"");
                sb.append(introspectedColumn.getJavaProperty());
                //$NON-NLS-1$
                sb.append("\")");
                parameter.addAnnotation(sb.toString());
            }
            method.addParameter(parameter);
        }
    }
    addMapperAnnotations(interfaze, method);
    context.getCommentGenerator().addGeneralMethodComment(method, introspectedTable);
    if (context.getPlugins().clientSelectByPrimaryKeyMethodGenerated(method, interfaze, introspectedTable)) {
        addExtraImports(interfaze);
        interfaze.addImportedTypes(importedTypes);
        interfaze.addMethod(method);
    }
}
Also used : IntrospectedColumn(org.mybatis.generator.api.IntrospectedColumn) TreeSet(java.util.TreeSet) 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

FullyQualifiedJavaType (org.mybatis.generator.api.dom.java.FullyQualifiedJavaType)163 Method (org.mybatis.generator.api.dom.java.Method)97 Parameter (org.mybatis.generator.api.dom.java.Parameter)54 TreeSet (java.util.TreeSet)53 IntrospectedColumn (org.mybatis.generator.api.IntrospectedColumn)32 Test (org.junit.Test)24 ArrayList (java.util.ArrayList)19 Field (org.mybatis.generator.api.dom.java.Field)19 TopLevelClass (org.mybatis.generator.api.dom.java.TopLevelClass)19 Messages.getString (org.mybatis.generator.internal.util.messages.Messages.getString)14 CommentGenerator (org.mybatis.generator.api.CommentGenerator)11 CompilationUnit (org.mybatis.generator.api.dom.java.CompilationUnit)11 Interface (org.mybatis.generator.api.dom.java.Interface)10 FullyQualifiedTable (org.mybatis.generator.api.FullyQualifiedTable)7 GeneratedKey (org.mybatis.generator.config.GeneratedKey)7 Plugin (org.mybatis.generator.api.Plugin)5 Attribute (org.mybatis.generator.api.dom.xml.Attribute)5 TextElement (org.mybatis.generator.api.dom.xml.TextElement)5 XmlElement (org.mybatis.generator.api.dom.xml.XmlElement)5 JavaBeansUtil.getJavaBeansField (org.mybatis.generator.internal.util.JavaBeansUtil.getJavaBeansField)5