Search in sources :

Example 46 with Parameter

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

the class ProviderInsertSelectiveMethodGenerator method addClassElements.

@Override
public void addClassElements(TopLevelClass topLevelClass) {
    Set<String> staticImports = new TreeSet<String>();
    Set<FullyQualifiedJavaType> importedTypes = new TreeSet<FullyQualifiedJavaType>();
    if (useLegacyBuilder) {
        //$NON-NLS-1$
        staticImports.add("org.apache.ibatis.jdbc.SqlBuilder.BEGIN");
        //$NON-NLS-1$
        staticImports.add("org.apache.ibatis.jdbc.SqlBuilder.INSERT_INTO");
        //$NON-NLS-1$
        staticImports.add("org.apache.ibatis.jdbc.SqlBuilder.SQL");
        //$NON-NLS-1$
        staticImports.add("org.apache.ibatis.jdbc.SqlBuilder.VALUES");
    } else {
        importedTypes.add(NEW_BUILDER_IMPORT);
    }
    FullyQualifiedJavaType fqjt = introspectedTable.getRules().calculateAllFieldsClass();
    importedTypes.add(fqjt);
    Method method = new Method(introspectedTable.getInsertSelectiveStatementId());
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setReturnType(FullyQualifiedJavaType.getStringInstance());
    //$NON-NLS-1$
    method.addParameter(new Parameter(fqjt, "record"));
    context.getCommentGenerator().addGeneralMethodComment(method, introspectedTable);
    if (useLegacyBuilder) {
        //$NON-NLS-1$
        method.addBodyLine("BEGIN();");
    } else {
        //$NON-NLS-1$
        method.addBodyLine("SQL sql = new SQL();");
    }
    method.addBodyLine(//$NON-NLS-1$
    String.format(//$NON-NLS-1$
    "%sINSERT_INTO(\"%s\");", builderPrefix, escapeStringForJava(introspectedTable.getFullyQualifiedTableNameAtRuntime())));
    for (IntrospectedColumn introspectedColumn : ListUtilities.removeIdentityAndGeneratedAlwaysColumns(introspectedTable.getAllColumns())) {
        //$NON-NLS-1$
        method.addBodyLine("");
        if (!introspectedColumn.getFullyQualifiedJavaType().isPrimitive() && !introspectedColumn.isSequenceColumn()) {
            method.addBodyLine(//$NON-NLS-1$
            String.format(//$NON-NLS-1$
            "if (record.%s() != null) {", getGetterMethodName(introspectedColumn.getJavaProperty(), introspectedColumn.getFullyQualifiedJavaType())));
        }
        method.addBodyLine(//$NON-NLS-1$
        String.format(//$NON-NLS-1$
        "%sVALUES(\"%s\", \"%s\");", builderPrefix, escapeStringForJava(getEscapedColumnName(introspectedColumn)), getParameterClause(introspectedColumn)));
        if (!introspectedColumn.getFullyQualifiedJavaType().isPrimitive() && !introspectedColumn.isSequenceColumn()) {
            //$NON-NLS-1$
            method.addBodyLine("}");
        }
    }
    //$NON-NLS-1$
    method.addBodyLine("");
    if (useLegacyBuilder) {
        //$NON-NLS-1$
        method.addBodyLine("return SQL();");
    } else {
        //$NON-NLS-1$
        method.addBodyLine("return sql.toString();");
    }
    if (context.getPlugins().providerInsertSelectiveMethodGenerated(method, topLevelClass, introspectedTable)) {
        topLevelClass.addStaticImports(staticImports);
        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) Parameter(org.mybatis.generator.api.dom.java.Parameter) Method(org.mybatis.generator.api.dom.java.Method)

Example 47 with Parameter

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

the class RecordWithBLOBsGenerator method addParameterizedConstructor.

private void addParameterizedConstructor(TopLevelClass topLevelClass) {
    Method method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setConstructor(true);
    method.setName(topLevelClass.getType().getShortName());
    context.getCommentGenerator().addGeneralMethodComment(method, introspectedTable);
    for (IntrospectedColumn introspectedColumn : introspectedTable.getAllColumns()) {
        method.addParameter(new Parameter(introspectedColumn.getFullyQualifiedJavaType(), introspectedColumn.getJavaProperty()));
        topLevelClass.addImportedType(introspectedColumn.getFullyQualifiedJavaType());
    }
    boolean comma = false;
    StringBuilder sb = new StringBuilder();
    //$NON-NLS-1$
    sb.append("super(");
    for (IntrospectedColumn introspectedColumn : introspectedTable.getNonBLOBColumns()) {
        if (comma) {
            //$NON-NLS-1$
            sb.append(", ");
        } else {
            comma = true;
        }
        sb.append(introspectedColumn.getJavaProperty());
    }
    //$NON-NLS-1$
    sb.append(");");
    method.addBodyLine(sb.toString());
    for (IntrospectedColumn introspectedColumn : introspectedTable.getBLOBColumns()) {
        sb.setLength(0);
        //$NON-NLS-1$
        sb.append("this.");
        sb.append(introspectedColumn.getJavaProperty());
        //$NON-NLS-1$
        sb.append(" = ");
        sb.append(introspectedColumn.getJavaProperty());
        sb.append(';');
        method.addBodyLine(sb.toString());
    }
    topLevelClass.addMethod(method);
}
Also used : IntrospectedColumn(org.mybatis.generator.api.IntrospectedColumn) Parameter(org.mybatis.generator.api.dom.java.Parameter) Method(org.mybatis.generator.api.dom.java.Method)

Example 48 with Parameter

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

the class SimpleModelGenerator method addParameterizedConstructor.

private void addParameterizedConstructor(TopLevelClass topLevelClass) {
    Method method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setConstructor(true);
    method.setName(topLevelClass.getType().getShortName());
    context.getCommentGenerator().addGeneralMethodComment(method, introspectedTable);
    List<IntrospectedColumn> constructorColumns = introspectedTable.getAllColumns();
    for (IntrospectedColumn introspectedColumn : constructorColumns) {
        method.addParameter(new Parameter(introspectedColumn.getFullyQualifiedJavaType(), introspectedColumn.getJavaProperty()));
    }
    StringBuilder sb = new StringBuilder();
    if (introspectedTable.getRules().generatePrimaryKeyClass()) {
        boolean comma = false;
        //$NON-NLS-1$
        sb.append("super(");
        for (IntrospectedColumn introspectedColumn : introspectedTable.getPrimaryKeyColumns()) {
            if (comma) {
                //$NON-NLS-1$
                sb.append(", ");
            } else {
                comma = true;
            }
            sb.append(introspectedColumn.getJavaProperty());
        }
        //$NON-NLS-1$
        sb.append(");");
        method.addBodyLine(sb.toString());
    }
    List<IntrospectedColumn> introspectedColumns = introspectedTable.getAllColumns();
    for (IntrospectedColumn introspectedColumn : introspectedColumns) {
        sb.setLength(0);
        //$NON-NLS-1$
        sb.append("this.");
        sb.append(introspectedColumn.getJavaProperty());
        //$NON-NLS-1$
        sb.append(" = ");
        sb.append(introspectedColumn.getJavaProperty());
        sb.append(';');
        method.addBodyLine(sb.toString());
    }
    topLevelClass.addMethod(method);
}
Also used : IntrospectedColumn(org.mybatis.generator.api.IntrospectedColumn) Parameter(org.mybatis.generator.api.dom.java.Parameter) Method(org.mybatis.generator.api.dom.java.Method)

Example 49 with Parameter

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

the class CountByExampleMethodGenerator method addInterfaceElements.

@Override
public void addInterfaceElements(Interface interfaze) {
    FullyQualifiedJavaType fqjt = new FullyQualifiedJavaType(introspectedTable.getExampleType());
    Set<FullyQualifiedJavaType> importedTypes = new TreeSet<FullyQualifiedJavaType>();
    importedTypes.add(fqjt);
    Method method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    //$NON-NLS-1$
    method.setReturnType(new FullyQualifiedJavaType("long"));
    method.setName(introspectedTable.getCountByExampleStatementId());
    //$NON-NLS-1$
    method.addParameter(new Parameter(fqjt, "example"));
    context.getCommentGenerator().addGeneralMethodComment(method, introspectedTable);
    addMapperAnnotations(method);
    if (context.getPlugins().clientCountByExampleMethodGenerated(method, interfaze, introspectedTable)) {
        addExtraImports(interfaze);
        interfaze.addImportedTypes(importedTypes);
        interfaze.addMethod(method);
    }
}
Also used : FullyQualifiedJavaType(org.mybatis.generator.api.dom.java.FullyQualifiedJavaType) TreeSet(java.util.TreeSet) Parameter(org.mybatis.generator.api.dom.java.Parameter) Method(org.mybatis.generator.api.dom.java.Method)

Example 50 with Parameter

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

the class DeleteByExampleMethodGenerator method addInterfaceElements.

@Override
public void addInterfaceElements(Interface interfaze) {
    Set<FullyQualifiedJavaType> importedTypes = new TreeSet<FullyQualifiedJavaType>();
    FullyQualifiedJavaType type = new FullyQualifiedJavaType(introspectedTable.getExampleType());
    importedTypes.add(type);
    Method method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setReturnType(FullyQualifiedJavaType.getIntInstance());
    method.setName(introspectedTable.getDeleteByExampleStatementId());
    //$NON-NLS-1$
    method.addParameter(new Parameter(type, "example"));
    context.getCommentGenerator().addGeneralMethodComment(method, introspectedTable);
    addMapperAnnotations(method);
    if (context.getPlugins().clientDeleteByExampleMethodGenerated(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)

Aggregations

Parameter (org.mybatis.generator.api.dom.java.Parameter)68 Method (org.mybatis.generator.api.dom.java.Method)66 FullyQualifiedJavaType (org.mybatis.generator.api.dom.java.FullyQualifiedJavaType)55 TreeSet (java.util.TreeSet)20 IntrospectedColumn (org.mybatis.generator.api.IntrospectedColumn)17 Field (org.mybatis.generator.api.dom.java.Field)11 ArrayList (java.util.ArrayList)7 InnerClass (org.mybatis.generator.api.dom.java.InnerClass)5 TopLevelClass (org.mybatis.generator.api.dom.java.TopLevelClass)5 Messages.getString (org.mybatis.generator.internal.util.messages.Messages.getString)4 CompilationUnit (org.mybatis.generator.api.dom.java.CompilationUnit)3 CommentGenerator (org.mybatis.generator.api.CommentGenerator)2 FullyQualifiedTable (org.mybatis.generator.api.FullyQualifiedTable)2 Interface (org.mybatis.generator.api.dom.java.Interface)2 DAOMethodNameCalculator (org.mybatis.generator.api.DAOMethodNameCalculator)1 Rules (org.mybatis.generator.internal.rules.Rules)1