Skip to content

Commit

Permalink
Merge pull request #2791 from hazendaz/formatting
Browse files Browse the repository at this point in the history
[ci] Formatting
  • Loading branch information
hazendaz authored Feb 4, 2023
2 parents 312b4ff + 5d8db22 commit 55cfb7d
Show file tree
Hide file tree
Showing 80 changed files with 923 additions and 834 deletions.
72 changes: 42 additions & 30 deletions src/test/java/org/apache/ibatis/submitted/dynsql/DynSqlTest.java
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 Down Expand Up @@ -51,7 +51,7 @@ static void setUp() throws Exception {
}

BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(),
"org/apache/ibatis/submitted/dynsql/CreateDB.sql");
"org/apache/ibatis/submitted/dynsql/CreateDB.sql");
}

@Test
Expand Down Expand Up @@ -84,7 +84,8 @@ void testSelectSimple() {
parameter.setSchema("ibtest");
parameter.setIds(ids);

List<Map<String, Object>> answer = sqlSession.selectList("org.apache.ibatis.submitted.dynsql.select_simple", parameter);
List<Map<String, Object>> answer = sqlSession.selectList("org.apache.ibatis.submitted.dynsql.select_simple",
parameter);

assertEquals(3, answer.size());
}
Expand Down Expand Up @@ -126,7 +127,8 @@ void testNumerics() {
@Test
void testOgnlStaticMethodCall() {
try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
List<Map<String, Object>> answer = sqlSession.selectList("org.apache.ibatis.submitted.dynsql.ognlStaticMethodCall", "Rock 'n Roll");
List<Map<String, Object>> answer = sqlSession
.selectList("org.apache.ibatis.submitted.dynsql.ognlStaticMethodCall", "Rock 'n Roll");
assertEquals(1, answer.size());
assertEquals(7, answer.get(0).get("ID"));
}
Expand All @@ -142,8 +144,9 @@ void testBindNull() {
}

/**
* Verify that can specify any variable name for parameter object when parameter is value object that a type handler exists.
*
* Verify that can specify any variable name for parameter object when parameter is value object that a type handler
* exists.
* <p>
* https://github.com/mybatis/mybatis-3/issues/1486
*/
@Test
Expand Down Expand Up @@ -181,7 +184,9 @@ void testNonValueObjectWithoutParamAnnotation() {
try {
mapper.selectDescriptionByConditions2(conditions);
} catch (PersistenceException e) {
assertEquals("There is no getter for property named 'conditions' in 'class org.apache.ibatis.submitted.dynsql.DynSqlMapper$Conditions'", e.getCause().getMessage());
assertEquals(
"There is no getter for property named 'conditions' in 'class org.apache.ibatis.submitted.dynsql.DynSqlMapper$Conditions'",
e.getCause().getMessage());
}
assertEquals(7, mapper.selectDescriptionByConditions2(null).size());
}
Expand All @@ -192,7 +197,9 @@ void testNonValueObjectWithoutParamAnnotation() {
try {
mapper.selectDescriptionByConditions3(conditions);
} catch (PersistenceException e) {
assertEquals("There is no getter for property named 'conditions' in 'class org.apache.ibatis.submitted.dynsql.DynSqlMapper$Conditions'", e.getCause().getMessage());
assertEquals(
"There is no getter for property named 'conditions' in 'class org.apache.ibatis.submitted.dynsql.DynSqlMapper$Conditions'",
e.getCause().getMessage());
}
assertEquals(7, mapper.selectDescriptionByConditions3(null).size());
}
Expand All @@ -208,28 +215,33 @@ void testCustomValueObjectWithoutParamAnnotation() throws IOException {
try (Reader configReader = Resources.getResourceAsReader("org/apache/ibatis/submitted/dynsql/MapperConfig.xml")) {
sqlSessionFactory = new SqlSessionFactoryBuilder().build(configReader);
// register type handler for the user defined class (= value object)
sqlSessionFactory.getConfiguration().getTypeHandlerRegistry().register(DynSqlMapper.Conditions.class, new TypeHandler<DynSqlMapper.Conditions>() {
@Override
public void setParameter(PreparedStatement ps, int i, DynSqlMapper.Conditions parameter, JdbcType jdbcType) throws SQLException {
if (parameter.getId() != null) {
ps.setInt(i, parameter.getId());
} else {
ps.setNull(i, JdbcType.INTEGER.TYPE_CODE);
}
}
@Override
public DynSqlMapper.Conditions getResult(ResultSet rs, String columnName) throws SQLException {
return null;
}
@Override
public DynSqlMapper.Conditions getResult(ResultSet rs, int columnIndex) throws SQLException {
return null;
}
@Override
public DynSqlMapper.Conditions getResult(CallableStatement cs, int columnIndex) throws SQLException {
return null;
}
});
sqlSessionFactory.getConfiguration().getTypeHandlerRegistry().register(DynSqlMapper.Conditions.class,
new TypeHandler<DynSqlMapper.Conditions>() {
@Override
public void setParameter(PreparedStatement ps, int i, DynSqlMapper.Conditions parameter, JdbcType jdbcType)
throws SQLException {
if (parameter.getId() != null) {
ps.setInt(i, parameter.getId());
} else {
ps.setNull(i, JdbcType.INTEGER.TYPE_CODE);
}
}

@Override
public DynSqlMapper.Conditions getResult(ResultSet rs, String columnName) throws SQLException {
return null;
}

@Override
public DynSqlMapper.Conditions getResult(ResultSet rs, int columnIndex) throws SQLException {
return null;
}

@Override
public DynSqlMapper.Conditions getResult(CallableStatement cs, int columnIndex) throws SQLException {
return null;
}
});
}
try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
DynSqlMapper mapper = sqlSession.getMapper(DynSqlMapper.class);
Expand Down
162 changes: 91 additions & 71 deletions src/test/java/org/apache/ibatis/submitted/dynsql/NumericRow.java
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 @@ -19,74 +19,94 @@
import java.math.BigInteger;

public class NumericRow {
private Integer id;
private Byte tinynumber;
private Short smallnumber;
private Long longinteger;
private BigInteger biginteger;
private BigDecimal numericnumber;
private BigDecimal decimalnumber;
private Float realnumber;
private Float floatnumber;
private Double doublenumber;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Byte getTinynumber() {
return tinynumber;
}
public void setTinynumber(Byte tinynumber) {
this.tinynumber = tinynumber;
}
public Short getSmallnumber() {
return smallnumber;
}
public void setSmallnumber(Short smallnumber) {
this.smallnumber = smallnumber;
}
public Long getLonginteger() {
return longinteger;
}
public void setLonginteger(Long longinteger) {
this.longinteger = longinteger;
}
public BigInteger getBiginteger() {
return biginteger;
}
public void setBiginteger(BigInteger biginteger) {
this.biginteger = biginteger;
}
public BigDecimal getNumericnumber() {
return numericnumber;
}
public void setNumericnumber(BigDecimal numericnumber) {
this.numericnumber = numericnumber;
}
public BigDecimal getDecimalnumber() {
return decimalnumber;
}
public void setDecimalnumber(BigDecimal decimalnumber) {
this.decimalnumber = decimalnumber;
}
public Float getRealnumber() {
return realnumber;
}
public void setRealnumber(Float realnumber) {
this.realnumber = realnumber;
}
public Float getFloatnumber() {
return floatnumber;
}
public void setFloatnumber(Float floatnumber) {
this.floatnumber = floatnumber;
}
public Double getDoublenumber() {
return doublenumber;
}
public void setDoublenumber(Double doublenumber) {
this.doublenumber = doublenumber;
}
private Integer id;
private Byte tinynumber;
private Short smallnumber;
private Long longinteger;
private BigInteger biginteger;
private BigDecimal numericnumber;
private BigDecimal decimalnumber;
private Float realnumber;
private Float floatnumber;
private Double doublenumber;

public Integer getId() {
return id;
}

public void setId(Integer id) {
this.id = id;
}

public Byte getTinynumber() {
return tinynumber;
}

public void setTinynumber(Byte tinynumber) {
this.tinynumber = tinynumber;
}

public Short getSmallnumber() {
return smallnumber;
}

public void setSmallnumber(Short smallnumber) {
this.smallnumber = smallnumber;
}

public Long getLonginteger() {
return longinteger;
}

public void setLonginteger(Long longinteger) {
this.longinteger = longinteger;
}

public BigInteger getBiginteger() {
return biginteger;
}

public void setBiginteger(BigInteger biginteger) {
this.biginteger = biginteger;
}

public BigDecimal getNumericnumber() {
return numericnumber;
}

public void setNumericnumber(BigDecimal numericnumber) {
this.numericnumber = numericnumber;
}

public BigDecimal getDecimalnumber() {
return decimalnumber;
}

public void setDecimalnumber(BigDecimal decimalnumber) {
this.decimalnumber = decimalnumber;
}

public Float getRealnumber() {
return realnumber;
}

public void setRealnumber(Float realnumber) {
this.realnumber = realnumber;
}

public Float getFloatnumber() {
return floatnumber;
}

public void setFloatnumber(Float floatnumber) {
this.floatnumber = floatnumber;
}

public Double getDoublenumber() {
return doublenumber;
}

public void setDoublenumber(Double doublenumber) {
this.doublenumber = doublenumber;
}
}
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 Down Expand Up @@ -41,7 +41,7 @@ static void setUp() throws Exception {
}

BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(),
"org/apache/ibatis/submitted/dynsql2/CreateDB.sql");
"org/apache/ibatis/submitted/dynsql2/CreateDB.sql");
}

