org.mybatis.generator.internal.util.JavaBeansUtil Java Examples

The following examples show how to use org.mybatis.generator.internal.util.JavaBeansUtil. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FullyQualifiedTable.java    From mapper-generator-javafx with Apache License 2.0 6 votes vote down vote up
public String getDomainObjectName() {
    if (stringHasValue(domainObjectName)) {
        return domainObjectName;
    }

    String finalDomainObjectName;
    if (stringHasValue(runtimeTableName)) {
        finalDomainObjectName = JavaBeansUtil.getCamelCaseString(runtimeTableName, true);
    } else {
        finalDomainObjectName = JavaBeansUtil.getCamelCaseString(introspectedTableName, true);
    }

    if (domainObjectRenamingRule != null) {
        Pattern pattern = Pattern.compile(domainObjectRenamingRule.getSearchString());
        String replaceString = domainObjectRenamingRule.getReplaceString();
        replaceString = replaceString == null ? "" : replaceString;
        Matcher matcher = pattern.matcher(finalDomainObjectName);
        finalDomainObjectName = JavaBeansUtil.getFirstCharacterUppercase(matcher.replaceAll(replaceString));
    }
    return finalDomainObjectName;
}
 
Example #2
Source File: DynamicSqlSupportClassGenerator.java    From mapper-generator-javafx with Apache License 2.0 6 votes vote down vote up
private Field calculateTableDefinition(TopLevelClass topLevelClass) {
    FullyQualifiedJavaType fqjt =
            new FullyQualifiedJavaType(introspectedTable.getFullyQualifiedTable().getDomainObjectName());
    String fieldName =
            JavaBeansUtil.getValidPropertyName(introspectedTable.getFullyQualifiedTable().getDomainObjectName());
    Field field = new Field(fieldName, fqjt);
    commentGenerator.addFieldAnnotation(field, introspectedTable, topLevelClass.getImportedTypes());
    field.setVisibility(JavaVisibility.PUBLIC);
    field.setStatic(true);
    field.setFinal(true);
    
    StringBuilder initializationString = new StringBuilder();
    initializationString.append(String.format("new %s()",
            escapeStringForJava(introspectedTable.getFullyQualifiedTable().getDomainObjectName())));
    field.setInitializationString(initializationString.toString());
    return field;
}
 
Example #3
Source File: FragmentGenerator.java    From mapper-generator-javafx with Apache License 2.0 6 votes vote down vote up
public List<String> getPrimaryKeyWhereClauseForUpdate() {
    List<String> lines = new ArrayList<>();
    
    boolean first = true;
    for (IntrospectedColumn column : introspectedTable.getPrimaryKeyColumns()) {
        String fieldName = AbstractMethodGenerator.calculateFieldName(tableFieldName, column);
        String methodName = JavaBeansUtil.getGetterMethodName(
                column.getJavaProperty(), column.getFullyQualifiedJavaType());
        if (first) {
            lines.add("        .where(" + fieldName
                    + ", isEqualTo(record::" + methodName
                    + "))");
            first = false;
        } else {
            lines.add("        .and(" + fieldName
                    + ", isEqualTo(record::" + methodName
                    + "))");
        }
    }
    
    return lines;
}
 
Example #4
Source File: FragmentGenerator.java    From mapper-generator-javafx with Apache License 2.0 6 votes vote down vote up
public List<String> getSetEqualLines(List<IntrospectedColumn> columnList, boolean terminate) {
    List<String> lines = new ArrayList<>();
    List<IntrospectedColumn> columns = ListUtilities.removeIdentityAndGeneratedAlwaysColumns(columnList);
    Iterator<IntrospectedColumn> iter = columns.iterator();
    while (iter.hasNext()) {
        IntrospectedColumn column = iter.next();
        String fieldName = AbstractMethodGenerator.calculateFieldName(tableFieldName, column);
        String methodName = JavaBeansUtil.getGetterMethodName(column.getJavaProperty(),
                column.getFullyQualifiedJavaType());
        String line = "        .set(" + fieldName
                + ").equalTo(record::" + methodName
                + ")";
        if (terminate && !iter.hasNext()) {
            line += ";";
        }
        lines.add(line);
    }
    
    return lines;
}
 
