Java Code Examples for org.mybatis.generator.api.dom.java.Method#addAnnotation()
The following examples show how to use
org.mybatis.generator.api.dom.java.Method#addAnnotation() .
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: OptimisticLockingPluginTest.java From mybatis-generator-plugins with Apache License 2.0 | 6 votes |
@Test public void shouldAddConditionToWhereClauseInAnnotation() { // Given Method realMethod = new Method("methodName"); realMethod.addAnnotation("@Update({"); realMethod.addAnnotation(" \"update schema.table_name\","); realMethod.addAnnotation(" \"set id = #{id,jdbcType=INT},\","); realMethod.addAnnotation(" \"other_column = #{other,jdbcType=INT},\","); realMethod.addAnnotation(" \"where id = #{id,jdbcType=BIGINT}\""); realMethod.addAnnotation("})"); // When Method newMethod = plugin.addMethod(realMethod, introspectedTable); // Then then(newMethod).isNotNull(); then(newMethod.getName()).isEqualTo(realMethod.getName() + OptimisticLockingPlugin.METHOD_SUFFIX); then(newMethod.getAnnotations()).hasSize(realMethod.getAnnotations().size() + 1); then(newMethod.getAnnotations()).containsAll(realMethod.getAnnotations().subList(0, 4)); then(newMethod.getAnnotations().get(4)).isEqualTo(realMethod.getAnnotations().get(4) + ","); then(newMethod.getAnnotations().get(5)).contains(String.format("and %s = ", LOCK_COLUMN_FUNCTION)); then(newMethod.getAnnotations().get(6)).isEqualTo(realMethod.getAnnotations().get(5)); }
Example 2
Source File: OptimisticLockingPluginTest.java From mybatis-generator-plugins with Apache License 2.0 | 6 votes |
@Test public void shouldSetCorrectTypeHandler() { // Given String typeHandler = "some.type.Handler"; given(modificationDate.getTypeHandler()).willReturn(typeHandler); Method realMethod = new Method("methodName"); realMethod.addAnnotation("@Update({"); realMethod.addAnnotation(" \"update schema.table_name\","); realMethod.addAnnotation(" \"set id = #{id,jdbcType=INT},\","); realMethod.addAnnotation(" \"other_column = #{other,jdbcType=INT},\","); realMethod.addAnnotation(" \"where id = #{id,jdbcType=BIGINT}\""); realMethod.addAnnotation("})"); // When Method newMethod = plugin.addMethod(realMethod, introspectedTable); // Then then(newMethod.getAnnotations().get(5)).contains(typeHandler); }
Example 3
Source File: AnnotatedUpdateByExampleWithoutBLOBsMethodGenerator.java From mybatis-generator-plus with Apache License 2.0 | 5 votes |
@Override public void addMapperAnnotations(Interface interfaze, Method method) { FullyQualifiedJavaType fqjt = new FullyQualifiedJavaType(introspectedTable.getMyBatis3SqlProviderType()); interfaze.addImportedType(new FullyQualifiedJavaType("org.apache.ibatis.annotations.UpdateProvider")); //$NON-NLS-1$ StringBuilder sb = new StringBuilder(); sb.append("@UpdateProvider(type="); //$NON-NLS-1$ sb.append(fqjt.getShortName()); sb.append(".class, method=\""); //$NON-NLS-1$ sb.append(introspectedTable.getUpdateByExampleStatementId()); sb.append("\")"); //$NON-NLS-1$ method.addAnnotation(sb.toString()); }
Example 4
Source File: GetByKeyControllerGenerator.java From maven-archetype with GNU Lesser General Public License v2.1 | 5 votes |
public static List<Method> generator(FullyQualifiedJavaType beanType,String beanName, String businessFieldName,FullyQualifiedJavaType keyType, String keyFiledName){ List<Method> methodList = new ArrayList<Method>(); Method method = new Method(); method.addAnnotation("@RequestMapping(value = \"get" + beanName + "ByKey.do\")"); method.addAnnotation("@ResponseBody"); method.setVisibility(JavaVisibility.PUBLIC); method.setReturnType(new FullyQualifiedJavaType(AjaxResponseBean.class.getName())); method.setName("get" + beanName + "ByKey"); Parameter param = new Parameter(keyType, keyFiledName); param.addAnnotation("@RequestParam(\"" + keyFiledName + "\") "); method.addParameter(param); // 方法body method.addBodyLine("try {"); method.addBodyLine("if(" + keyFiledName + " == null || " + keyFiledName + " < 0){"); method.addBodyLine("return AjaxResponseBean.Const.PARAMETER_INVALID_ERROR_RESPONSE_BEAN; "); method.addBodyLine("}"); method.addBodyLine(beanName + " result = this."+ businessFieldName +".get"+ beanName +"ByKey(" + keyFiledName + ");"); method.addBodyLine("return AjaxResponseBean.getReturnValueResponseBean(result);"); method.addBodyLine("} catch (Exception e) {"); method.addBodyLine("logger.error(\"主键获取详情异常;key=\"+" + keyFiledName + " + e.getMessage());"); method.addBodyLine("return AjaxResponseBean.getErrorResponseBean(\"主键获取详情异常;key=\"+" + keyFiledName + " + e.getMessage());"); method.addBodyLine("}"); methodList.add(method); return methodList; }
Example 5
Source File: UpdateControllerGenerator.java From maven-archetype with GNU Lesser General Public License v2.1 | 5 votes |
public static List<Method> generator(FullyQualifiedJavaType beanType,String beanName, String businessFieldName){ List<Method> methodList = new ArrayList<Method>(); String beanFiledName = StringUtils.uncapitalize(beanName); Method method = new Method(); method.addAnnotation("@RequestMapping(value = \"updateSave" + beanName + ".do\")"); method.setVisibility(JavaVisibility.PUBLIC); method.setReturnType(new FullyQualifiedJavaType(String.class.getName())); method.setName("updateSave" + beanName); Parameter param1 = new Parameter(beanType, beanFiledName); param1.addAnnotation("@ModelAttribute "); Parameter paramModelMap = new Parameter(new FullyQualifiedJavaType(ModelMap.class.getName()), "map"); method.addParameter(param1); method.addParameter(paramModelMap); // 方法body method.addBodyLine("try {"); method.addBodyLine("if(" + beanFiledName + " == null ){"); method.addBodyLine("// || NumberUtil.isNotPositive(" + beanFiledName + ".getId())){"); method.addBodyLine("map.put(\"message\",\"更新对象为空。\");"); method.addBodyLine(ControllerPluginUtil.RETURN); method.addBodyLine("}"); method.addBodyLine("int updateCount = this." + businessFieldName + ".update(" + beanFiledName + ");"); method.addBodyLine("if(updateCount == 1 ){"); method.addBodyLine("map.put(\"message\",\"更新成功。\");"); method.addBodyLine("}else{"); method.addBodyLine("map.put(\"message\",\"更新失败。\");"); method.addBodyLine("}"); method.addBodyLine("} catch (Exception e) {"); method.addBodyLine("logger.error(\"更新异常\" + e.getMessage());"); method.addBodyLine("map.put(\"message\", \"查询异常\" + e.getMessage());"); method.addBodyLine("}"); method.addBodyLine(ControllerPluginUtil.RETURN); methodList.add(method); return methodList; }
Example 6
Source File: BatchUpdateControllerGenerator.java From maven-archetype with GNU Lesser General Public License v2.1 | 5 votes |
public static List<Method> generator(FullyQualifiedJavaType innerClassType,String beanName, String businessFieldName){ List<Method> methodList = new ArrayList<Method>(); String innerClassFiledName = StringUtils.uncapitalize(innerClassType.getShortName()); Method method = new Method(); method.addAnnotation("@RequestMapping(value = \"batchUpdateSave" + beanName + ".do\")"); method.setVisibility(JavaVisibility.PUBLIC); method.setReturnType(new FullyQualifiedJavaType(String.class.getName())); method.setName("batchUpdateSave" + beanName); Parameter param1 = new Parameter(innerClassType, innerClassFiledName); param1.addAnnotation("@ModelAttribute "); Parameter paramModelMap = new Parameter(new FullyQualifiedJavaType(ModelMap.class.getName()), "map"); method.addParameter(param1); method.addParameter(paramModelMap); // 方法body method.addBodyLine("try {"); method.addBodyLine("if(" + innerClassFiledName + " != null && CollectionUtil.isNotNull(" + innerClassFiledName + ".get"+ beanName + "List())){"); method.addBodyLine("int updateCount = this." + businessFieldName + ".update(" + innerClassFiledName + ".get"+ beanName + "List());"); method.addBodyLine("if(updateCount >0 ){"); method.addBodyLine("map.put(\"message\",\"更新成功。\");"); method.addBodyLine("}else{"); method.addBodyLine("map.put(\"message\",\"更新失败。\");"); method.addBodyLine("}"); method.addBodyLine("}"); method.addBodyLine("} catch (Exception e) {"); method.addBodyLine("logger.error(\"批量更新异常\" + e.getMessage());"); method.addBodyLine("map.put(\"message\", \"批量更新异常\" + e.getMessage());"); method.addBodyLine("}"); method.addBodyLine(ControllerPluginUtil.RETURN); methodList.add(method); return methodList; }
Example 7
Source File: AnnotatedUpdateByExampleWithoutBLOBsMethodGenerator.java From mybatis-generator-core-fix with Apache License 2.0 | 5 votes |
@Override public void addMapperAnnotations(Interface interfaze, Method method) { FullyQualifiedJavaType fqjt = new FullyQualifiedJavaType(introspectedTable.getMyBatis3SqlProviderType()); interfaze.addImportedType(new FullyQualifiedJavaType("org.apache.ibatis.annotations.UpdateProvider")); //$NON-NLS-1$ StringBuilder sb = new StringBuilder(); sb.append("@UpdateProvider(type="); //$NON-NLS-1$ sb.append(fqjt.getShortName()); sb.append(".class, method=\""); //$NON-NLS-1$ sb.append(introspectedTable.getUpdateByExampleStatementId()); sb.append("\")"); //$NON-NLS-1$ method.addAnnotation(sb.toString()); }
Example 8
Source File: AnnotatedUpdateByExampleSelectiveMethodGenerator.java From mybatis-generator-plus with Apache License 2.0 | 5 votes |
@Override public void addMapperAnnotations(Interface interfaze, Method method) { FullyQualifiedJavaType fqjt = new FullyQualifiedJavaType(introspectedTable.getMyBatis3SqlProviderType()); interfaze.addImportedType(new FullyQualifiedJavaType("org.apache.ibatis.annotations.UpdateProvider")); //$NON-NLS-1$ StringBuilder sb = new StringBuilder(); sb.append("@UpdateProvider(type="); //$NON-NLS-1$ sb.append(fqjt.getShortName()); sb.append(".class, method=\""); //$NON-NLS-1$ sb.append(introspectedTable.getUpdateByExampleSelectiveStatementId()); sb.append("\")"); //$NON-NLS-1$ method.addAnnotation(sb.toString()); }
Example 9
Source File: AnnotatedUpdateByPrimaryKeySelectiveMethodGenerator.java From mybatis-generator-plus with Apache License 2.0 | 5 votes |
@Override public void addMapperAnnotations(Interface interfaze, Method method) { FullyQualifiedJavaType fqjt = new FullyQualifiedJavaType(introspectedTable.getMyBatis3SqlProviderType()); interfaze.addImportedType(new FullyQualifiedJavaType("org.apache.ibatis.annotations.UpdateProvider")); //$NON-NLS-1$ StringBuilder sb = new StringBuilder(); sb.append("@UpdateProvider(type="); //$NON-NLS-1$ sb.append(fqjt.getShortName()); sb.append(".class, method=\""); //$NON-NLS-1$ sb.append(introspectedTable.getUpdateByPrimaryKeySelectiveStatementId()); sb.append("\")"); //$NON-NLS-1$ method.addAnnotation(sb.toString()); }
Example 10
Source File: AnnotatedDeleteByPrimaryKeyMethodGenerator.java From mapper-generator-javafx with Apache License 2.0 | 5 votes |
@Override public void addMapperAnnotations(Method method) { method.addAnnotation("@Delete({"); StringBuilder sb = new StringBuilder(); javaIndent(sb, 1); sb.append("\"delete from "); sb.append(escapeStringForJava( introspectedTable.getFullyQualifiedTableNameAtRuntime())); sb.append("\","); method.addAnnotation(sb.toString()); boolean and = false; Iterator<IntrospectedColumn> iter = introspectedTable.getPrimaryKeyColumns().iterator(); while (iter.hasNext()) { sb.setLength(0); javaIndent(sb, 1); if (and) { sb.append(" \"and "); } else { sb.append("\"where "); and = true; } IntrospectedColumn introspectedColumn = iter.next(); sb.append(escapeStringForJava( getEscapedColumnName(introspectedColumn))); sb.append(" = "); sb.append(getParameterClause(introspectedColumn)); sb.append('\"'); if (iter.hasNext()) { sb.append(','); } method.addAnnotation(sb.toString()); } method.addAnnotation("})"); }
Example 11
Source File: AnnotatedUpdateByExampleWithBLOBsMethodGenerator.java From mybatis-generator-core-fix with Apache License 2.0 | 5 votes |
@Override public void addMapperAnnotations(Interface interfaze, Method method) { FullyQualifiedJavaType fqjt = new FullyQualifiedJavaType(introspectedTable.getMyBatis3SqlProviderType()); interfaze.addImportedType(new FullyQualifiedJavaType("org.apache.ibatis.annotations.UpdateProvider")); //$NON-NLS-1$ StringBuilder sb = new StringBuilder(); sb.append("@UpdateProvider(type="); //$NON-NLS-1$ sb.append(fqjt.getShortName()); sb.append(".class, method=\""); //$NON-NLS-1$ sb.append(introspectedTable.getUpdateByExampleWithBLOBsStatementId()); sb.append("\")"); //$NON-NLS-1$ method.addAnnotation(sb.toString()); }
Example 12
Source File: AnnotatedUpdateByPrimaryKeySelectiveMethodGenerator.java From mapper-generator-javafx with Apache License 2.0 | 5 votes |
@Override public void addMapperAnnotations(Method method) { FullyQualifiedJavaType fqjt = new FullyQualifiedJavaType(introspectedTable.getMyBatis3SqlProviderType()); StringBuilder sb = new StringBuilder(); sb.append("@UpdateProvider(type="); sb.append(fqjt.getShortName()); sb.append(".class, method=\""); sb.append(introspectedTable.getUpdateByPrimaryKeySelectiveStatementId()); sb.append("\")"); method.addAnnotation(sb.toString()); }
Example 13
Source File: ToStringPlugin.java From mybatis-generator-plus with Apache License 2.0 | 5 votes |
private void generateToString(IntrospectedTable introspectedTable, TopLevelClass topLevelClass) { Method method = new Method(); method.setVisibility(JavaVisibility.PUBLIC); method.setReturnType(FullyQualifiedJavaType.getStringInstance()); method.setName("toString"); //$NON-NLS-1$ if (introspectedTable.isJava5Targeted()) { method.addAnnotation("@Override"); //$NON-NLS-1$ } context.getCommentGenerator().addGeneralMethodComment(method, introspectedTable); method.addBodyLine("StringBuilder sb = new StringBuilder();"); //$NON-NLS-1$ method.addBodyLine("sb.append(getClass().getSimpleName());"); //$NON-NLS-1$ method.addBodyLine("sb.append(\" [\");"); //$NON-NLS-1$ method.addBodyLine("sb.append(\"Hash = \").append(hashCode());"); //$NON-NLS-1$ StringBuilder sb = new StringBuilder(); for (Field field : topLevelClass.getFields()) { String property = field.getName(); sb.setLength(0); sb.append("sb.append(\"").append(", ").append(property) //$NON-NLS-1$ //$NON-NLS-2$ .append("=\")").append(".append(").append(property) //$NON-NLS-1$ //$NON-NLS-2$ .append(");"); //$NON-NLS-1$ method.addBodyLine(sb.toString()); } method.addBodyLine("sb.append(\"]\");"); //$NON-NLS-1$ method.addBodyLine("return sb.toString();"); //$NON-NLS-1$ topLevelClass.addMethod(method); }
Example 14
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 15
Source File: BasicUpdateMethodGenerator.java From mapper-generator-javafx with Apache License 2.0 | 5 votes |
@Override public MethodAndImports generateMethodAndImports() { if (!introspectedTable.getRules().generateUpdateByExampleSelective() && !introspectedTable.getRules().generateUpdateByExampleWithBLOBs() && !introspectedTable.getRules().generateUpdateByExampleWithoutBLOBs() && !introspectedTable.getRules().generateUpdateByPrimaryKeySelective() && !introspectedTable.getRules().generateUpdateByPrimaryKeyWithBLOBs() && !introspectedTable.getRules().generateUpdateByPrimaryKeyWithoutBLOBs()) { return null; } Set<FullyQualifiedJavaType> imports = new HashSet<>(); FullyQualifiedJavaType parameterType = new FullyQualifiedJavaType( "org.mybatis.dynamic.sql.update.render.UpdateStatementProvider"); FullyQualifiedJavaType adapter = new FullyQualifiedJavaType("org.mybatis.dynamic.sql.util.SqlProviderAdapter"); FullyQualifiedJavaType annotation = new FullyQualifiedJavaType("org.apache.ibatis.annotations.UpdateProvider"); imports.add(parameterType); imports.add(adapter); imports.add(annotation); Method method = new Method("update"); method.setAbstract(true); method.setReturnType(FullyQualifiedJavaType.getIntInstance()); method.addParameter(new Parameter(parameterType, "updateStatement")); context.getCommentGenerator().addGeneralMethodAnnotation(method, introspectedTable, imports); method.addAnnotation("@UpdateProvider(type=SqlProviderAdapter.class, method=\"update\")"); return MethodAndImports.withMethod(method) .withImports(imports) .build(); }
Example 16
Source File: UpdateControllerGenerator.java From maven-archetype with GNU Lesser General Public License v2.1 | 5 votes |
public static List<Method> generator(FullyQualifiedJavaType beanType,String beanName, String businessFieldName){ List<Method> methodList = new ArrayList<Method>(); String beanFiledName = StringUtils.uncapitalize(beanName); Method method = new Method(); method.addAnnotation("@RequestMapping(value = \"updateSave" + beanName + ".do\")"); method.addAnnotation("@ResponseBody"); method.setVisibility(JavaVisibility.PUBLIC); method.setReturnType(new FullyQualifiedJavaType(AjaxResponseBean.class.getName())); method.setName("updateSave" + beanName); Parameter param1 = new Parameter(beanType, beanFiledName); param1.addAnnotation("@ModelAttribute "); method.addParameter(param1); // 方法body method.addBodyLine("try {"); method.addBodyLine("if(" + beanFiledName + " == null ){"); method.addBodyLine("// || NumberUtil.isNotPositive(" + beanFiledName + ".getId())){"); method.addBodyLine("return AjaxResponseBean.Const.PARAMETER_INVALID_ERROR_RESPONSE_BEAN;"); method.addBodyLine("}"); method.addBodyLine("int updateCount = this." + businessFieldName + ".update(" + beanFiledName + ");"); method.addBodyLine("if(updateCount >0 ){"); method.addBodyLine("return AjaxResponseBean.Const.SUCCESS_RESPONSE_BEAN;"); method.addBodyLine("}"); method.addBodyLine("return AjaxResponseBean.Const.ERROR_RESPONSE_BEAN;"); method.addBodyLine("} catch (Exception e) {"); method.addBodyLine("logger.error(\"更新异常\" + e.getMessage());"); method.addBodyLine("return AjaxResponseBean.getErrorResponseBean(\"更新异常\" + e.getMessage());"); method.addBodyLine("}"); methodList.add(method); return methodList; }
Example 17
Source File: AnnotatedSelectAllMethodGenerator.java From mybatis-generator-core-fix with Apache License 2.0 | 4 votes |
@Override public void addMapperAnnotations(Interface interfaze, Method method) { interfaze.addImportedType(new FullyQualifiedJavaType("org.apache.ibatis.annotations.Select")); //$NON-NLS-1$ StringBuilder sb = new StringBuilder(); method.addAnnotation("@Select({"); //$NON-NLS-1$ javaIndent(sb, 1); sb.append("\"select\","); //$NON-NLS-1$ method.addAnnotation(sb.toString()); Iterator<IntrospectedColumn> iter = introspectedTable .getAllColumns().iterator(); sb.setLength(0); javaIndent(sb, 1); sb.append('"'); boolean hasColumns = false; while (iter.hasNext()) { sb.append(escapeStringForJava(getSelectListPhrase(iter.next()))); hasColumns = true; if (iter.hasNext()) { sb.append(", "); //$NON-NLS-1$ } if (sb.length() > 80) { sb.append("\","); //$NON-NLS-1$ method.addAnnotation(sb.toString()); sb.setLength(0); javaIndent(sb, 1); sb.append('"'); hasColumns = false; } } if (hasColumns) { sb.append("\","); //$NON-NLS-1$ method.addAnnotation(sb.toString()); } String orderByClause = introspectedTable.getTableConfigurationProperty(PropertyRegistry.TABLE_SELECT_ALL_ORDER_BY_CLAUSE); boolean hasOrderBy = StringUtility.stringHasValue(orderByClause); sb.setLength(0); javaIndent(sb, 1); sb.append("\"from "); //$NON-NLS-1$ sb.append(escapeStringForJava(introspectedTable .getAliasedFullyQualifiedTableNameAtRuntime())); sb.append('\"'); if (hasOrderBy) { sb.append(','); } method.addAnnotation(sb.toString()); if (hasOrderBy) { sb.setLength(0); javaIndent(sb, 1); sb.append("\"order by "); //$NON-NLS-1$ sb.append(orderByClause); sb.append('\"'); method.addAnnotation(sb.toString()); } method.addAnnotation("})"); //$NON-NLS-1$ addAnnotatedResults(interfaze, method); }
Example 18
Source File: AnnotatedSelectByPrimaryKeyMethodGenerator.java From mybatis-generator-core-fix with Apache License 2.0 | 4 votes |
@Override public void addMapperAnnotations(Interface interfaze, Method method) { interfaze.addImportedType(new FullyQualifiedJavaType("org.apache.ibatis.annotations.Select")); //$NON-NLS-1$ StringBuilder sb = new StringBuilder(); method.addAnnotation("@Select({"); //$NON-NLS-1$ javaIndent(sb, 1); sb.append("\"select\","); //$NON-NLS-1$ method.addAnnotation(sb.toString()); Iterator<IntrospectedColumn> iter = introspectedTable .getAllColumns().iterator(); sb.setLength(0); javaIndent(sb, 1); sb.append('"'); boolean hasColumns = false; while (iter.hasNext()) { sb.append(escapeStringForJava(getSelectListPhrase(iter.next()))); hasColumns = true; if (iter.hasNext()) { sb.append(", "); //$NON-NLS-1$ } if (sb.length() > 80) { sb.append("\","); //$NON-NLS-1$ method.addAnnotation(sb.toString()); sb.setLength(0); javaIndent(sb, 1); sb.append('"'); hasColumns = false; } } if (hasColumns) { sb.append("\","); //$NON-NLS-1$ method.addAnnotation(sb.toString()); } sb.setLength(0); javaIndent(sb, 1); sb.append("\"from "); //$NON-NLS-1$ sb.append(escapeStringForJava(introspectedTable .getAliasedFullyQualifiedTableNameAtRuntime())); sb.append("\","); //$NON-NLS-1$ method.addAnnotation(sb.toString()); boolean and = false; iter = introspectedTable.getPrimaryKeyColumns().iterator(); while (iter.hasNext()) { IntrospectedColumn introspectedColumn = iter.next(); sb.setLength(0); javaIndent(sb, 1); if (and) { sb.append(" \"and "); //$NON-NLS-1$ } else { sb.append("\"where "); //$NON-NLS-1$ and = true; } sb.append(escapeStringForJava(getAliasedEscapedColumnName(introspectedColumn))); sb.append(" = "); //$NON-NLS-1$ sb.append(getParameterClause(introspectedColumn)); sb.append('\"'); if (iter.hasNext()) { sb.append(','); } method.addAnnotation(sb.toString()); } method.addAnnotation("})"); //$NON-NLS-1$ if (useResultMapIfAvailable) { if (introspectedTable.getRules().generateBaseResultMap() || introspectedTable.getRules().generateResultMapWithBLOBs()) { addResultMapAnnotation(interfaze, method); } else { addAnnotatedResults(interfaze, method); } } else { addAnnotatedResults(interfaze, method); } }
Example 19
Source File: BasicSelectManyMethodGenerator.java From mapper-generator-javafx with Apache License 2.0 | 4 votes |
@Override public MethodAndImports generateMethodAndImports() { if (!introspectedTable.getRules().generateSelectByExampleWithBLOBs() && !introspectedTable.getRules().generateSelectByExampleWithoutBLOBs()) { return null; } Set<FullyQualifiedJavaType> imports = new HashSet<>(); FullyQualifiedJavaType parameterType = new FullyQualifiedJavaType( "org.mybatis.dynamic.sql.select.render.SelectStatementProvider"); FullyQualifiedJavaType adapter = new FullyQualifiedJavaType("org.mybatis.dynamic.sql.util.SqlProviderAdapter"); FullyQualifiedJavaType annotation = new FullyQualifiedJavaType("org.apache.ibatis.annotations.SelectProvider"); imports.add(parameterType); imports.add(adapter); imports.add(annotation); imports.add(FullyQualifiedJavaType.getNewListInstance()); imports.add(recordType); FullyQualifiedJavaType returnType = FullyQualifiedJavaType.getNewListInstance(); returnType.addTypeArgument(recordType); Method method = new Method("selectMany"); method.setAbstract(true); method.setReturnType(returnType); method.addParameter(new Parameter(parameterType, "selectStatement")); context.getCommentGenerator().addGeneralMethodAnnotation(method, introspectedTable, imports); method.addAnnotation("@SelectProvider(type=SqlProviderAdapter.class, method=\"select\")"); MethodAndImports.Builder builder = MethodAndImports.withMethod(method) .withImports(imports); MethodParts methodParts; if (introspectedTable.isConstructorBased()) { methodParts = fragmentGenerator.getAnnotatedConstructorArgs(); } else { methodParts = fragmentGenerator.getAnnotatedResults(); } acceptParts(builder, method, methodParts); return builder.build(); }
Example 20
Source File: AnnotatedDeleteByPrimaryKeyMethodGenerator.java From mybatis-generator-core-fix with Apache License 2.0 | 4 votes |
@Override public void addMapperAnnotations(Interface interfaze, Method method) { interfaze.addImportedType(new FullyQualifiedJavaType("org.apache.ibatis.annotations.Delete")); //$NON-NLS-1$ method.addAnnotation("@Delete({"); //$NON-NLS-1$ StringBuilder sb = new StringBuilder(); javaIndent(sb, 1); sb.append("\"delete from " ); //$NON-NLS-1$ sb.append(escapeStringForJava( introspectedTable.getFullyQualifiedTableNameAtRuntime())); sb.append("\","); //$NON-NLS-1$ method.addAnnotation(sb.toString()); boolean and = false; Iterator<IntrospectedColumn> iter = introspectedTable.getPrimaryKeyColumns().iterator(); while (iter.hasNext()) { IntrospectedColumn introspectedColumn = iter.next(); sb.setLength(0); javaIndent(sb, 1); if (and) { sb.append(" \"and "); //$NON-NLS-1$ } else { sb.append("\"where "); //$NON-NLS-1$ and = true; } sb.append(escapeStringForJava( getEscapedColumnName(introspectedColumn))); sb.append(" = "); //$NON-NLS-1$ sb.append(getParameterClause(introspectedColumn)); sb.append('\"'); if (iter.hasNext()) { sb.append(','); } method.addAnnotation(sb.toString()); } method.addAnnotation("})"); //$NON-NLS-1$ }