Skip to content

Additoinal Cleanup on formatting blocks #3358

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@
* Since 3.5.1, this attribute can omit.
* <p>
* If this attribute omit, the MyBatis will call a method that decide by following rules. <code>
* <pre>
* <ul>
* <li>
* If class that specified the {@link #type()} attribute implements the
Expand All @@ -91,7 +90,6 @@
* and use a fallback method that named {@code provideSql} from specified type
* </li>
* </ul>
* </pre>
* </code>
*
* @return a method name of method for providing an SQL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@
* Since 3.5.1, this attribute can omit.
* <p>
* If this attribute omit, the MyBatis will call a method that decide by following rules. <code>
* <pre>
* <ul>
* <li>
* If class that specified the {@link #type()} attribute implements the
Expand All @@ -91,7 +90,6 @@
* and use a fallback method that named {@code provideSql} from specified type
* </li>
* </ul>
* </pre>
* </code>
*
* @return a method name of method for providing an SQL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@
* Since 3.5.1, this attribute can omit.
* <p>
* If this attribute omit, the MyBatis will call a method that decide by following rules. <code>
* <pre>
* <ul>
* <li>
* If class that specified the {@link #type()} attribute implements the
Expand All @@ -89,9 +88,8 @@
* If cannot resolve a method by {@link org.apache.ibatis.builder.annotation.ProviderMethodResolver}
* (= not implement it or it was returned {@code null}), the MyBatis will search
* and use a fallback method that named {@code provideSql} from specified type.
* </li>
* </li>
* </ul>
* </pre>
* </code>
*
* @return a method name of method for providing an SQL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
* If cannot resolve a method by {@link org.apache.ibatis.builder.annotation.ProviderMethodResolver}
* (= not implement it or it was returned {@code null}), the MyBatis will search and use a fallback method
* that named {@code provideSql} from specified type</li>
* </ul>
* </ul>
* </code>
*
* @return a method name of method for providing an SQL
Expand Down
10 changes: 3 additions & 7 deletions src/test/java/org/apache/ibatis/binding/BoundAuthorMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,8 @@ public interface BoundAuthorMapper {

// ======================================================

@ConstructorArgs({ @Arg(column = "AUTHOR_ID", javaType = int.class) })
// @formatter:off
@ConstructorArgs({
@Arg(column = "AUTHOR_ID", javaType = int.class)
})
@Results({
@Result(property = "username", column = "AUTHOR_USERNAME"),
@Result(property = "password", column = "AUTHOR_PASSWORD"),
Expand Down Expand Up @@ -179,11 +177,9 @@ public interface BoundAuthorMapper {

// ======================================================

// @formatter:off
@Results(
@Result(property = "id", column = "AUTHOR_ID")
)
@Results(@Result(property = "id", column = "AUTHOR_ID"))
@Result(property = "username", column = "AUTHOR_USERNAME")
// @formatter:off
@Select({
"SELECT ",
" ID as AUTHOR_ID,",
Expand Down
38 changes: 18 additions & 20 deletions src/test/java/org/apache/ibatis/binding/BoundBlogMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,8 @@ public interface BoundBlogMapper {
// ======================================================

@Select("SELECT * FROM post ORDER BY id")
@Results({ @Result(id = true, property = "id", column = "id") })
// @formatter:off
@Results({
@Result(id = true, property = "id", column = "id")
})
@TypeDiscriminator(
column = "draft",
javaType = int.class,
Expand All @@ -149,8 +147,8 @@ public interface BoundBlogMapper {
// ======================================================

// @formatter:off
@Select("SELECT * FROM "
+ "blog WHERE id = #{id}")
@Select("SELECT * FROM blog "
+ "WHERE id = #{id}")
@ConstructorArgs({
@Arg(column = "id", javaType = int.class, id = true),
@Arg(column = "title", javaType = String.class),
Expand All @@ -171,47 +169,47 @@ public interface BoundBlogMapper {
// ======================================================

// @formatter:off
@Select("SELECT * FROM "
+ "blog WHERE id = #{id}")
@Select("SELECT * FROM blog "
+ "WHERE id = #{id}")
// @formatter:on
Map<String, Object> selectBlogAsMap(Map<String, Object> params);

// ======================================================

// @formatter:off
@Select("SELECT * FROM "
+ "post WHERE subject like #{query}")
@Select("SELECT * FROM post "
+ "WHERE subject like #{query}")
// @formatter:on
List<Post> selectPostsLike(RowBounds bounds, String query);

// ======================================================

// @formatter:off
@Select("SELECT * FROM "
+ "post WHERE subject like #{subjectQuery} and body like #{bodyQuery}")
@Select("SELECT * FROM post "
+ "WHERE subject like #{subjectQuery} and body like #{bodyQuery}")
// @formatter:on
List<Post> selectPostsLikeSubjectAndBody(RowBounds bounds, @Param("subjectQuery") String subjectQuery,
@Param("bodyQuery") String bodyQuery);

// ======================================================

// @formatter:off
@Select("SELECT * FROM "
+ "post WHERE id = #{id}")
@Select("SELECT * FROM post "
+ "WHERE id = #{id}")
// @formatter:on
List<Post> selectPostsById(int id);

// ======================================================

// @formatter:off
@Select("SELECT * FROM blog "
+ "WHERE id = #{id} AND title = #{nonExistentParam,jdbcType=VARCHAR}")
+ "WHERE id = #{id} AND title = #{nonExistentParam,jdbcType=VARCHAR}")
// @formatter:on
Blog selectBlogByNonExistentParam(@Param("id") int id);

// @formatter:off
@Select("SELECT * FROM blog "
+ "WHERE id = #{id} AND title = #{params.nonExistentParam,jdbcType=VARCHAR}")
+ "WHERE id = #{id} AND title = #{params.nonExistentParam,jdbcType=VARCHAR}")
// @formatter:on
Blog selectBlogByNonExistentNestedParam(@Param("id") int id, @Param("params") Map<String, Object> params);

Expand All @@ -222,21 +220,21 @@ List<Post> selectPostsLikeSubjectAndBody(RowBounds bounds, @Param("subjectQuery"

// @formatter:off
@Select("SELECT * FROM blog "
+ "WHERE id = #{0} AND title = #{1}")
+ "WHERE id = #{0} AND title = #{1}")
// @formatter:on
Blog selectBlogByDefault30ParamNames(int id, String title);

// @formatter:off
@Select("SELECT * FROM blog "
+ "WHERE id = #{param1} AND title = #{param2}")
+ "WHERE id = #{param1} AND title = #{param2}")
// @formatter:on
Blog selectBlogByDefault31ParamNames(int id, String title);

// ======================================================

// @formatter:off
@Select("SELECT * FROM blog "
+ "WHERE ${column} = #{id} AND title = #{value}")
+ "WHERE ${column} = #{id} AND title = #{value}")
// @formatter:on
Blog selectBlogWithAParamNamedValue(@Param("column") String column, @Param("id") int id,
@Param("value") String title);
Expand All @@ -246,7 +244,7 @@ Blog selectBlogWithAParamNamedValue(@Param("column") String column, @Param("id")
// @formatter:off
@Select({
"SELECT *",
"FROM blog"
"FROM blog"
})
@Results({
@Result(property = "author", column = "author_id", one = @One(select = "org.apache.ibatis.binding.BoundAuthorMapper.selectAuthor")),
Expand All @@ -258,7 +256,7 @@ Blog selectBlogWithAParamNamedValue(@Param("column") String column, @Param("id")
// @formatter:off
@Select({
"SELECT *",
"FROM blog"
"FROM blog"
})
@Results({
@Result(property = "author", column = "author_id", one = @One(select = "org.apache.ibatis.binding.BoundAuthorMapper.selectAuthor", fetchType = FetchType.EAGER)),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2009-2023 the original author or authors.
* Copyright 2009-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -29,7 +29,7 @@ public interface MapperWithOneAndMany {
// @formatter:off
@Select({
"SELECT *",
"FROM blog"
"FROM blog"
})
@Results({
@Result(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -473,11 +473,24 @@ void shouldTypeVariablesBeComparedWithEquals() throws Exception {
executor.shutdown();
}

// @formatter:off
class AA {}
class BB {}
interface IfaceA extends ParentIface<AA> {}
interface IfaceB extends ParentIface<BB> {}
interface ParentIface<T> {List<T> m();}
// @formatter:on
class AA {
// Do nothing
}

class BB {
// Do nothing
}

interface IfaceA extends ParentIface<AA> {
// Do Nothing
}

interface IfaceB extends ParentIface<BB> {
// Do Nothing
}

interface ParentIface<T> {
List<T> m();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@
*/
class AutoMappingUnknownColumnBehaviorTest {

// @formatter:off
interface Mapper {
// @formatter:off
@Select({
"SELECT ",
" ID,",
Expand All @@ -54,17 +54,19 @@ interface Mapper {
" BIO",
"FROM AUTHOR WHERE ID = #{id}"
})
// @formatter:on
Author selectAuthor(int id);

// @formatter:off
@Select({
"SELECT ",
" ID,", // unknown property type
" USERNAME",
"FROM AUTHOR WHERE ID = #{id}"
})
// @formatter:on
SimpleAuthor selectSimpleAuthor(int id);
}
// @formatter:on

static class SimpleAuthor {
private AtomicInteger id; // unknown property type
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2009-2023 the original author or authors.
* Copyright 2009-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -69,8 +69,8 @@ public interface UserDao {
// @formatter:on
List<User> findAll3();

// @formatter:off
@Select("select id teacher_id, username teacher_name from user")
// @formatter:off
@Results(id = "userMap", value = {
@Result(id = true, column = "teacher_id", property = "id"),
@Result(column = "teacher_name", property = "username")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2009-2023 the original author or authors.
* Copyright 2009-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -69,8 +69,8 @@ public interface UserDao {
// @formatter:on
List<User> findAll3();

// @formatter:off
@Select("select id teacher_id, username teacher_name from user")
// @formatter:off
@Results(id = "userMap", value = {
@Result(id = true, column = "teacher_id", property = "id"),
@Result(column = "teacher_name", property = "username")
Expand Down
Loading
Loading