Example #5
Source File: FragmentGenerator.java    From mapper-generator-javafx with Apache License 2.0 6 votes vote down vote up
public List<String> getSetEqualWhenPresentLines(List<IntrospectedColumn> columnList, boolean terminate) {
    List<String> lines = new ArrayList<>();
    List<IntrospectedColumn> columns = ListUtilities.removeIdentityAndGeneratedAlwaysColumns(columnList);
    Iterator<IntrospectedColumn> iter = columns.iterator();
    while (iter.hasNext()) {
        IntrospectedColumn column = iter.next();
        String fieldName = AbstractMethodGenerator.calculateFieldName(tableFieldName, column);
        String methodName = JavaBeansUtil.getGetterMethodName(column.getJavaProperty(),
                column.getFullyQualifiedJavaType());
        String line = "        .set(" + fieldName
                + ").equalToWhenPresent(record::"
                + methodName + ")";
        if (terminate && !iter.hasNext()) {
            line += ";";
        }
        lines.add(line);
    }
    return lines;
}
 
Example #6
Source File: DynamicSqlMapperGenerator.java    From mapper-generator-javafx with Apache License 2.0 5 votes vote down vote up
private void preCalculate() {
    recordType = new FullyQualifiedJavaType(introspectedTable.getBaseRecordType());
    resultMapId = recordType.getShortNameWithoutTypeArguments() + "Result";
    tableFieldName =
            JavaBeansUtil.getValidPropertyName(introspectedTable.getFullyQualifiedTable().getDomainObjectName());
    fragmentGenerator = new FragmentGenerator.Builder()
            .withIntrospectedTable(introspectedTable)
            .withResultMapId(resultMapId)
            .withTableFieldName(tableFieldName)
            .build();
}
 
Example #7
Source File: OptimisticLockerPlugin.java    From mybatis-generator-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * Model builder set 方法生成
 * @param method
 * @param topLevelClass
 * @param builderClass
 * @param introspectedColumn
 * @param introspectedTable
 * @return
 */
@Override
public boolean modelBuilderSetterMethodGenerated(Method method, TopLevelClass topLevelClass, InnerClass builderClass, IntrospectedColumn introspectedColumn, IntrospectedTable introspectedTable) {
    if (this.versionColumn != null && this.customizedNextVersion && introspectedColumn.getActualColumnName().equals(this.versionColumn.getActualColumnName())) {
        // nextVersion 方法
        Method nextVersion = JavaElementGeneratorTools.generateMethod(
                METHOD_NEXT_VERSION,
                JavaVisibility.PUBLIC,
                builderClass.getType(),
                new Parameter(this.versionColumn.getFullyQualifiedJavaType(), "version")
        );
        nextVersion.addAnnotation("@Deprecated");
        commentGenerator.addSetterComment(nextVersion, introspectedTable, this.versionColumn);

        Method setterMethod = JavaBeansUtil.getJavaBeansSetter(this.versionColumn, context, introspectedTable);

        JavaElementGeneratorTools.generateMethodBody(
                nextVersion,
                "obj." + setterMethod.getName() + "(version);",
                "return this;"
        );

        FormatTools.addMethodWithBestPosition(builderClass, nextVersion);
    }

    return true;
}
 
Example #8
Source File: IncrementsPlugin.java    From mybatis-generator-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * Model builder class 生成
 * @param topLevelClass
 * @param builderClass
 * @param columns
 * @param introspectedTable
 * @return
 */