@Test
Expand All @@ -62,7 +62,8 @@ void testDynamicSelectWithTypeHandler() {
Parameter parameter = new Parameter();
parameter.setNames(names);

List<Map<String, Object>> answer = sqlSession.selectList("org.apache.ibatis.submitted.dynsql2.dynamicSelectWithTypeHandler", parameter);
List<Map<String, Object>> answer = sqlSession
.selectList("org.apache.ibatis.submitted.dynsql2.dynamicSelectWithTypeHandler", parameter);

assertEquals(2, answer.size());
}
Expand Down
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 @@ -23,26 +23,22 @@
public class FirstNameTypeHandler implements TypeHandler {

@Override
public Object getResult(CallableStatement cs, int columnIndex)
throws SQLException {
public Object getResult(CallableStatement cs, int columnIndex) throws SQLException {
return cs.getString(columnIndex);
}

@Override
public Object getResult(ResultSet rs, String columnName)
throws SQLException {
public Object getResult(ResultSet rs, String columnName) throws SQLException {
return rs.getString(columnName);
}

@Override
public Object getResult(ResultSet rs, int columnIndex)
throws SQLException {
public Object getResult(ResultSet rs, int columnIndex) throws SQLException {
return rs.getString(columnIndex);
}

@Override
public void setParameter(PreparedStatement ps, int i, Object parameter,
JdbcType jdbcType) throws SQLException {
public void setParameter(PreparedStatement ps, int i, Object parameter, JdbcType jdbcType) throws SQLException {
if (parameter == null) {
ps.setNull(i, Types.VARCHAR);
} else {
Expand Down
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 @@ -23,26 +23,22 @@
public class LastNameTypeHandler implements TypeHandler {

@Override
public Object getResult(CallableStatement cs, int columnIndex)
throws SQLException {
public Object getResult(CallableStatement cs, int columnIndex) throws SQLException {
return cs.getString(columnIndex);
}

@Override
public Object getResult(ResultSet rs, String columnName)
throws SQLException {
public Object getResult(ResultSet rs, String columnName) throws SQLException {
return rs.getString(columnName);
}

@Override
public Object getResult(ResultSet rs, int columnIndex)
throws SQLException {
public Object getResult(ResultSet rs, int columnIndex) throws SQLException {
return rs.getString(columnIndex);
}

@Override
public void setParameter(PreparedStatement ps, int i, Object parameter,
JdbcType jdbcType) throws SQLException {
public void setParameter(PreparedStatement ps, int i, Object parameter, JdbcType jdbcType) throws SQLException {
if (parameter == null) {
ps.setNull(i, Types.VARCHAR);
} else {
Expand Down
Loading

0 comments on commit 55cfb7d

Please sign in to comment.