Java Code Examples for org.mybatis.generator.api.dom.java.Method#addBodyLines()
The following examples show how to use
org.mybatis.generator.api.dom.java.Method#addBodyLines() .
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: UpdateByExampleMethodGenerator.java From mapper-generator-javafx with Apache License 2.0 | 5 votes |
@Override public MethodAndImports generateMethodAndImports() { if (!introspectedTable.getRules().generateUpdateByExampleWithBLOBs() && !introspectedTable.getRules().generateUpdateByExampleWithoutBLOBs()) { return null; } Set<FullyQualifiedJavaType> imports = new HashSet<>(); imports.add(new FullyQualifiedJavaType("org.mybatis.dynamic.sql.update.UpdateDSL")); imports.add(new FullyQualifiedJavaType( "org.mybatis.dynamic.sql.update.MyBatis3UpdateModelAdapter")); imports.add(recordType); Method method = new Method("updateByExample"); method.setDefault(true); context.getCommentGenerator().addGeneralMethodAnnotation(method, introspectedTable, imports); FullyQualifiedJavaType returnType = new FullyQualifiedJavaType("UpdateDSL<MyBatis3UpdateModelAdapter<Integer>>"); method.setReturnType(returnType); method.addParameter(new Parameter(recordType, "record")); method.addBodyLine("return UpdateDSL.updateWithMapper(this::update, " + tableFieldName + ")"); method.addBodyLines(fragmentGenerator.getSetEqualLines(introspectedTable.getAllColumns(), true)); return MethodAndImports.withMethod(method) .withImports(imports) .build(); }
Example 2
Source File: AbstractMethodGenerator.java From mapper-generator-javafx with Apache License 2.0 | 5 votes |
protected void acceptParts(MethodAndImports.Builder builder, Method method, MethodParts methodParts) { for (Parameter parameter : methodParts.getParameters()) { method.addParameter(parameter); } for (String annotation : methodParts.getAnnotations()) { method.addAnnotation(annotation); } method.addBodyLines(methodParts.getBodyLines()); builder.withImports(methodParts.getImports()); }
Example 3
Source File: DeleteByPrimaryKeyMethodGenerator.java From mapper-generator-javafx with Apache License 2.0 | 5 votes |
@Override public MethodAndImports generateMethodAndImports() { if (!introspectedTable.getRules().generateDeleteByPrimaryKey()) { return null; } Set<FullyQualifiedJavaType> imports = new HashSet<>(); Set<String> staticImports = new HashSet<>(); imports.add(new FullyQualifiedJavaType("org.mybatis.dynamic.sql.delete.DeleteDSL")); staticImports.add("org.mybatis.dynamic.sql.SqlBuilder.*"); Method method = new Method("deleteByPrimaryKey"); method.setDefault(true); context.getCommentGenerator().addGeneralMethodAnnotation(method, introspectedTable, imports); method.setReturnType(FullyQualifiedJavaType.getIntInstance()); method.addBodyLine("return DeleteDSL.deleteFromWithMapper(this::delete, " + tableFieldName + ")"); MethodParts methodParts = fragmentGenerator.getPrimaryKeyWhereClauseAndParameters(); for (Parameter parameter : methodParts.getParameters()) { method.addParameter(parameter); } method.addBodyLines(methodParts.getBodyLines()); imports.addAll(methodParts.getImports()); method.addBodyLine(" .build()"); method.addBodyLine(" .execute();"); return MethodAndImports.withMethod(method) .withImports(imports) .withStaticImports(staticImports) .build(); }
Example 4
Source File: UpdateByPrimaryKeySelectiveMethodGenerator.java From mapper-generator-javafx with Apache License 2.0 | 5 votes |
@Override public MethodAndImports generateMethodAndImports() { if (!introspectedTable.getRules().generateUpdateByPrimaryKeySelective()) { return null; } Set<FullyQualifiedJavaType> imports = new HashSet<>(); imports.add(new FullyQualifiedJavaType("org.mybatis.dynamic.sql.update.UpdateDSL")); imports.add(recordType); Method method = new Method("updateByPrimaryKeySelective"); method.setDefault(true); context.getCommentGenerator().addGeneralMethodAnnotation(method, introspectedTable, imports); method.setReturnType(FullyQualifiedJavaType.getIntInstance()); method.addParameter(new Parameter(recordType, "record")); method.addBodyLine("return UpdateDSL.updateWithMapper(this::update, " + tableFieldName + ")"); method.addBodyLines( fragmentGenerator.getSetEqualWhenPresentLines(introspectedTable.getNonPrimaryKeyColumns(), false)); method.addBodyLines(fragmentGenerator.getPrimaryKeyWhereClauseForUpdate()); method.addBodyLine(" .build()"); method.addBodyLine(" .execute();"); return MethodAndImports.withMethod(method) .withImports(imports) .build(); }
Example 5
Source File: UpdateByExampleSelectiveMethodGenerator.java From mapper-generator-javafx with Apache License 2.0 | 5 votes |
@Override public MethodAndImports generateMethodAndImports() { if (!introspectedTable.getRules().generateUpdateByExampleSelective()) { return null; } Set<FullyQualifiedJavaType> imports = new HashSet<>(); imports.add(new FullyQualifiedJavaType("org.mybatis.dynamic.sql.update.UpdateDSL")); imports.add(new FullyQualifiedJavaType( "org.mybatis.dynamic.sql.update.MyBatis3UpdateModelAdapter")); imports.add(recordType); Method method = new Method("updateByExampleSelective"); method.setDefault(true); context.getCommentGenerator().addGeneralMethodAnnotation(method, introspectedTable, imports); FullyQualifiedJavaType returnType = new FullyQualifiedJavaType("UpdateDSL<MyBatis3UpdateModelAdapter<Integer>>"); method.setReturnType(returnType); method.addParameter(new Parameter(recordType, "record")); method.addBodyLine("return UpdateDSL.updateWithMapper(this::update, " + tableFieldName + ")"); method.addBodyLines(fragmentGenerator.getSetEqualWhenPresentLines(introspectedTable.getAllColumns(), true)); return MethodAndImports.withMethod(method) .withImports(imports) .build(); }
Example 6
Source File: UpdateByPrimaryKeyMethodGenerator.java From mapper-generator-javafx with Apache License 2.0 | 5 votes |
@Override public MethodAndImports generateMethodAndImports() { if (!introspectedTable.getRules().generateUpdateByPrimaryKeyWithBLOBs() && !introspectedTable.getRules().generateUpdateByPrimaryKeyWithoutBLOBs()) { return null; } Set<FullyQualifiedJavaType> imports = new HashSet<>(); imports.add(new FullyQualifiedJavaType("org.mybatis.dynamic.sql.update.UpdateDSL")); imports.add(recordType); Method method = new Method("updateByPrimaryKey"); method.setDefault(true); context.getCommentGenerator().addGeneralMethodAnnotation(method, introspectedTable, imports); method.setReturnType(FullyQualifiedJavaType.getIntInstance()); method.addParameter(new Parameter(recordType, "record")); method.addBodyLine("return UpdateDSL.updateWithMapper(this::update, " + tableFieldName + ")"); method.addBodyLines(fragmentGenerator.getSetEqualLines(introspectedTable.getNonPrimaryKeyColumns(), false)); method.addBodyLines(fragmentGenerator.getPrimaryKeyWhereClauseForUpdate()); method.addBodyLine(" .build()"); method.addBodyLine(" .execute();"); return MethodAndImports.withMethod(method) .withImports(imports) .build(); }
Example 7
Source File: JavaElementTools.java From mybatis-generator-plugin with Apache License 2.0 | 5 votes |
/** * clone * @param method * @return */ public static Method clone(Method method) { Method dest = new Method(method.getName()); // 注解 for (String javaDocLine : method.getJavaDocLines()) { dest.addJavaDocLine(javaDocLine); } dest.setReturnType(method.getReturnType()); for (Parameter parameter : method.getParameters()) { dest.addParameter(JavaElementTools.clone(parameter)); } for (FullyQualifiedJavaType exception : method.getExceptions()) { dest.addException(exception); } for (TypeParameter typeParameter : method.getTypeParameters()) { dest.addTypeParameter(typeParameter); } dest.addBodyLines(method.getBodyLines()); dest.setConstructor(method.isConstructor()); dest.setNative(method.isNative()); dest.setSynchronized(method.isSynchronized()); dest.setDefault(method.isDefault()); dest.setFinal(method.isFinal()); dest.setStatic(method.isStatic()); dest.setVisibility(method.getVisibility()); return dest; }