@Override
public boolean modelBuilderClassGenerated(TopLevelClass topLevelClass, InnerClass builderClass, List<IntrospectedColumn> columns, IntrospectedTable introspectedTable) {
    if (this.support()) {
        if (this.incEnum == null) {
            this.incEnum = this.generatedIncEnum(introspectedTable);
            this.incEnumBuilder = builderClass;
            // 增加枚举
            builderClass.addInnerEnum(this.incEnum);
            // topLevel class 添加必要的操作方法
            this.addIncMethodToTopLevelClass(topLevelClass, builderClass, introspectedTable, false);
        }


        // Builder 中 添加字段支持
        for (IntrospectedColumn column : columns) {
            if (this.supportIncrement(column)) {
                Field field = JavaBeansUtil.getJavaBeansField(column, context, introspectedTable);
                // 增加方法
                Method mIncrements = JavaElementGeneratorTools.generateMethod(
                        field.getName(),
                        JavaVisibility.PUBLIC,
                        builderClass.getType(),
                        new Parameter(field.getType(), field.getName()),
                        new Parameter(this.getIncEnum(builderClass, introspectedTable), "inc")
                );
                commentGenerator.addSetterComment(mIncrements, introspectedTable, column);

                Method setterMethod = JavaBeansUtil.getJavaBeansSetter(column, context, introspectedTable);
                mIncrements.addBodyLine("obj." + IncrementsPlugin.FIELD_INC_MAP + ".put(\"" + column.getActualColumnName() + "\", inc);");
                mIncrements.addBodyLine("obj." + setterMethod.getName() + "(" + field.getName() + ");");
                mIncrements.addBodyLine("return this;");

                FormatTools.addMethodWithBestPosition(builderClass, mIncrements);
            }
        }
    }
    return true;
}
 
Example #9
Source File: DynamicSqlSupportClassGenerator.java    From mybatis-generator-plugins with Apache License 2.0 5 votes vote down vote up
private Field calculateTableDefinition(TopLevelClass topLevelClass) {
	FullyQualifiedJavaType fqjt = new FullyQualifiedJavaType(sqlTableClassName);
	String fieldName = JavaBeansUtil.getValidPropertyName(sqlTableClassName);
	Field field = new Field(fieldName, fqjt);
	commentGenerator.addFieldAnnotation(field, introspectedTable, topLevelClass.getImportedTypes());
	field.setVisibility(JavaVisibility.PUBLIC);
	field.setStatic(true);
	field.setFinal(true);

	StringBuilder initializationString = new StringBuilder();
	initializationString.append(String.format("new %s()", //$NON-NLS-1$
			escapeStringForJava(sqlTableClassName)));
	field.setInitializationString(initializationString.toString());
	return field;
}
 
