org.mybatis.generator.api.dom.java.Parameter Java Examples
The following examples show how to use
org.mybatis.generator.api.dom.java.Parameter.
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: DeleteByExampleMethodGenerator.java From mybatis-generator-plus with Apache License 2.0 | 6 votes |
@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()); method.addParameter(new Parameter(type, "example")); //$NON-NLS-1$ context.getCommentGenerator().addGeneralMethodComment(method, introspectedTable); addMapperAnnotations(interfaze, method); if (context.getPlugins().clientDeleteByExampleMethodGenerated( method, interfaze, introspectedTable)) { interfaze.addImportedTypes(importedTypes); interfaze.addMethod(method); } }
Example #2
Source File: PrimaryKeyGenerator.java From mybatis-generator-core-fix with Apache License 2.0 | 6 votes |
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); StringBuilder sb = new StringBuilder(); for (IntrospectedColumn introspectedColumn : introspectedTable .getPrimaryKeyColumns()) { method.addParameter(new Parameter(introspectedColumn.getFullyQualifiedJavaType(), introspectedColumn.getJavaProperty())); sb.setLength(0); sb.append("this."); //$NON-NLS-1$ sb.append(introspectedColumn.getJavaProperty()); sb.append(" = "); //$NON-NLS-1$ sb.append(introspectedColumn.getJavaProperty()); sb.append(';'); method.addBodyLine(sb.toString()); } topLevelClass.addMethod(method); }
Example #3
Source File: CreateSubPackagePluginTest.java From mybatis-generator-plugins with Apache License 2.0 | 6 votes |
@Test public void shouldRenameMethodParameters() throws Exception { FullyQualifiedJavaType type = new FullyQualifiedJavaType("type"); FullyQualifiedJavaType renamedType = new FullyQualifiedJavaType("renamedType"); Parameter parameter = new Parameter(type, "name", "annotation"); List<Parameter> parameters = new ArrayList<>(); parameters.add(parameter); // Given given(method.getParameters()).willReturn(parameters); given(modelProperties.renameType(eq(type))).willReturn(renamedType); // When boolean ok = plugin.renameMethod(method); // Then assertThat(ok).isTrue(); assertThat(parameters).hasSize(1); Parameter newParameter = parameters.get(0); assertThat(newParameter).isNotSameAs(parameter); assertThat(newParameter.getType()).isEqualTo(renamedType); assertThat(newParameter.getName()).isEqualTo(parameter.getName()); assertThat(newParameter.getAnnotations()).containsExactlyElementsOf(parameter.getAnnotations()); }
Example #4
Source File: UpdateByPrimaryKeyWithoutBLOBsMethodGenerator.java From mybatis-generator-plus with Apache License 2.0 | 6 votes |
@Override public void addInterfaceElements(Interface interfaze) { Set<FullyQualifiedJavaType> importedTypes = new TreeSet<FullyQualifiedJavaType>(); FullyQualifiedJavaType parameterType = new FullyQualifiedJavaType( introspectedTable.getBaseRecordType()); importedTypes.add(parameterType); Method method = new Method(); method.setVisibility(JavaVisibility.PUBLIC); method.setReturnType(FullyQualifiedJavaType.getIntInstance()); method.setName(introspectedTable.getUpdateByPrimaryKeyStatementId()); method.addParameter(new Parameter(parameterType, "record")); //$NON-NLS-1$ context.getCommentGenerator().addGeneralMethodComment(method, introspectedTable); addMapperAnnotations(interfaze, method); if (context.getPlugins() .clientUpdateByPrimaryKeyWithoutBLOBsMethodGenerated(method, interfaze, introspectedTable)) { interfaze.addImportedTypes(importedTypes); interfaze.addMethod(method); } }
Example #5
Source File: RenameExampleClassAndMethodsPlugin.java From mybatis-generator-plugins with Apache License 2.0 | 6 votes |
boolean renameMethod(Method method) { String oldMethodName = method.getName(); Matcher matcher = classMethodPattern.matcher(oldMethodName); String newMethodName = matcher.replaceAll(classMethodReplaceString); method.setName(newMethodName); for (int i = 0; i < method.getParameters().size(); i++) { Parameter parameter = method.getParameters().get(i); String oldParamName = parameter.getName(); matcher = parameterPattern.matcher(oldParamName); if (matcher.lookingAt()) { String newName = matcher.replaceAll(parameterReplaceString); Parameter newParam = new Parameter(parameter.getType(), newName, parameter.isVarargs()); for (String annotation : parameter.getAnnotations()) { newParam.addAnnotation(annotation); } method.getParameters().set(i, newParam); } } return true; }
Example #6
Source File: CountByExampleMethodGenerator.java From mybatis-generator-core-fix with Apache License 2.0 | 6 votes |
@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); method.setReturnType(FullyQualifiedJavaType.getIntInstance()); method.setName(introspectedTable.getCountByExampleStatementId()); method.addParameter(new Parameter(fqjt, "example")); //$NON-NLS-1$ context.getCommentGenerator().addGeneralMethodComment(method, introspectedTable); addMapperAnnotations(interfaze, method); if (context.getPlugins().clientCountByExampleMethodGenerated(method, interfaze, introspectedTable)) { interfaze.addImportedTypes(importedTypes); interfaze.addMethod(method); } }
Example #7
Source File: DeleteByExampleMethodGenerator.java From mybatis-generator-core-fix with Apache License 2.0 | 6 votes |
@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()); method.addParameter(new Parameter(type, "example")); //$NON-NLS-1$ context.getCommentGenerator().addGeneralMethodComment(method, introspectedTable); addMapperAnnotations(interfaze, method); if (context.getPlugins().clientDeleteByExampleMethodGenerated( method, interfaze, introspectedTable)) { interfaze.addImportedTypes(importedTypes); interfaze.addMethod(method); } }
Example #8
Source File: UpdateByPrimaryKeyWithoutBLOBsMethodGenerator.java From mybatis-generator-plus with Apache License 2.0 | 6 votes |
private Method getMethodShell(Set<FullyQualifiedJavaType> importedTypes) { FullyQualifiedJavaType parameterType = new FullyQualifiedJavaType( introspectedTable.getBaseRecordType()); importedTypes.add(parameterType); Method method = new Method(); method.setVisibility(JavaVisibility.PUBLIC); method.setReturnType(FullyQualifiedJavaType.getIntInstance()); method .setName(getDAOMethodNameCalculator() .getUpdateByPrimaryKeyWithoutBLOBsMethodName( introspectedTable)); method.addParameter(new Parameter(parameterType, "record")); //$NON-NLS-1$ for (FullyQualifiedJavaType fqjt : daoTemplate.getCheckedExceptions()) { method.addException(fqjt); importedTypes.add(fqjt); } context.getCommentGenerator().addGeneralMethodComment(method, introspectedTable); return method; }
Example #9
Source File: InsertSelectiveMethodGenerator.java From mybatis-generator-plus with Apache License 2.0 | 6 votes |
@Override public void addInterfaceElements(Interface interfaze) { Set<FullyQualifiedJavaType> importedTypes = new TreeSet<FullyQualifiedJavaType>(); Method method = new Method(); method.setReturnType(FullyQualifiedJavaType.getIntInstance()); method.setVisibility(JavaVisibility.PUBLIC); method.setName(introspectedTable.getInsertSelectiveStatementId()); FullyQualifiedJavaType parameterType = introspectedTable.getRules() .calculateAllFieldsClass(); importedTypes.add(parameterType); method.addParameter(new Parameter(parameterType, "record")); //$NON-NLS-1$ context.getCommentGenerator().addGeneralMethodComment(method, introspectedTable); addMapperAnnotations(interfaze, method); if (context.getPlugins().clientInsertSelectiveMethodGenerated( method, interfaze, introspectedTable)) { interfaze.addImportedTypes(importedTypes); interfaze.addMethod(method); } }
Example #10
Source File: RenameExampleClassAndMethodsPluginTest.java From mybatis-generator-plugins with Apache License 2.0 | 6 votes |
@Test public void shouldRenameMethodParameters() throws Exception { FullyQualifiedJavaType type = new FullyQualifiedJavaType("type"); Parameter parameter = new Parameter(type, PARAM_SEARCH, "annotation"); List<Parameter> parameters = new ArrayList<>(); parameters.add(parameter); // Given given(method.getName()).willReturn(String.format("Some%1$sWith%1$sInName", CLASS_SEARCH)); given(method.getParameters()).willReturn(parameters); // When boolean ok = plugin.renameMethod(method); // Then assertThat(ok).isTrue(); assertThat(parameters).hasSize(1); Parameter newParameter = parameters.get(0); assertThat(newParameter).isNotSameAs(parameter); assertThat(newParameter.getType()).isEqualTo(type); assertThat(newParameter.getName()).isEqualTo(PARAM_REPLACE); assertThat(newParameter.getAnnotations()).containsExactlyElementsOf(parameter.getAnnotations()); }
Example #11
Source File: FragmentGenerator.java From mapper-generator-javafx with Apache License 2.0 | 6 votes |
public MethodParts getPrimaryKeyWhereClauseAndParameters() { MethodParts.Builder builder = new MethodParts.Builder(); boolean first = true; for (IntrospectedColumn column : introspectedTable.getPrimaryKeyColumns()) { String fieldName = AbstractMethodGenerator.calculateFieldName(tableFieldName, column); builder.withImport(column.getFullyQualifiedJavaType()); builder.withParameter(new Parameter( column.getFullyQualifiedJavaType(), column.getJavaProperty() + "_")); if (first) { builder.withBodyLine(" .where(" + fieldName + ", isEqualTo(" + column.getJavaProperty() + "_))"); first = false; } else { builder.withBodyLine(" .and(" + fieldName + ", isEqualTo(" + column.getJavaProperty() + "_))"); } } return builder.build(); }
Example #12
Source File: InsertSelectiveMethodGenerator.java From mybatis-generator-core-fix with Apache License 2.0 | 6 votes |
@Override public void addInterfaceElements(Interface interfaze) { Set<FullyQualifiedJavaType> importedTypes = new TreeSet<FullyQualifiedJavaType>(); Method method = new Method(); method.setReturnType(FullyQualifiedJavaType.getIntInstance()); method.setVisibility(JavaVisibility.PUBLIC); method.setName(introspectedTable.getInsertSelectiveStatementId()); FullyQualifiedJavaType parameterType = introspectedTable.getRules() .calculateAllFieldsClass(); importedTypes.add(parameterType); method.addParameter(new Parameter(parameterType, "record")); //$NON-NLS-1$ context.getCommentGenerator().addGeneralMethodComment(method, introspectedTable); addMapperAnnotations(interfaze, method); if (context.getPlugins().clientInsertSelectiveMethodGenerated( method, interfaze, introspectedTable)) { interfaze.addImportedTypes(importedTypes); interfaze.addMethod(method); } }
Example #13
Source File: WrapObjectPluginTest.java From mybatis-generator-plugins with Apache License 2.0 | 6 votes |
@Test public void shouldReplaceSetterToCallWrappedProperty() throws Exception { Parameter parameter = new Parameter(FullyQualifiedJavaType.getStringInstance(), "name"); List<Parameter> parameters = new ArrayList<>(); parameters.add(parameter); // Given given(introspectedTable.getFullyQualifiedTableNameAtRuntime()).willReturn(TABLE_NAME); given(method.getName()).willReturn("setName"); given(method.getParameters()).willReturn(parameters); plugin.getSettersToWrap().add("setName"); // When boolean ok = plugin.modelSetterMethodGenerated(method, topLevelClass, introspectedColumn, introspectedTable, null); // Then assertThat(ok).isTrue(); assertThat(methodLines).hasSize(1); verify(method).getBodyLines(); verify(method).addBodyLine(anyString()); }
Example #14
Source File: AbstractDAOTemplate.java From mybatis-generator-core-fix with Apache License 2.0 | 6 votes |
/** * Gets the constructor clone. * * @param commentGenerator * the comment generator * @param type * the type * @param introspectedTable * the introspected table * @return the constructor clone */ public final Method getConstructorClone(CommentGenerator commentGenerator, FullyQualifiedJavaType type, IntrospectedTable introspectedTable) { configure(); Method answer = new Method(); answer.setConstructor(true); answer.setName(type.getShortName()); answer.setVisibility(constructorTemplate.getVisibility()); for (Parameter parm : constructorTemplate.getParameters()) { answer.addParameter(parm); } for (String bodyLine : constructorTemplate.getBodyLines()) { answer.addBodyLine(bodyLine); } for (FullyQualifiedJavaType fqjt : constructorTemplate.getExceptions()) { answer.addException(fqjt); } commentGenerator.addGeneralMethodComment(answer, introspectedTable); return answer; }
Example #15
Source File: UpdateByPrimaryKeyWithoutBLOBsMethodGenerator.java From mybatis-generator-core-fix with Apache License 2.0 | 6 votes |
private Method getMethodShell(Set<FullyQualifiedJavaType> importedTypes) { FullyQualifiedJavaType parameterType = new FullyQualifiedJavaType( introspectedTable.getBaseRecordType()); importedTypes.add(parameterType); Method method = new Method(); method.setVisibility(JavaVisibility.PUBLIC); method.setReturnType(FullyQualifiedJavaType.getIntInstance()); method .setName(getDAOMethodNameCalculator() .getUpdateByPrimaryKeyWithoutBLOBsMethodName( introspectedTable)); method.addParameter(new Parameter(parameterType, "record")); //$NON-NLS-1$ for (FullyQualifiedJavaType fqjt : daoTemplate.getCheckedExceptions()) { method.addException(fqjt); importedTypes.add(fqjt); } context.getCommentGenerator().addGeneralMethodComment(method, introspectedTable); return method; }
Example #16
Source File: CreateSubPackagePlugin.java From mybatis-generator-plugins with Apache License 2.0 | 6 votes |
/** * Rename the method types. * * @param method * the method * @return true */ boolean renameMethod(Method method) { method.setReturnType(modelProperties.renameType(method.getReturnType())); for (int i = 0; i < method.getParameters().size(); i++) { Parameter parameter = method.getParameters().get(i); FullyQualifiedJavaType parameterType = parameter.getType(); FullyQualifiedJavaType newParameterType = modelProperties.renameType(parameterType); if (parameterType != newParameterType) { Parameter newParam = new Parameter(newParameterType, parameter.getName(), parameter.isVarargs()); for (String annotation : parameter.getAnnotations()) { newParam.addAnnotation(annotation); } method.getParameters().set(i, newParam); log.debug("set new parameter: [{}][{}]", parameter, newParam); } } modelProperties.renameAnnotations(method.getAnnotations()); mapperProperties.renameAnnotations(method.getAnnotations()); return true; }
Example #17
Source File: DeleteByExampleMethodGenerator.java From mybatis-generator-core-fix with Apache License 2.0 | 6 votes |
private Method getMethodShell(Set<FullyQualifiedJavaType> importedTypes) { FullyQualifiedJavaType type = new FullyQualifiedJavaType( introspectedTable.getExampleType()); importedTypes.add(type); Method method = new Method(); method.setVisibility(getExampleMethodVisibility()); method.setReturnType(FullyQualifiedJavaType.getIntInstance()); method.setName(getDAOMethodNameCalculator() .getDeleteByExampleMethodName(introspectedTable)); method.addParameter(new Parameter(type, "example")); //$NON-NLS-1$ for (FullyQualifiedJavaType fqjt : daoTemplate.getCheckedExceptions()) { method.addException(fqjt); importedTypes.add(fqjt); } context.getCommentGenerator().addGeneralMethodComment(method, introspectedTable); return method; }
Example #18
Source File: GetByKeyBusinessGenerator.java From maven-archetype with GNU Lesser General Public License v2.1 | 6 votes |
public static List<Method> generator(FullyQualifiedJavaType beanType,String beanName, String mapperFieldName,FullyQualifiedJavaType keyType){ List<Method> methodList = new ArrayList<Method>(); // add get by key method Method method = new Method(); method.setVisibility(JavaVisibility.PUBLIC); method.setReturnType(beanType); method.setName("get" + beanName + "ByKey"); //$NON-NLS-1$ method.addParameter(new Parameter(keyType, "key")); //$NON-NLS-1$ method.addException(new FullyQualifiedJavaType(Exception.class.getName())); method.addBodyLine("return this."+ mapperFieldName +".selectByPrimaryKey(key);"); methodList.add(method); // add new method here return methodList; }
Example #19
Source File: CountByExampleMethodGenerator.java From mybatis-generator-plus with Apache License 2.0 | 6 votes |
@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); method.setReturnType(FullyQualifiedJavaType.getIntInstance()); method.setName(introspectedTable.getCountByExampleStatementId()); method.addParameter(new Parameter(fqjt, "example")); //$NON-NLS-1$ context.getCommentGenerator().addGeneralMethodComment(method, introspectedTable); addMapperAnnotations(interfaze, method); if (context.getPlugins().clientCountByExampleMethodGenerated(method, interfaze, introspectedTable)) { interfaze.addImportedTypes(importedTypes); interfaze.addMethod(method); } }
Example #20
Source File: CountByExampleMethodGenerator.java From mapper-generator-javafx with Apache License 2.0 | 6 votes |
@Override public void addInterfaceElements(Interface interfaze) { FullyQualifiedJavaType fqjt = new FullyQualifiedJavaType( introspectedTable.getExampleType()); Set<FullyQualifiedJavaType> importedTypes = new TreeSet<>(); importedTypes.add(fqjt); Method method = new Method(introspectedTable.getCountByExampleStatementId()); method.setVisibility(JavaVisibility.PUBLIC); method.setAbstract(true); method.setReturnType(new FullyQualifiedJavaType("long")); 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); } }
Example #21
Source File: PrimaryKeyGenerator.java From mapper-generator-javafx with Apache License 2.0 | 6 votes |
private void addParameterizedConstructor(TopLevelClass topLevelClass) { Method method = new Method(topLevelClass.getType().getShortName()); method.setVisibility(JavaVisibility.PUBLIC); method.setConstructor(true); context.getCommentGenerator().addGeneralMethodComment(method, introspectedTable); StringBuilder sb = new StringBuilder(); for (IntrospectedColumn introspectedColumn : introspectedTable .getPrimaryKeyColumns()) { method.addParameter(new Parameter(introspectedColumn.getFullyQualifiedJavaType(), introspectedColumn.getJavaProperty())); sb.setLength(0); sb.append("this."); sb.append(introspectedColumn.getJavaProperty()); sb.append(" = "); sb.append(introspectedColumn.getJavaProperty()); sb.append(';'); method.addBodyLine(sb.toString()); } topLevelClass.addMethod(method); }
Example #22
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 #23
Source File: CreateSubPackagePluginTest.java From mybatis-generator-plugins with Apache License 2.0 | 6 votes |
@Test public void shouldIgnoreMethodParametersOfDifferentType() throws Exception { FullyQualifiedJavaType type = new FullyQualifiedJavaType("type"); Parameter parameter = new Parameter(type, "name", "annotation"); List<Parameter> parameters = new ArrayList<>(); parameters.add(parameter); // Given given(method.getParameters()).willReturn(parameters); given(modelProperties.renameType(eq(type))).willReturn(type); // When boolean ok = plugin.renameMethod(method); // Then assertThat(ok).isTrue(); assertThat(parameters).hasSize(1); Parameter newParameter = parameters.get(0); assertThat(newParameter).isSameAs(parameter); }
Example #24
Source File: AbstractDAOTemplate.java From mybatis-generator-plus with Apache License 2.0 | 6 votes |
public final Method getConstructorClone(CommentGenerator commentGenerator, FullyQualifiedJavaType type, IntrospectedTable introspectedTable) { configure(); Method answer = new Method(); answer.setConstructor(true); answer.setName(type.getShortName()); answer.setVisibility(constructorTemplate.getVisibility()); for (Parameter parm : constructorTemplate.getParameters()) { answer.addParameter(parm); } for (String bodyLine : constructorTemplate.getBodyLines()) { answer.addBodyLine(bodyLine); } for (FullyQualifiedJavaType fqjt : constructorTemplate.getExceptions()) { answer.addException(fqjt); } commentGenerator.addGeneralMethodComment(answer, introspectedTable); return answer; }
Example #25
Source File: CaseInsensitiveLikePlugin.java From mapper-generator-javafx with Apache License 2.0 | 6 votes |
private Method toMethod(IntrospectedColumn introspectedColumn) { StringBuilder sb = new StringBuilder(); sb.append(introspectedColumn.getJavaProperty()); sb.setCharAt(0, Character.toUpperCase(sb.charAt(0))); sb.insert(0, "and"); sb.append("LikeInsensitive"); Method method = new Method(sb.toString()); method.setVisibility(JavaVisibility.PUBLIC); method.addParameter(new Parameter(introspectedColumn .getFullyQualifiedJavaType(), "value")); method.setReturnType(FullyQualifiedJavaType.getCriteriaInstance()); sb.setLength(0); sb.append("addCriterion(\"upper("); sb.append(MyBatis3FormattingUtilities .getAliasedActualColumnName(introspectedColumn)); sb.append(") like\", value.toUpperCase(), \""); sb.append(introspectedColumn.getJavaProperty()); sb.append("\");"); method.addBodyLine(sb.toString()); method.addBodyLine("return (Criteria) this;"); return method; }
Example #26
Source File: PrimaryKeyGenerator.java From mybatis-generator-plus with Apache License 2.0 | 6 votes |
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); StringBuilder sb = new StringBuilder(); for (IntrospectedColumn introspectedColumn : introspectedTable .getPrimaryKeyColumns()) { method.addParameter(new Parameter(introspectedColumn.getFullyQualifiedJavaType(), introspectedColumn.getJavaProperty())); sb.setLength(0); sb.append("this."); //$NON-NLS-1$ sb.append(introspectedColumn.getJavaProperty()); sb.append(" = "); //$NON-NLS-1$ sb.append(introspectedColumn.getJavaProperty()); sb.append(';'); method.addBodyLine(sb.toString()); } topLevelClass.addMethod(method); }
Example #27
Source File: CountListBusinessGenerator.java From maven-archetype with GNU Lesser General Public License v2.1 | 6 votes |
public static List<Method> generator(FullyQualifiedJavaType beanType,String beanName, String mapperFieldName,FullyQualifiedJavaType paramType){ List<Method> methodList = new ArrayList<Method>(); // add get by key method Method method = new Method(); method.setVisibility(JavaVisibility.PUBLIC); method.setReturnType(FullyQualifiedJavaType.getIntInstance()); method.setName("count" + beanName + "List"); //$NON-NLS-1$ method.addParameter(new Parameter(paramType, "param")); //$NON-NLS-1$ method.addException(new FullyQualifiedJavaType(Exception.class.getName())); method.addBodyLine("return this."+ mapperFieldName +".countByExample(param);"); methodList.add(method); // add new method here return methodList; }
Example #28
Source File: SelectiveEnhancedPlugin.java From mybatis-generator-plugin with Apache License 2.0 | 6 votes |
/** * insertSelective 方法生成 * 具体执行顺序 http://www.mybatis.org/generator/reference/pluggingIn.html * @param method * @param interfaze * @param introspectedTable * @return */ @Override public boolean clientInsertSelectiveMethodGenerated(Method method, Interface interfaze, IntrospectedTable introspectedTable) { method.getParameters().clear(); FullyQualifiedJavaType parameterType = introspectedTable.getRules().calculateAllFieldsClass(); method.addParameter(new Parameter(parameterType, "record", "@Param(\"record\")")); // 找出全字段对应的Model FullyQualifiedJavaType fullFieldModel = introspectedTable.getRules().calculateAllFieldsClass(); // column枚举 FullyQualifiedJavaType selectiveType = new FullyQualifiedJavaType(fullFieldModel.getShortName() + "." + ModelColumnPlugin.ENUM_NAME); method.addParameter(new Parameter(selectiveType, "selective", "@Param(\"selective\")", true)); FormatTools.replaceGeneralMethodComment(commentGenerator, method, introspectedTable); return super.clientInsertSelectiveMethodGenerated(method, interfaze, introspectedTable); }
Example #29
Source File: DeleteByExampleMethodGenerator.java From mapper-generator-javafx with Apache License 2.0 | 6 votes |
@Override public void addInterfaceElements(Interface interfaze) { Set<FullyQualifiedJavaType> importedTypes = new TreeSet<>(); FullyQualifiedJavaType type = new FullyQualifiedJavaType( introspectedTable.getExampleType()); importedTypes.add(type); Method method = new Method(introspectedTable.getDeleteByExampleStatementId()); method.setVisibility(JavaVisibility.PUBLIC); method.setAbstract(true); method.setReturnType(FullyQualifiedJavaType.getIntInstance()); 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); } }
Example #30
Source File: SelectiveEnhancedPlugin.java From mybatis-generator-plugin with Apache License 2.0 | 5 votes |
@Override public boolean clientUpdateWithVersionByExampleSelectiveMethodGenerated(Method method, Interface interfaze, IntrospectedTable introspectedTable) { // issue#69 OptimisticLockerPlugin 插件updateWithVersionByExampleSelective方法的生成是基于updateByExampleSelective的, // 这个方法在配置了SelectiveEnhancedPlugin时可能已经被先配置的SelectiveEnhancedPlugin改变了 if (!"selective".equals(method.getParameters().get(method.getParameters().size() - 1).getName())) { // column枚举,找出全字段对应的Model FullyQualifiedJavaType fullFieldModel = introspectedTable.getRules().calculateAllFieldsClass(); FullyQualifiedJavaType selectiveType = new FullyQualifiedJavaType(fullFieldModel.getShortName() + "." + ModelColumnPlugin.ENUM_NAME); method.addParameter(new Parameter(selectiveType, "selective", "@Param(\"selective\")", true)); } return true; }