Java Code Examples for org.mybatis.generator.api.dom.java.Method#setDefault()
The following examples show how to use
org.mybatis.generator.api.dom.java.Method#setDefault() .
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: RowBoundsPlugin.java From mapper-generator-javafx with Apache License 2.0 | 6 votes |
private void addNewComposedFunction(Interface interfaze, IntrospectedTable introspectedTable, Optional<FullyQualifiedJavaType> baseMethodReturnType) { if (!baseMethodReturnType.isPresent()) { // shouldn't happen, but just in case... return; } interfaze.addImportedType(new FullyQualifiedJavaType("java.util.function.Function")); FullyQualifiedJavaType returnType = new FullyQualifiedJavaType("Function<SelectStatementProvider, " + baseMethodReturnType.get().getShortName() + ">"); Method method = new Method("selectManyWithRowbounds"); method.setDefault(true); method.setReturnType(returnType); method.addParameter(new Parameter(rowBounds, "rowBounds")); method.addBodyLine( "return selectStatement -> selectManyWithRowbounds(selectStatement, rowBounds);"); context.getCommentGenerator().addGeneralMethodAnnotation( method, introspectedTable, interfaze.getImportedTypes()); interfaze.addMethod(method); }
Example 2
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 3
Source File: DeleteByExampleMethodGenerator.java From mapper-generator-javafx with Apache License 2.0 | 5 votes |
@Override public MethodAndImports generateMethodAndImports() { if (!introspectedTable.getRules().generateDeleteByExample()) { return null; } Set<FullyQualifiedJavaType> imports = new HashSet<>(); imports.add(new FullyQualifiedJavaType("org.mybatis.dynamic.sql.delete.DeleteDSL")); imports.add(new FullyQualifiedJavaType( "org.mybatis.dynamic.sql.delete.MyBatis3DeleteModelAdapter")); Method method = new Method("deleteByExample"); method.setDefault(true); context.getCommentGenerator().addGeneralMethodAnnotation(method, introspectedTable, imports); FullyQualifiedJavaType returnType = new FullyQualifiedJavaType("DeleteDSL<MyBatis3DeleteModelAdapter<Integer>>"); method.setReturnType(returnType); method.addBodyLine( "return DeleteDSL.deleteFromWithMapper(this::delete, " + tableFieldName + ");"); return MethodAndImports.withMethod(method) .withImports(imports) .build(); }
Example 4
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 5
Source File: SelectByPrimaryKeyMethodGenerator.java From mapper-generator-javafx with Apache License 2.0 | 5 votes |
@Override public MethodAndImports generateMethodAndImports() { if (!introspectedTable.getRules().generateSelectByPrimaryKey()) { return null; } Set<FullyQualifiedJavaType> imports = new HashSet<>(); imports.add(new FullyQualifiedJavaType("org.mybatis.dynamic.sql.select.SelectDSL")); imports.add(recordType); Method method = new Method("selectByPrimaryKey"); method.setDefault(true); context.getCommentGenerator().addGeneralMethodAnnotation(method, introspectedTable, imports); method.setReturnType(recordType); StringBuilder sb = new StringBuilder(); sb.append("return SelectDSL.selectWithMapper(this::selectOne, "); sb.append(fragmentGenerator.getSelectList()); sb.append(')'); method.addBodyLine(sb.toString()); method.addBodyLine(" .from(" + tableFieldName + ")"); //$NON-NLS-2$ MethodAndImports.Builder builder = MethodAndImports.withMethod(method) .withStaticImport("org.mybatis.dynamic.sql.SqlBuilder.*") .withImports(imports); MethodParts methodParts = fragmentGenerator.getPrimaryKeyWhereClauseAndParameters(); acceptParts(builder, method, methodParts); method.addBodyLine(" .build()"); method.addBodyLine(" .execute();"); return builder.build(); }
Example 6
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 7
Source File: InsertMethodGenerator.java From mapper-generator-javafx with Apache License 2.0 | 5 votes |
@Override public MethodAndImports generateMethodAndImports() { if (!introspectedTable.getRules().generateInsert()) { 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("insert"); 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); method.addBodyLine(" .map(" + fieldName + ").toProperty(\"" + column.getJavaProperty() + "\")"); } method.addBodyLine(" .build()"); method.addBodyLine(" .render(RenderingStrategy.MYBATIS3));"); return MethodAndImports.withMethod(method) .withImports(imports) .build(); }
Example 8
Source File: SelectDistinctByExampleMethodGenerator.java From mapper-generator-javafx with Apache License 2.0 | 5 votes |
@Override public MethodAndImports generateMethodAndImports() { if (!introspectedTable.getRules().generateSelectByExampleWithBLOBs() && !introspectedTable.getRules().generateSelectByExampleWithoutBLOBs()) { return null; } Set<FullyQualifiedJavaType> imports = new HashSet<>(); imports.add(new FullyQualifiedJavaType("org.mybatis.dynamic.sql.select.QueryExpressionDSL")); imports.add(new FullyQualifiedJavaType( "org.mybatis.dynamic.sql.select.MyBatis3SelectModelAdapter")); imports.add(new FullyQualifiedJavaType("org.mybatis.dynamic.sql.select.SelectDSL")); imports.add(FullyQualifiedJavaType.getNewListInstance()); imports.add(recordType); Method method = new Method("selectDistinctByExample"); method.setDefault(true); context.getCommentGenerator().addGeneralMethodAnnotation(method, introspectedTable, imports); FullyQualifiedJavaType returnType = new FullyQualifiedJavaType("QueryExpressionDSL<MyBatis3SelectModelAdapter<List<" + recordType.getShortNameWithoutTypeArguments() + ">>>"); method.setReturnType(returnType); StringBuilder sb = new StringBuilder(); sb.append("return SelectDSL.selectDistinctWithMapper(this::selectMany, "); sb.append(fragmentGenerator.getSelectList()); sb.append(')'); method.addBodyLine(sb.toString()); method.addBodyLine(" .from(" + tableFieldName + ");"); //$NON-NLS-2$ return MethodAndImports.withMethod(method) .withImports(imports) .build(); }
Example 9
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 10
Source File: SelectByExampleMethodGenerator.java From mapper-generator-javafx with Apache License 2.0 | 5 votes |
@Override public MethodAndImports generateMethodAndImports() { if (!introspectedTable.getRules().generateSelectByExampleWithBLOBs() && !introspectedTable.getRules().generateSelectByExampleWithoutBLOBs()) { return null; } Set<FullyQualifiedJavaType> imports = new HashSet<>(); imports.add(new FullyQualifiedJavaType("org.mybatis.dynamic.sql.select.QueryExpressionDSL")); imports.add(new FullyQualifiedJavaType( "org.mybatis.dynamic.sql.select.MyBatis3SelectModelAdapter")); imports.add(new FullyQualifiedJavaType("org.mybatis.dynamic.sql.select.SelectDSL")); imports.add(FullyQualifiedJavaType.getNewListInstance()); imports.add(recordType); Method method = new Method("selectByExample"); method.setDefault(true); context.getCommentGenerator().addGeneralMethodAnnotation(method, introspectedTable, imports); FullyQualifiedJavaType returnType = new FullyQualifiedJavaType("QueryExpressionDSL<MyBatis3SelectModelAdapter<List<" + recordType.getShortNameWithoutTypeArguments() + ">>>"); method.setReturnType(returnType); StringBuilder sb = new StringBuilder(); sb.append("return SelectDSL.selectWithMapper(this::selectMany, "); sb.append(fragmentGenerator.getSelectList()); sb.append(')'); method.addBodyLine(sb.toString()); method.addBodyLine(" .from(" + tableFieldName + ");"); //$NON-NLS-2$ return MethodAndImports.withMethod(method) .withImports(imports) .build(); }
Example 11
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 12
Source File: CountByExampleMethodGenerator.java From mapper-generator-javafx with Apache License 2.0 | 5 votes |
@Override public MethodAndImports generateMethodAndImports() { if (!introspectedTable.getRules().generateCountByExample()) { return null; } Set<FullyQualifiedJavaType> imports = new HashSet<>(); imports.add(new FullyQualifiedJavaType("org.mybatis.dynamic.sql.select.QueryExpressionDSL")); imports.add(new FullyQualifiedJavaType( "org.mybatis.dynamic.sql.select.MyBatis3SelectModelAdapter")); imports.add(new FullyQualifiedJavaType("org.mybatis.dynamic.sql.SqlBuilder")); imports.add(new FullyQualifiedJavaType("org.mybatis.dynamic.sql.select.SelectDSL")); Method method = new Method("countByExample"); method.setDefault(true); context.getCommentGenerator().addGeneralMethodAnnotation(method, introspectedTable, imports); FullyQualifiedJavaType returnType = new FullyQualifiedJavaType("QueryExpressionDSL<MyBatis3SelectModelAdapter<Long>>"); method.setReturnType(returnType); method.addBodyLine("return SelectDSL.selectWithMapper(this::count, SqlBuilder.count())"); method.addBodyLine(" .from(" + tableFieldName + ");"); //$NON-NLS-2$ return MethodAndImports.withMethod(method) .withImports(imports) .build(); }
Example 13
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; }
Example 14
Source File: InsertSelectiveMethodGenerator.java From mapper-generator-javafx with Apache License 2.0 | 4 votes |
@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(); }