Example #10
Source File: DatabaseIntrospector.java    From mapper-generator-javafx with Apache License 2.0 4 votes vote down vote up
private void calculateExtraColumnInformation(TableConfiguration tc,
        Map<ActualTableName, List<IntrospectedColumn>> columns) {
    StringBuilder sb = new StringBuilder();
    Pattern pattern = null;
    String replaceString = null;
    if (tc.getColumnRenamingRule() != null) {
        pattern = Pattern.compile(tc.getColumnRenamingRule()
                .getSearchString());
        replaceString = tc.getColumnRenamingRule().getReplaceString();
        replaceString = replaceString == null ? "" : replaceString;
    }

    for (Map.Entry<ActualTableName, List<IntrospectedColumn>> entry : columns
            .entrySet()) {
        for (IntrospectedColumn introspectedColumn : entry.getValue()) {
            String calculatedColumnName;
            if (pattern == null) {
                calculatedColumnName = introspectedColumn
                        .getActualColumnName();
            } else {
                Matcher matcher = pattern.matcher(introspectedColumn
                        .getActualColumnName());
                calculatedColumnName = matcher.replaceAll(replaceString);
            }

            if (isTrue(tc
                    .getProperty(PropertyRegistry.TABLE_USE_ACTUAL_COLUMN_NAMES))) {
                introspectedColumn.setJavaProperty(
                        JavaBeansUtil.getValidPropertyName(calculatedColumnName));
            } else if (isTrue(tc
                            .getProperty(PropertyRegistry.TABLE_USE_COMPOUND_PROPERTY_NAMES))) {
                sb.setLength(0);
                sb.append(calculatedColumnName);
                sb.append('_');
                sb.append(JavaBeansUtil.getCamelCaseString(
                        introspectedColumn.getRemarks(), true));
                introspectedColumn.setJavaProperty(
                        JavaBeansUtil.getValidPropertyName(sb.toString()));
            } else {
                introspectedColumn.setJavaProperty(
                        JavaBeansUtil.getCamelCaseString(calculatedColumnName, false));
            }

            FullyQualifiedJavaType fullyQualifiedJavaType = javaTypeResolver
                    .calculateJavaType(introspectedColumn);

            if (fullyQualifiedJavaType != null) {
                introspectedColumn
                        .setFullyQualifiedJavaType(fullyQualifiedJavaType);
                introspectedColumn.setJdbcTypeName(javaTypeResolver
                        .calculateJdbcTypeName(introspectedColumn));
            } else {
                // type cannot be resolved. Check for ignored or overridden
                boolean warn = true;
                if (tc.isColumnIgnored(introspectedColumn
                        .getActualColumnName())) {
                    warn = false;
                }

                ColumnOverride co = tc.getColumnOverride(introspectedColumn
                        .getActualColumnName());
                if (co != null
                        && stringHasValue(co.getJavaType())) {
                    warn = false;
                }

                // if the type is not supported, then we'll report a warning
                if (warn) {
                    introspectedColumn
                            .setFullyQualifiedJavaType(FullyQualifiedJavaType
                                    .getObjectInstance());
                    introspectedColumn.setJdbcTypeName("OTHER");

                    String warning = getString("Warning.14",
                            Integer.toString(introspectedColumn.getJdbcType()),
                            entry.getKey().toString(),
                            introspectedColumn.getActualColumnName());

                    warnings.add(warning);
                }
            }

            if (context.autoDelimitKeywords()
                    && SqlReservedWords.containsWord(introspectedColumn
                        .getActualColumnName())) {
                introspectedColumn.setColumnNameDelimited(true);
            }

            if (tc.isAllColumnDelimitingEnabled()) {
                introspectedColumn.setColumnNameDelimited(true);
            }
        }
    }
}
 
Example #11
Source File: InsertSelectiveMethodGenerator.java    From mapper-generator-javafx with Apache License 2.0 4 votes vote down vote up
@Override
public MethodAndImports generateMethodAndImports() {
    if (!introspectedTable.getRules().generateInsertSelective()) {
        return null;
    }

    Set<FullyQualifiedJavaType> imports = new HashSet<>();
    
    imports.add(new FullyQualifiedJavaType("org.mybatis.dynamic.sql.SqlBuilder"));
    imports.add(new FullyQualifiedJavaType("org.mybatis.dynamic.sql.render.RenderingStrategy"));
    imports.add(recordType);
    
    Method method = new Method("insertSelective");
    method.setDefault(true);
    context.getCommentGenerator().addGeneralMethodAnnotation(method, introspectedTable, imports);
    method.setReturnType(FullyQualifiedJavaType.getIntInstance());
    method.addParameter(new Parameter(recordType, "record"));
    
    method.addBodyLine("return insert(SqlBuilder.insert(record)");
    method.addBodyLine("        .into(" + tableFieldName + ")"); //$NON-NLS-2$
    
    List<IntrospectedColumn> columns = ListUtilities.removeIdentityAndGeneratedAlwaysColumns(
            introspectedTable.getAllColumns());
    for (IntrospectedColumn column : columns) {
        String fieldName = calculateFieldName(column);
        if (column.isSequenceColumn()) {
            method.addBodyLine("        .map(" + fieldName
                    + ").toProperty(\"" + column.getJavaProperty()
                    + "\")");
        } else {
            String methodName =
                    JavaBeansUtil.getGetterMethodName(column.getJavaProperty(),
                            column.getFullyQualifiedJavaType());
            method.addBodyLine("        .map(" + fieldName
                    + ").toPropertyWhenPresent(\"" + column.getJavaProperty()
                    + "\", record::" + methodName
                    + ")");
        }
    }
    
    method.addBodyLine("        .build()");
    method.addBodyLine("        .render(RenderingStrategy.MYBATIS3));");
    
    return MethodAndImports.withMethod(method)
            .withImports(imports)
            .build();
}
 
