Search in sources :

Example 81 with FullyQualifiedJavaType

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

the class DeleteByPrimaryKeyMethodGenerator method addImplementationElements.

@Override
public void addImplementationElements(TopLevelClass topLevelClass) {
    Set<FullyQualifiedJavaType> importedTypes = new TreeSet<FullyQualifiedJavaType>();
    Method method = getMethodShell(importedTypes);
    StringBuilder sb = new StringBuilder();
    if (!introspectedTable.getRules().generatePrimaryKeyClass()) {
        // no primary key class, but primary key is enabled. Primary
        // key columns must be in the base class.
        FullyQualifiedJavaType keyType = new FullyQualifiedJavaType(introspectedTable.getBaseRecordType());
        topLevelClass.addImportedType(keyType);
        sb.setLength(0);
        sb.append(keyType.getShortName());
        //$NON-NLS-1$
        sb.append(" _key = new ");
        sb.append(keyType.getShortName());
        //$NON-NLS-1$
        sb.append("();");
        method.addBodyLine(sb.toString());
        for (IntrospectedColumn introspectedColumn : introspectedTable.getPrimaryKeyColumns()) {
            sb.setLength(0);
            //$NON-NLS-1$
            sb.append("_key.");
            sb.append(getSetterMethodName(introspectedColumn.getJavaProperty()));
            sb.append('(');
            sb.append(introspectedColumn.getJavaProperty());
            //$NON-NLS-1$
            sb.append(");");
            method.addBodyLine(sb.toString());
        }
    }
    sb.setLength(0);
    //$NON-NLS-1$
    sb.append("int rows = ");
    sb.append(daoTemplate.getDeleteMethod(introspectedTable.getIbatis2SqlMapNamespace(), introspectedTable.getDeleteByPrimaryKeyStatementId(), //$NON-NLS-1$
    "_key"));
    method.addBodyLine(sb.toString());
    //$NON-NLS-1$
    method.addBodyLine("return rows;");
    if (context.getPlugins().clientDeleteByPrimaryKeyMethodGenerated(method, topLevelClass, introspectedTable)) {
        topLevelClass.addImportedTypes(importedTypes);
        topLevelClass.addMethod(method);
    }
}
Also used : IntrospectedColumn(org.mybatis.generator.api.IntrospectedColumn) TreeSet(java.util.TreeSet) FullyQualifiedJavaType(org.mybatis.generator.api.dom.java.FullyQualifiedJavaType) Method(org.mybatis.generator.api.dom.java.Method)

Example 82 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 = getMethodShell(importedTypes);
    if (context.getPlugins().clientInsertMethodGenerated(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 83 with FullyQualifiedJavaType

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

the class InsertSelectiveMethodGenerator 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.getInsertSelectiveStatementId(), //$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().clientInsertSelectiveMethodGenerated(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 84 with FullyQualifiedJavaType

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

the class SelectByExampleWithBLOBsMethodGenerator 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.getSelectByExampleWithBLOBsStatementId(), //$NON-NLS-1$
    "example"));
    method.addBodyLine(sb.toString());
    //$NON-NLS-1$
    method.addBodyLine("return list;");
    if (context.getPlugins().clientSelectByExampleWithBLOBsMethodGenerated(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 85 with FullyQualifiedJavaType

use of org.mybatis.generator.api.dom.java.FullyQualifiedJavaType 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)

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