Skip to content

Commit

Permalink
Merge pull request #2816 from hazendaz/copyright
Browse files Browse the repository at this point in the history
[ci] Apply open rewrite partially on java cleanup
  • Loading branch information
hazendaz authored Feb 20, 2023
2 parents a99d783 + 630f017 commit eaa6983
Show file tree
Hide file tree
Showing 35 changed files with 329 additions and 286 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2009-2022 the original author or authors.
* Copyright 2009-2023 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 All @@ -26,8 +26,8 @@ public class LoggingCache implements Cache {

private final Log log;
private final Cache delegate;
protected int requests = 0;
protected int hits = 0;
protected int requests;
protected int hits;

public LoggingCache(Cache delegate) {
this.delegate = delegate;
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/org/apache/ibatis/datasource/pooled/PoolState.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ public class PoolState {

protected final List<PooledConnection> idleConnections = new ArrayList<>();
protected final List<PooledConnection> activeConnections = new ArrayList<>();
protected long requestCount = 0;
protected long accumulatedRequestTime = 0;
protected long accumulatedCheckoutTime = 0;
protected long claimedOverdueConnectionCount = 0;
protected long accumulatedCheckoutTimeOfOverdueConnections = 0;
protected long accumulatedWaitTime = 0;
protected long hadToWaitCount = 0;
protected long badConnectionCount = 0;
protected long requestCount;
protected long accumulatedRequestTime;
protected long accumulatedCheckoutTime;
protected long claimedOverdueConnectionCount;
protected long accumulatedCheckoutTimeOfOverdueConnections;
protected long accumulatedWaitTime;
protected long hadToWaitCount;
protected long badConnectionCount;

public PoolState(PooledDataSource dataSource) {
this.dataSource = dataSource;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class DynamicContext {

private final ContextMap bindings;
private final StringJoiner sqlBuilder = new StringJoiner(" ");
private int uniqueNumber = 0;
private int uniqueNumber;

public DynamicContext(Configuration configuration, Object parameterObject) {
if (parameterObject != null && !(parameterObject instanceof Map)) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/apache/ibatis/session/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public class Configuration {
protected ObjectFactory objectFactory = new DefaultObjectFactory();
protected ObjectWrapperFactory objectWrapperFactory = new DefaultObjectWrapperFactory();

protected boolean lazyLoadingEnabled = false;
protected boolean lazyLoadingEnabled;
protected ProxyFactory proxyFactory = new JavassistProxyFactory(); // #224 Using internal Javassist instead of OGNL

protected String databaseId;
Expand Down
12 changes: 6 additions & 6 deletions src/test/java/org/apache/ibatis/binding/BoundAuthorMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ public interface BoundAuthorMapper {
" USERNAME as AUTHOR_USERNAME,",
" PASSWORD as AUTHOR_PASSWORD,",
" EMAIL as AUTHOR_EMAIL,",
" BIO as AUTHOR_BIO," +
" FAVOURITE_SECTION as AUTHOR_SECTION",
" BIO as AUTHOR_BIO,"
+ " FAVOURITE_SECTION as AUTHOR_SECTION",
"FROM AUTHOR WHERE ID = #{id}"})
// @formatter:on
Author selectAuthorConstructor(int id);
Expand All @@ -125,8 +125,8 @@ public interface BoundAuthorMapper {
" USERNAME as AUTHOR_USERNAME,",
" PASSWORD as AUTHOR_PASSWORD,",
" EMAIL as AUTHOR_EMAIL,",
" BIO as AUTHOR_BIO," +
" FAVOURITE_SECTION as AUTHOR_SECTION",
" BIO as AUTHOR_BIO,"
+ " FAVOURITE_SECTION as AUTHOR_SECTION",
"FROM AUTHOR WHERE ID = #{id}"})
// @formatter:on
Author selectAuthorMapToConstructorUsingRepeatable(int id);
Expand Down Expand Up @@ -164,8 +164,8 @@ public interface BoundAuthorMapper {
" USERNAME as AUTHOR_USERNAME,",
" PASSWORD as AUTHOR_PASSWORD,",
" EMAIL as AUTHOR_EMAIL,",
" BIO as AUTHOR_BIO," +
" FAVOURITE_SECTION as AUTHOR_SECTION",
" BIO as AUTHOR_BIO,"
+ " FAVOURITE_SECTION as AUTHOR_SECTION",
"FROM AUTHOR WHERE ID = #{id}"})
// @formatter:on
Author selectAuthorUsingBothArgAndConstructorArgs(int id);
Expand Down
48 changes: 24 additions & 24 deletions src/test/java/org/apache/ibatis/binding/BoundBlogMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,16 +128,16 @@ public interface BoundBlogMapper {
// ======================================================

// @formatter:off
@Select("SELECT * FROM " +
"blog WHERE id = #{id}")
@Select("SELECT * FROM "
+ "blog WHERE id = #{id}")
// @formatter:on
Blog selectBlog(int id);

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

// @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 @@ -158,47 +158,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}")
@Select("SELECT * FROM blog "
+ "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}")
@Select("SELECT * FROM blog "
+ "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 @@ -208,22 +208,22 @@ List<Post> selectPostsLikeSubjectAndBody(RowBounds bounds, @Param("subjectQuery"
// ======================================================

// @formatter:off
@Select("SELECT * FROM blog " +
"WHERE id = #{0} AND title = #{1}")
@Select("SELECT * FROM blog "
+ "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}")
@Select("SELECT * FROM blog "
+ "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}")
@Select("SELECT * FROM blog "
+ "WHERE ${column} = #{id} AND title = #{value}")
// @formatter:on
Blog selectBlogWithAParamNamedValue(@Param("column") String column, @Param("id") int id,
@Param("value") String title);
Expand All @@ -248,8 +248,8 @@ Blog selectBlogWithAParamNamedValue(@Param("column") String column, @Param("id")
"FROM blog"
})
@Results({
@Result(property = "author", column = "author_id", one = @One(select = "org.apache.ibatis.binding.BoundAuthorMapper.selectAuthor", fetchType=FetchType.EAGER)),
@Result(property = "posts", column = "id", many = @Many(select = "selectPostsById", fetchType=FetchType.EAGER))
@Result(property = "author", column = "author_id", one = @One(select = "org.apache.ibatis.binding.BoundAuthorMapper.selectAuthor", fetchType = FetchType.EAGER)),
@Result(property = "posts", column = "id", many = @Many(select = "selectPostsById", fetchType = FetchType.EAGER))
})
// @formatter:on
List<Blog> selectBlogsWithAutorAndPostsEagerly();
Expand Down
16 changes: 0 additions & 16 deletions src/test/java/org/apache/ibatis/builder/XmlMapperBuilderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@ void mappedStatementWithoutOptionsWhenSpecifyDefaultValue() throws Exception {
@Test
void parseExpression() {
BaseBuilder builder = new BaseBuilder(new Configuration()) {
{
}
};
{
Pattern pattern = builder.parseExpression("[0-9]", "[a-z]");
Expand All @@ -100,8 +98,6 @@ void parseExpression() {
@Test
void resolveJdbcTypeWithUndefinedValue() {
BaseBuilder builder = new BaseBuilder(new Configuration()) {
{
}
};
when(() -> builder.resolveJdbcType("aaa"));
then(caughtException()).isInstanceOf(BuilderException.class)
Expand All @@ -112,8 +108,6 @@ void resolveJdbcTypeWithUndefinedValue() {
@Test
void resolveResultSetTypeWithUndefinedValue() {
BaseBuilder builder = new BaseBuilder(new Configuration()) {
{
}
};
when(() -> builder.resolveResultSetType("bbb"));
then(caughtException()).isInstanceOf(BuilderException.class)
Expand All @@ -124,8 +118,6 @@ void resolveResultSetTypeWithUndefinedValue() {
@Test
void resolveParameterModeWithUndefinedValue() {
BaseBuilder builder = new BaseBuilder(new Configuration()) {
{
}
};
when(() -> builder.resolveParameterMode("ccc"));
then(caughtException()).isInstanceOf(BuilderException.class)
Expand All @@ -136,8 +128,6 @@ void resolveParameterModeWithUndefinedValue() {
@Test
void createInstanceWithAbstractClass() {
BaseBuilder builder = new BaseBuilder(new Configuration()) {
{
}
};
when(() -> builder.createInstance("org.apache.ibatis.builder.BaseBuilder"));
then(caughtException()).isInstanceOf(BuilderException.class).hasMessage(
Expand All @@ -147,8 +137,6 @@ void createInstanceWithAbstractClass() {
@Test
void resolveClassWithNotFound() {
BaseBuilder builder = new BaseBuilder(new Configuration()) {
{
}
};
when(() -> builder.resolveClass("ddd"));
then(caughtException()).isInstanceOf(BuilderException.class).hasMessage(
Expand All @@ -158,8 +146,6 @@ void resolveClassWithNotFound() {
@Test
void resolveTypeHandlerTypeHandlerAliasIsNull() {
BaseBuilder builder = new BaseBuilder(new Configuration()) {
{
}
};
TypeHandler<?> typeHandler = builder.resolveTypeHandler(String.class, (String) null);
assertThat(typeHandler).isNull();
Expand All @@ -168,8 +154,6 @@ void resolveTypeHandlerTypeHandlerAliasIsNull() {
@Test
void resolveTypeHandlerNoAssignable() {
BaseBuilder builder = new BaseBuilder(new Configuration()) {
{
}
};
when(() -> builder.resolveTypeHandler(String.class, "integer"));
then(caughtException()).isInstanceOf(BuilderException.class).hasMessage(
Expand Down
12 changes: 8 additions & 4 deletions src/test/java/org/apache/ibatis/cache/SerializedCacheTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,12 @@ public CachingObject(int x) {

@Override
public boolean equals(Object o) {
if (this == o)
if (this == o) {
return true;
if (o == null || getClass() != o.getClass())
}
if (o == null || getClass() != o.getClass()) {
return false;
}
CachingObject obj = (CachingObject) o;
return x == obj.x;
}
Expand All @@ -87,10 +89,12 @@ public CachingObjectWithoutSerializable(int x) {

@Override
public boolean equals(Object o) {
if (this == o)
if (this == o) {
return true;
if (o == null || getClass() != o.getClass())
}
if (o == null || getClass() != o.getClass()) {
return false;
}
CachingObjectWithoutSerializable obj = (CachingObjectWithoutSerializable) o;
return x == obj.x;
}
Expand Down
25 changes: 17 additions & 8 deletions src/test/java/org/apache/ibatis/domain/blog/Author.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,25 +93,34 @@ public Section getFavouriteSection() {

@Override
public boolean equals(Object o) {
if (this == o)
if (this == o) {
return true;
if (!(o instanceof Author))
}
if (!(o instanceof Author)) {
return false;
}

Author author = (Author) o;

if (id != author.id)
if (id != author.id) {
return false;
if (bio != null ? !bio.equals(author.bio) : author.bio != null)
}
if (bio != null ? !bio.equals(author.bio) : author.bio != null) {
return false;
if (email != null ? !email.equals(author.email) : author.email != null)
}
if (email != null ? !email.equals(author.email) : author.email != null) {
return false;
if (password != null ? !password.equals(author.password) : author.password != null)
}
if (password != null ? !password.equals(author.password) : author.password != null) {
return false;
if (username != null ? !username.equals(author.username) : author.username != null)
}
if (username != null ? !username.equals(author.username) : author.username != null) {
return false;
if (favouriteSection != null ? !favouriteSection.equals(author.favouriteSection) : author.favouriteSection != null)
}
if (favouriteSection != null ? !favouriteSection.equals(author.favouriteSection)
: author.favouriteSection != null) {
return false;
}

return true;
}
Expand Down
Loading

0 comments on commit eaa6983

Please sign in to comment.