Example #12
Source File: IncrementPlugin.java    From mybatis-generator-plugin with Apache License 2.0 4 votes vote down vote up
/**
 * 构建Increment Enum
 * @param topLevelClass
 * @param introspectedTable
 * @return
 */
private InnerEnum generateIncrementEnum(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) {
    InnerEnum innerEnum = new InnerEnum(new FullyQualifiedJavaType(ENUM_INCREMENT));
    innerEnum.setVisibility(JavaVisibility.PUBLIC);
    innerEnum.setStatic(true);
    commentGenerator.addEnumComment(innerEnum, introspectedTable);

    // 生成属性和构造函数
    Field columnField = new Field("column", new FullyQualifiedJavaType(ModelColumnPlugin.ENUM_NAME));
    columnField.setVisibility(JavaVisibility.PRIVATE);
    columnField.setFinal(true);
    innerEnum.addField(columnField);

    Method constructor = new Method(ENUM_INCREMENT);
    constructor.setConstructor(true);
    constructor.addBodyLine("this.column = column;");
    constructor.addParameter(new Parameter(new FullyQualifiedJavaType(ModelColumnPlugin.ENUM_NAME), "column"));
    FormatTools.addMethodWithBestPosition(innerEnum, constructor);

    // 属性的Getter方法
    innerEnum.addMethod(JavaElementGeneratorTools.generateGetterMethod(columnField));

    // 添加增减方法
    Method mInc = JavaElementGeneratorTools.generateMethod(
            METHOD_INC,
            JavaVisibility.PUBLIC,
            new FullyQualifiedJavaType(ENUM_INCREMENT + "." + CLASS_INCREMENT_ITEM),
            new Parameter(FullyQualifiedJavaType.getObjectInstance(), "value")
    );
    mInc.addBodyLine("return new " + ENUM_INCREMENT + "." + CLASS_INCREMENT_ITEM + "(this.column, \"+\", value);");
    innerEnum.addMethod(mInc);

    Method mDec = JavaElementGeneratorTools.generateMethod(
            METHOD_DEC,
            JavaVisibility.PUBLIC,
            new FullyQualifiedJavaType(ENUM_INCREMENT + "." + CLASS_INCREMENT_ITEM),
            new Parameter(FullyQualifiedJavaType.getObjectInstance(), "value")
    );
    mDec.addBodyLine("return new " + ENUM_INCREMENT + "." + CLASS_INCREMENT_ITEM + "(this.column, \"-\", value);");
    innerEnum.addMethod(mDec);

    // Enum枚举
    for (IntrospectedColumn introspectedColumn : this.incColumns) {
        Field field = JavaBeansUtil.getJavaBeansField(introspectedColumn, context, introspectedTable);

        StringBuffer sb = new StringBuffer();
        sb.append(field.getName());
        sb.append("(");
        sb.append(ModelColumnPlugin.ENUM_NAME);
        sb.append(".");
        sb.append(field.getName());
        sb.append(")");

        innerEnum.addEnumConstant(sb.toString());
    }


    // 添加内部类IncrementItem
    innerEnum.addInnerClass(this.generateIncrementItemClass(introspectedTable));

    return innerEnum;
}
 
Example #13
Source File: ModelBuilderPlugin.java    From mybatis-generator-plugin with Apache License 2.0 4 votes vote down vote up
/**
 * 生成ModelBuilder
 * @param topLevelClass
 * @param introspectedTable
 * @param columns
 * @return
 */
private InnerClass generateModelBuilder(TopLevelClass topLevelClass, IntrospectedTable introspectedTable, List<IntrospectedColumn> columns) {
    // 生成内部Builder类
    InnerClass innerClass = new InnerClass(BUILDER_CLASS_NAME);
    innerClass.setVisibility(JavaVisibility.PUBLIC);
    innerClass.setStatic(true);
    if (topLevelClass.getSuperClass() != null) {
        innerClass.setSuperClass(topLevelClass.getSuperClass().getShortName() + "." + BUILDER_CLASS_NAME);
    }

    // 具体执行顺序 http://www.mybatis.org/generator/reference/pluggingIn.html
    // 顺序为 key base withBLOBs
    InnerTypeFullyQualifiedJavaType builderType = new InnerTypeFullyQualifiedJavaType(topLevelClass.getType().getFullyQualifiedName() + "." + BUILDER_CLASS_NAME);

    // 增加静态builder方法实现和lombok一样
    Method builder = JavaElementGeneratorTools.generateMethod(
            "builder",
            JavaVisibility.PUBLIC,
            builderType
    );
    commentGenerator.addGeneralMethodComment(builder, introspectedTable);
    builder.setStatic(true);
    builder.addBodyLine("return new " + builderType.getShortName() + "();");
    FormatTools.addMethodWithBestPosition(topLevelClass, builder);

    commentGenerator.addClassComment(innerClass, introspectedTable);
    logger.debug("itfsw(数据Model链式构建插件):" + topLevelClass.getType().getShortName() + "增加内部Builder类。");

    // 构建内部obj变量
    Field f = JavaElementGeneratorTools.generateField("obj", JavaVisibility.PRIVATE, topLevelClass.getType(), null);
    commentGenerator.addFieldComment(f, introspectedTable);
    innerClass.addField(f);

    // 构造构造方法
    Method constructor = new Method(BUILDER_CLASS_NAME);
    constructor.setVisibility(JavaVisibility.PUBLIC);
    constructor.setConstructor(true);
    constructor.addBodyLine(new StringBuilder("this.obj = new ").append(topLevelClass.getType().getShortName()).append("();").toString());
    commentGenerator.addGeneralMethodComment(constructor, introspectedTable);
    FormatTools.addMethodWithBestPosition(innerClass, constructor);
    logger.debug("itfsw(数据Model链式构建插件):" + topLevelClass.getType().getShortName() + ".Builder增加的构造方法。");

    for (IntrospectedColumn introspectedColumn : columns) {
        Field field = JavaBeansUtil.getJavaBeansField(introspectedColumn, context, introspectedTable);
        Method setterMethod = JavaBeansUtil.getJavaBeansSetter(introspectedColumn, context, introspectedTable);

        Method method = JavaElementGeneratorTools.generateMethod(
                field.getName(),
                JavaVisibility.PUBLIC,
                innerClass.getType(),
                new Parameter(field.getType(), field.getName())
        );
        commentGenerator.addSetterComment(method, introspectedTable, introspectedColumn);
        method = JavaElementGeneratorTools.generateMethodBody(
                method,
                "obj." + setterMethod.getName() + "(" + field.getName() + ");",
                "return this;"
        );

        // hook
        if (PluginTools.getHook(IModelBuilderPluginHook.class).modelBuilderSetterMethodGenerated(method, topLevelClass, innerClass, introspectedColumn, introspectedTable)) {
            FormatTools.addMethodWithBestPosition(innerClass, method);
            logger.debug("itfsw(数据Model链式构建插件):" + topLevelClass.getType().getShortName() + ".Builder增加" + method.getName() + "方法(复合主键)。");
        }
    }

    Method build = JavaElementGeneratorTools.generateMethod(
            "build",
            JavaVisibility.PUBLIC,
            topLevelClass.getType()
    );
    build.addBodyLine("return this.obj;");
    commentGenerator.addGeneralMethodComment(build, introspectedTable);
    FormatTools.addMethodWithBestPosition(innerClass, build);
    logger.debug("itfsw(数据Model链式构建插件):" + topLevelClass.getType().getShortName() + ".Builder增加build方法。");

    // hook
    PluginTools.getHook(IModelBuilderPluginHook.class).modelBuilderClassGenerated(topLevelClass, innerClass, columns, introspectedTable);

    return innerClass;
}
 
Example #14
Source File: LogicalDeletePlugin.java    From mybatis-generator-plugin with Apache License 2.0 4 votes vote down vote up
/**
 * 具体执行顺序 http://www.mybatis.org/generator/reference/pluggingIn.html
 * @param field
 * @param topLevelClass
 * @param introspectedColumn
 * @param introspectedTable
 * @param modelClassType
 * @return
 */
@Override
public boolean modelFieldGenerated(Field field, TopLevelClass topLevelClass, IntrospectedColumn introspectedColumn, IntrospectedTable introspectedTable, ModelClassType modelClassType) {
    if (this.logicalDeleteColumn != null) {
        // 常量、枚举和逻辑删除方法跟随 逻辑删除列走
        if (this.logicalDeleteColumn.getJavaProperty().equals(field.getName())) {
            // 1. 添加枚举
            if (PluginTools.getHook(ILogicalDeletePluginHook.class).logicalDeleteEnumGenerated(this.logicalDeleteColumn) == false) {
                topLevelClass.addInnerEnum(this.logicalDeleteEnum);
            }
            // 2. andLogicalDeleted 方法
            Method mAndLogicalDeleted = JavaElementGeneratorTools.generateMethod(
                    METHOD_LOGICAL_DELETED,
                    JavaVisibility.PUBLIC,
                    null,
                    new Parameter(FullyQualifiedJavaType.getBooleanPrimitiveInstance(), "deleted")
            );
            commentGenerator.addGeneralMethodComment(mAndLogicalDeleted, introspectedTable);
            Method logicalDeleteSetter = JavaBeansUtil.getJavaBeansSetter(this.logicalDeleteColumn, context, introspectedTable);
            mAndLogicalDeleted.addBodyLine(logicalDeleteSetter.getName() + "(deleted ? " + this.getEnumConstantValue(true) + " : " + this.getEnumConstantValue(false) + ");");
            FormatTools.addMethodWithBestPosition(topLevelClass, mAndLogicalDeleted);

            // 3. 添加逻辑删除常量
            if (this.enableLogicalDeleteConst) {
                Field logicalUnDeleteConstField = JavaElementGeneratorTools.generateStaticFinalField(
                        this.logicalUnDeleteConstName,
                        this.logicalDeleteColumn.getFullyQualifiedJavaType(),
                        this.getEnumConstantValue(false)
                );
                commentGenerator.addFieldComment(logicalUnDeleteConstField, introspectedTable);
                Field logicalDeleteConstField = JavaElementGeneratorTools.generateStaticFinalField(
                        this.logicalDeleteConstName,
                        this.logicalDeleteColumn.getFullyQualifiedJavaType(),
                        this.getEnumConstantValue(true)
                );
                commentGenerator.addFieldComment(logicalDeleteConstField, introspectedTable);

                // 常量放在字段开头
                ArrayList<Field> fields = (ArrayList<Field>) topLevelClass.getFields();
                fields.add(0, logicalUnDeleteConstField);
                fields.add(0, logicalDeleteConstField);
            }
        }
    }
    return super.modelFieldGenerated(field, topLevelClass, introspectedColumn, introspectedTable, modelClassType);
}