diff --git a/src/main/java/jp/co/future/uroborosql/SqlEntityQueryImpl.java b/src/main/java/jp/co/future/uroborosql/SqlEntityQueryImpl.java index aaf541eb..94697f59 100644 --- a/src/main/java/jp/co/future/uroborosql/SqlEntityQueryImpl.java +++ b/src/main/java/jp/co/future/uroborosql/SqlEntityQueryImpl.java @@ -256,13 +256,7 @@ public long count(final String col) { public T sum(final String col) { String camelColumnName = CaseFormat.CAMEL_CASE.convert(col); MappingColumn mappingColumn = MappingUtils.getMappingColumn(context().getSchema(), entityType, camelColumnName); - Class rawType = mappingColumn.getJavaType().getRawType(); - if (!(short.class.equals(rawType) || - int.class.equals(rawType) || - long.class.equals(rawType) || - float.class.equals(rawType) || - double.class.equals(rawType) || - Number.class.isAssignableFrom(mappingColumn.getJavaType().getRawType()))) { + if (!mappingColumn.isNumber()) { throw new UroborosqlRuntimeException("Column is not of type Number. col=" + camelColumnName); } TableMetadata.Column column = tableMetadata.getColumn(camelColumnName); diff --git a/src/main/java/jp/co/future/uroborosql/mapping/MappingColumn.java b/src/main/java/jp/co/future/uroborosql/mapping/MappingColumn.java index 36ad177a..f961ca84 100644 --- a/src/main/java/jp/co/future/uroborosql/mapping/MappingColumn.java +++ b/src/main/java/jp/co/future/uroborosql/mapping/MappingColumn.java @@ -6,6 +6,9 @@ */ package jp.co.future.uroborosql.mapping; +import java.time.temporal.Temporal; +import java.util.Optional; + import jp.co.future.uroborosql.enums.SqlKind; import jp.co.future.uroborosql.mapping.annotations.GeneratedValue; import jp.co.future.uroborosql.mapping.annotations.SequenceGenerator; @@ -20,7 +23,7 @@ public interface MappingColumn { /** - * エンティティから値を取得 + * エンティティから値を取得. * * @param entity エンティティ * @return 取得した値 @@ -28,7 +31,7 @@ public interface MappingColumn { Object getValue(Object entity); /** - * エンティティに値をセット + * エンティティに値をセット. * * @param entity エンティティ * @param value 値 @@ -36,49 +39,49 @@ public interface MappingColumn { void setValue(Object entity, Object value); /** - * カラム名取得 + * カラム名取得. * * @return カラム名 */ String getName(); /** - * キャメルケースカラム名取得 + * キャメルケースカラム名取得. * * @return キャメルケースカラム名 */ String getCamelName(); /** - * {@link JavaType}取得 + * {@link JavaType}取得. * * @return {@link JavaType} */ JavaType getJavaType(); /** - * IDアノテーションが付与されているかどうか + * IDアノテーションが付与されているかどうか. * * @return IDアノテーションが付与されている場合true */ boolean isId(); /** - * {@link GeneratedValue}の取得 + * {@link GeneratedValue}の取得. * * @return {@link GeneratedValue} */ GeneratedValue getGeneratedValue(); /** - * {@link SequenceGenerator}の取得 + * {@link SequenceGenerator}の取得. * * @return {@link SequenceGenerator} */ SequenceGenerator getSequenceGenerator(); /** - * 修飾済みのシーケンス名の取得 + * 修飾済みのシーケンス名の取得. * * @return {@link SequenceGenerator} をもとに修飾したシーケンス名 */ @@ -99,14 +102,14 @@ default String getQualifiedSequenceName() { } /** - * {@link Transient}の取得 + * {@link Transient}の取得. * * @return {@link Transient} */ Transient getTransient(); /** - * 指定したSQL種別でtransientかどうかを判断する + * 指定したSQL種別でtransientかどうか. * * @param sqlKind SQL種別 * @return 指定したSQL種別でtransientの場合true @@ -114,14 +117,69 @@ default String getQualifiedSequenceName() { boolean isTransient(SqlKind sqlKind); /** - * バージョン情報カラムかどうか + * バージョン情報カラムかどうか. * * @return バージョンカラムの場合はtrue */ boolean isVersion(); /** - * {@link Version} の取得 + * Optional型のカラムかどうか. + * + * @return Optional型のカラムの場合はtrue + */ + default boolean isOptional() { + return Optional.class.equals(getJavaType().getRawType()); + } + + /** + * 文字、または文字列型のカラムかどうか. + * + * @return 文字、または文字列型のカラムの場合はtrue + */ + default boolean isString() { + Class rawType = isOptional() ? getJavaType().getParam(0).getRawType() : getJavaType().getRawType(); + return String.class.equals(rawType) || + char.class.equals(rawType) || + Character.class.equals(rawType); + } + + /** + * 数値型のカラムかどうか. + * + * @return 数値型のカラムの場合はtrue + */ + default boolean isNumber() { + Class rawType = isOptional() ? getJavaType().getParam(0).getRawType() : getJavaType().getRawType(); + return short.class.equals(rawType) || + int.class.equals(rawType) || + long.class.equals(rawType) || + float.class.equals(rawType) || + double.class.equals(rawType) || + Number.class.isAssignableFrom(rawType); + } + + /** + * 配列型のカラムかどうか. + * + * @return 配列型のカラムの場合はtrue + */ + default boolean isArray() { + return getJavaType().getRawType().isArray(); + } + + /** + * 時間的オブジェクト型のカラムかどうか. + * + * @return 時間的オブジェクト型のカラムの場合はtrue + */ + default boolean isTemporal() { + Class rawType = isOptional() ? getJavaType().getParam(0).getRawType() : getJavaType().getRawType(); + return Temporal.class.isAssignableFrom(rawType); + } + + /** + * {@link Version} の取得. * * @return {@link Version} */ diff --git a/src/test/java/jp/co/future/uroborosql/mapping/DefaultEntityHandlerTest.java b/src/test/java/jp/co/future/uroborosql/mapping/DefaultEntityHandlerTest.java index b2f6a001..31e6949d 100644 --- a/src/test/java/jp/co/future/uroborosql/mapping/DefaultEntityHandlerTest.java +++ b/src/test/java/jp/co/future/uroborosql/mapping/DefaultEntityHandlerTest.java @@ -8,6 +8,7 @@ import static org.junit.Assert.fail; import java.lang.reflect.Field; +import java.math.BigDecimal; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; @@ -331,6 +332,112 @@ public void testQuery4() throws Exception { } } + @Test + public void testQuery5() throws Exception { + + try (SqlAgent agent = config.agent()) { + agent.required(() -> { + TestEntity4 test1 = new TestEntity4(1L, "name1", new BigDecimal("20"), + LocalDate.of(1990, Month.APRIL, 1)); + agent.insert(test1); + TestEntity4 test2 = new TestEntity4(2L, "name2", new BigDecimal("21"), + LocalDate.of(1990, Month.MAY, 1)); + agent.insert(test2); + TestEntity4 test3 = new TestEntity4(3L, "name3", new BigDecimal("22"), + LocalDate.of(1990, Month.MAY, 1)); + agent.insert(test3); + TestEntity4 test4 = new TestEntity4(4L, "name4", new BigDecimal("23"), null); + agent.insert(test4); + + long count1 = agent.query(TestEntity4.class).count(); + assertThat(count1, is(4L)); + long count2 = agent.query(TestEntity4.class).count(TestEntity4.Names.Birthday); + assertThat(count2, is(3L)); + + BigDecimal sum = agent.query(TestEntity4.class).sum(TestEntity4.Names.Age); + assertThat(sum, is(new BigDecimal("86"))); + + BigDecimal min = agent.query(TestEntity4.class).min(TestEntity4.Names.Age); + assertThat(min, is(new BigDecimal("20"))); + + String minName = agent.query(TestEntity4.class).min(TestEntity4.Names.Name); + assertThat(minName, is("name1")); + + long max = agent.query(TestEntity4.class).max(TestEntity4.Names.Id); + assertThat(max, is(4L)); + + LocalDate maxDate = agent.query(TestEntity4.class).max(TestEntity4.Names.Birthday); + assertThat(maxDate, is(LocalDate.of(1990, Month.MAY, 1))); + }); + } + } + + @Test + public void testQuery6() throws Exception { + + try (SqlAgent agent = config.agent()) { + agent.required(() -> { + TestEntity5 test1 = new TestEntity5(1L, "name1", Optional.ofNullable(new BigDecimal("20")), + LocalDate.of(1990, Month.APRIL, 1)); + agent.insert(test1); + TestEntity5 test2 = new TestEntity5(2L, "name2", Optional.ofNullable(new BigDecimal("21")), + LocalDate.of(1990, Month.MAY, 1)); + agent.insert(test2); + TestEntity5 test3 = new TestEntity5(3L, "name3", Optional.ofNullable(new BigDecimal("22")), + LocalDate.of(1990, Month.MAY, 1)); + agent.insert(test3); + TestEntity5 test4 = new TestEntity5(4L, "name4", Optional.empty(), null); + agent.insert(test4); + + long count1 = agent.query(TestEntity5.class).count(); + assertThat(count1, is(4L)); + long count2 = agent.query(TestEntity5.class).count(TestEntity5.Names.Birthday); + assertThat(count2, is(3L)); + + Optional sum = agent.query(TestEntity5.class).sum(TestEntity5.Names.Age); + assertThat(sum.orElseThrow(IllegalStateException::new), is(new BigDecimal("63"))); + + Optional min = agent.query(TestEntity5.class).min(TestEntity5.Names.Age); + assertThat(min.orElseThrow(IllegalStateException::new), is(new BigDecimal("20"))); + + String minName = agent.query(TestEntity5.class).min(TestEntity5.Names.Name); + assertThat(minName, is("name1")); + + long max = agent.query(TestEntity5.class).max(TestEntity5.Names.Id); + assertThat(max, is(4L)); + + LocalDate maxDate = agent.query(TestEntity5.class).max(TestEntity5.Names.Birthday); + assertThat(maxDate, is(LocalDate.of(1990, Month.MAY, 1))); + + }); + } + } + + @Test + public void testQuery7() throws Exception { + + try (SqlAgent agent = config.agent()) { + agent.required(() -> { + TestEntity5 test1 = new TestEntity5(1L, "name1", Optional.empty(), + LocalDate.of(1990, Month.APRIL, 1)); + agent.insert(test1); + TestEntity5 test2 = new TestEntity5(2L, "name2", Optional.empty(), + LocalDate.of(1990, Month.MAY, 1)); + agent.insert(test2); + + Optional sum = agent.query(TestEntity5.class).sum(TestEntity5.Names.Age); + assertThat(sum.isPresent(), is(false)); + + Optional min = agent.query(TestEntity5.class).min(TestEntity5.Names.Age); + assertThat(min.isPresent(), is(false)); + + Optional max = agent.query(TestEntity5.class).max(TestEntity5.Names.Age); + assertThat(max.isPresent(), is(false)); + + }); + } + } + @Test(expected = UroborosqlRuntimeException.class) public void testQueryCountUnmatchColumn() throws Exception { try (SqlAgent agent = config.agent()) { @@ -399,9 +506,7 @@ public void testQueryWithCondition() throws Exception { TestEntity test3 = new TestEntity(3L, "name3", 20, LocalDate.of(1990, Month.JUNE, 1), Optional.empty()); agent.insert(test3); - // Equal - List list = null; - list = agent.query(TestEntity.class).equal("id", 2).collect(); + List list = agent.query(TestEntity.class).equal("id", 2).collect(); assertThat(list.size(), is(1)); assertThat(list.get(0), is(test2)); @@ -700,9 +805,8 @@ public void testQueryWithBetweenColumns() throws Exception { "name3"); agent.insert(test3); - List list = null; // Between - list = agent.query(TestHistoryEntity.class) + List list = agent.query(TestHistoryEntity.class) .betweenColumns(LocalDate.of(1990, Month.APRIL, 15), "start_at", "finish_at") .asc("id") .collect(); @@ -738,9 +842,8 @@ public void testQueryWithNotBetweenColumns() throws Exception { "name3"); agent.insert(test3); - List list = null; // Between - list = agent.query(TestHistoryEntity.class) + List list = agent.query(TestHistoryEntity.class) .notBetweenColumns(LocalDate.of(1990, Month.APRIL, 15), "start_at", "finish_at") .asc("id") .collect(); // 4/15 < start_at or 4/15 > finish_at diff --git a/src/test/java/jp/co/future/uroborosql/mapping/MappingColumnTest.java b/src/test/java/jp/co/future/uroborosql/mapping/MappingColumnTest.java new file mode 100644 index 00000000..683f3d44 --- /dev/null +++ b/src/test/java/jp/co/future/uroborosql/mapping/MappingColumnTest.java @@ -0,0 +1,1361 @@ +package jp.co.future.uroborosql.mapping; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.sameInstance; +import static org.hamcrest.MatcherAssert.assertThat; + +import java.math.BigDecimal; +import java.math.BigInteger; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.time.OffsetDateTime; +import java.time.OffsetTime; +import java.time.Year; +import java.time.YearMonth; +import java.time.ZonedDateTime; +import java.util.Optional; + +import org.junit.Test; + +import jp.co.future.uroborosql.mapping.annotations.Table; + +public class MappingColumnTest { + + @Test + public void testMappingColumnType() throws Exception { + // string + MappingColumn col = MappingUtils.getMappingColumn(TestColType.class, "colStr"); + assertThat(col.getJavaType().getRawType(), sameInstance(String.class)); + assertThat(col.isOptional(), is(false)); + assertThat(col.isString(), is(true)); + assertThat(col.isNumber(), is(false)); + assertThat(col.isArray(), is(false)); + assertThat(col.isTemporal(), is(false)); + + col = MappingUtils.getMappingColumn(TestColType.class, "colChar"); + assertThat(col.getJavaType().getRawType(), sameInstance(char.class)); + assertThat(col.isOptional(), is(false)); + assertThat(col.isString(), is(true)); + assertThat(col.isNumber(), is(false)); + assertThat(col.isArray(), is(false)); + assertThat(col.isTemporal(), is(false)); + + col = MappingUtils.getMappingColumn(TestColType.class, "colCharacter"); + assertThat(col.getJavaType().getRawType(), sameInstance(Character.class)); + assertThat(col.isOptional(), is(false)); + assertThat(col.isString(), is(true)); + assertThat(col.isNumber(), is(false)); + assertThat(col.isArray(), is(false)); + assertThat(col.isTemporal(), is(false)); + + // number + col = MappingUtils.getMappingColumn(TestColType.class, "colShort"); + assertThat(col.getJavaType().getRawType(), sameInstance(short.class)); + assertThat(col.isOptional(), is(false)); + assertThat(col.isString(), is(false)); + assertThat(col.isNumber(), is(true)); + assertThat(col.isArray(), is(false)); + assertThat(col.isTemporal(), is(false)); + + col = MappingUtils.getMappingColumn(TestColType.class, "colShortType"); + assertThat(col.getJavaType().getRawType(), sameInstance(Short.class)); + assertThat(col.isOptional(), is(false)); + assertThat(col.isString(), is(false)); + assertThat(col.isNumber(), is(true)); + assertThat(col.isArray(), is(false)); + assertThat(col.isTemporal(), is(false)); + + col = MappingUtils.getMappingColumn(TestColType.class, "colInt"); + assertThat(col.getJavaType().getRawType(), sameInstance(int.class)); + assertThat(col.isOptional(), is(false)); + assertThat(col.isString(), is(false)); + assertThat(col.isNumber(), is(true)); + assertThat(col.isArray(), is(false)); + assertThat(col.isTemporal(), is(false)); + + col = MappingUtils.getMappingColumn(TestColType.class, "colIntType"); + assertThat(col.getJavaType().getRawType(), sameInstance(Integer.class)); + assertThat(col.isOptional(), is(false)); + assertThat(col.isString(), is(false)); + assertThat(col.isNumber(), is(true)); + assertThat(col.isArray(), is(false)); + assertThat(col.isTemporal(), is(false)); + + col = MappingUtils.getMappingColumn(TestColType.class, "colLong"); + assertThat(col.getJavaType().getRawType(), sameInstance(long.class)); + assertThat(col.isOptional(), is(false)); + assertThat(col.isString(), is(false)); + assertThat(col.isNumber(), is(true)); + assertThat(col.isArray(), is(false)); + assertThat(col.isTemporal(), is(false)); + + col = MappingUtils.getMappingColumn(TestColType.class, "colLongType"); + assertThat(col.getJavaType().getRawType(), sameInstance(Long.class)); + assertThat(col.isOptional(), is(false)); + assertThat(col.isString(), is(false)); + assertThat(col.isNumber(), is(true)); + assertThat(col.isArray(), is(false)); + assertThat(col.isTemporal(), is(false)); + + col = MappingUtils.getMappingColumn(TestColType.class, "colFloat"); + assertThat(col.getJavaType().getRawType(), sameInstance(float.class)); + assertThat(col.isOptional(), is(false)); + assertThat(col.isString(), is(false)); + assertThat(col.isNumber(), is(true)); + assertThat(col.isArray(), is(false)); + assertThat(col.isTemporal(), is(false)); + + col = MappingUtils.getMappingColumn(TestColType.class, "colFloatType"); + assertThat(col.getJavaType().getRawType(), sameInstance(Float.class)); + assertThat(col.isOptional(), is(false)); + assertThat(col.isString(), is(false)); + assertThat(col.isNumber(), is(true)); + assertThat(col.isArray(), is(false)); + assertThat(col.isTemporal(), is(false)); + + col = MappingUtils.getMappingColumn(TestColType.class, "colDouble"); + assertThat(col.getJavaType().getRawType(), sameInstance(double.class)); + assertThat(col.isOptional(), is(false)); + assertThat(col.isString(), is(false)); + assertThat(col.isNumber(), is(true)); + assertThat(col.isArray(), is(false)); + assertThat(col.isTemporal(), is(false)); + + col = MappingUtils.getMappingColumn(TestColType.class, "colDoubleType"); + assertThat(col.getJavaType().getRawType(), sameInstance(Double.class)); + assertThat(col.isOptional(), is(false)); + assertThat(col.isString(), is(false)); + assertThat(col.isNumber(), is(true)); + assertThat(col.isArray(), is(false)); + assertThat(col.isTemporal(), is(false)); + + col = MappingUtils.getMappingColumn(TestColType.class, "colBigInteger"); + assertThat(col.getJavaType().getRawType(), sameInstance(BigInteger.class)); + assertThat(col.isOptional(), is(false)); + assertThat(col.isString(), is(false)); + assertThat(col.isNumber(), is(true)); + assertThat(col.isArray(), is(false)); + assertThat(col.isTemporal(), is(false)); + + col = MappingUtils.getMappingColumn(TestColType.class, "colBigDecimal"); + assertThat(col.getJavaType().getRawType(), sameInstance(BigDecimal.class)); + assertThat(col.isOptional(), is(false)); + assertThat(col.isString(), is(false)); + assertThat(col.isNumber(), is(true)); + assertThat(col.isArray(), is(false)); + assertThat(col.isTemporal(), is(false)); + + // temporal + col = MappingUtils.getMappingColumn(TestColType.class, "colLocalDate"); + assertThat(col.getJavaType().getRawType(), sameInstance(LocalDate.class)); + assertThat(col.isOptional(), is(false)); + assertThat(col.isString(), is(false)); + assertThat(col.isNumber(), is(false)); + assertThat(col.isArray(), is(false)); + assertThat(col.isTemporal(), is(true)); + + col = MappingUtils.getMappingColumn(TestColType.class, "colLocalDateTime"); + assertThat(col.getJavaType().getRawType(), sameInstance(LocalDateTime.class)); + assertThat(col.isOptional(), is(false)); + assertThat(col.isString(), is(false)); + assertThat(col.isNumber(), is(false)); + assertThat(col.isArray(), is(false)); + assertThat(col.isTemporal(), is(true)); + + col = MappingUtils.getMappingColumn(TestColType.class, "colOffsetDateTime"); + assertThat(col.getJavaType().getRawType(), sameInstance(OffsetDateTime.class)); + assertThat(col.isOptional(), is(false)); + assertThat(col.isString(), is(false)); + assertThat(col.isNumber(), is(false)); + assertThat(col.isArray(), is(false)); + assertThat(col.isTemporal(), is(true)); + + col = MappingUtils.getMappingColumn(TestColType.class, "colZonedDateTime"); + assertThat(col.getJavaType().getRawType(), sameInstance(ZonedDateTime.class)); + assertThat(col.isOptional(), is(false)); + assertThat(col.isString(), is(false)); + assertThat(col.isNumber(), is(false)); + assertThat(col.isArray(), is(false)); + assertThat(col.isTemporal(), is(true)); + + col = MappingUtils.getMappingColumn(TestColType.class, "colLocalTime"); + assertThat(col.getJavaType().getRawType(), sameInstance(LocalTime.class)); + assertThat(col.isOptional(), is(false)); + assertThat(col.isString(), is(false)); + assertThat(col.isNumber(), is(false)); + assertThat(col.isArray(), is(false)); + assertThat(col.isTemporal(), is(true)); + + col = MappingUtils.getMappingColumn(TestColType.class, "colOffsetTime"); + assertThat(col.getJavaType().getRawType(), sameInstance(OffsetTime.class)); + assertThat(col.isOptional(), is(false)); + assertThat(col.isString(), is(false)); + assertThat(col.isNumber(), is(false)); + assertThat(col.isArray(), is(false)); + assertThat(col.isTemporal(), is(true)); + + col = MappingUtils.getMappingColumn(TestColType.class, "colYear"); + assertThat(col.getJavaType().getRawType(), sameInstance(Year.class)); + assertThat(col.isOptional(), is(false)); + assertThat(col.isString(), is(false)); + assertThat(col.isNumber(), is(false)); + assertThat(col.isArray(), is(false)); + assertThat(col.isTemporal(), is(true)); + + col = MappingUtils.getMappingColumn(TestColType.class, "colYearMonth"); + assertThat(col.getJavaType().getRawType(), sameInstance(YearMonth.class)); + assertThat(col.isOptional(), is(false)); + assertThat(col.isString(), is(false)); + assertThat(col.isNumber(), is(false)); + assertThat(col.isArray(), is(false)); + assertThat(col.isTemporal(), is(true)); + + // lagacy datetime + col = MappingUtils.getMappingColumn(TestColType.class, "colUtilDate"); + assertThat(col.getJavaType().getRawType(), sameInstance(java.util.Date.class)); + assertThat(col.isOptional(), is(false)); + assertThat(col.isString(), is(false)); + assertThat(col.isNumber(), is(false)); + assertThat(col.isArray(), is(false)); + assertThat(col.isTemporal(), is(false)); + + col = MappingUtils.getMappingColumn(TestColType.class, "colSqlDate"); + assertThat(col.getJavaType().getRawType(), sameInstance(java.sql.Date.class)); + assertThat(col.isOptional(), is(false)); + assertThat(col.isString(), is(false)); + assertThat(col.isNumber(), is(false)); + assertThat(col.isArray(), is(false)); + assertThat(col.isTemporal(), is(false)); + + col = MappingUtils.getMappingColumn(TestColType.class, "colSqlTime"); + assertThat(col.getJavaType().getRawType(), sameInstance(java.sql.Time.class)); + assertThat(col.isOptional(), is(false)); + assertThat(col.isString(), is(false)); + assertThat(col.isNumber(), is(false)); + assertThat(col.isArray(), is(false)); + assertThat(col.isTemporal(), is(false)); + + col = MappingUtils.getMappingColumn(TestColType.class, "colSqlTimestamp"); + assertThat(col.getJavaType().getRawType(), sameInstance(java.sql.Timestamp.class)); + assertThat(col.isOptional(), is(false)); + assertThat(col.isString(), is(false)); + assertThat(col.isNumber(), is(false)); + assertThat(col.isArray(), is(false)); + assertThat(col.isTemporal(), is(false)); + + } + + @Test + public void testMappingColumnTypeOptional() throws Exception { + // string + MappingColumn col = MappingUtils.getMappingColumn(TestColType.class, "colStrOpt"); + assertThat(col.getJavaType().getRawType(), sameInstance(Optional.class)); + assertThat(col.getJavaType().getParam(0).getRawType(), sameInstance(String.class)); + assertThat(col.isOptional(), is(true)); + assertThat(col.isString(), is(true)); + assertThat(col.isNumber(), is(false)); + assertThat(col.isArray(), is(false)); + assertThat(col.isTemporal(), is(false)); + + col = MappingUtils.getMappingColumn(TestColType.class, "colCharacterOpt"); + assertThat(col.getJavaType().getRawType(), sameInstance(Optional.class)); + assertThat(col.getJavaType().getParam(0).getRawType(), sameInstance(Character.class)); + assertThat(col.isOptional(), is(true)); + assertThat(col.isString(), is(true)); + assertThat(col.isNumber(), is(false)); + assertThat(col.isArray(), is(false)); + assertThat(col.isTemporal(), is(false)); + + // number + col = MappingUtils.getMappingColumn(TestColType.class, "colShortTypeOpt"); + assertThat(col.getJavaType().getRawType(), sameInstance(Optional.class)); + assertThat(col.getJavaType().getParam(0).getRawType(), sameInstance(Short.class)); + assertThat(col.isOptional(), is(true)); + assertThat(col.isString(), is(false)); + assertThat(col.isNumber(), is(true)); + assertThat(col.isArray(), is(false)); + assertThat(col.isTemporal(), is(false)); + + col = MappingUtils.getMappingColumn(TestColType.class, "colIntTypeOpt"); + assertThat(col.getJavaType().getRawType(), sameInstance(Optional.class)); + assertThat(col.getJavaType().getParam(0).getRawType(), sameInstance(Integer.class)); + assertThat(col.isOptional(), is(true)); + assertThat(col.isString(), is(false)); + assertThat(col.isNumber(), is(true)); + assertThat(col.isArray(), is(false)); + assertThat(col.isTemporal(), is(false)); + + col = MappingUtils.getMappingColumn(TestColType.class, "colLongTypeOpt"); + assertThat(col.getJavaType().getRawType(), sameInstance(Optional.class)); + assertThat(col.getJavaType().getParam(0).getRawType(), sameInstance(Long.class)); + assertThat(col.isOptional(), is(true)); + assertThat(col.isString(), is(false)); + assertThat(col.isNumber(), is(true)); + assertThat(col.isArray(), is(false)); + assertThat(col.isTemporal(), is(false)); + + col = MappingUtils.getMappingColumn(TestColType.class, "colFloatTypeOpt"); + assertThat(col.getJavaType().getRawType(), sameInstance(Optional.class)); + assertThat(col.getJavaType().getParam(0).getRawType(), sameInstance(Float.class)); + assertThat(col.isOptional(), is(true)); + assertThat(col.isString(), is(false)); + assertThat(col.isNumber(), is(true)); + assertThat(col.isArray(), is(false)); + assertThat(col.isTemporal(), is(false)); + + col = MappingUtils.getMappingColumn(TestColType.class, "colDoubleTypeOpt"); + assertThat(col.getJavaType().getRawType(), sameInstance(Optional.class)); + assertThat(col.getJavaType().getParam(0).getRawType(), sameInstance(Double.class)); + assertThat(col.isOptional(), is(true)); + assertThat(col.isString(), is(false)); + assertThat(col.isNumber(), is(true)); + assertThat(col.isArray(), is(false)); + assertThat(col.isTemporal(), is(false)); + + col = MappingUtils.getMappingColumn(TestColType.class, "colBigIntegerOpt"); + assertThat(col.getJavaType().getRawType(), sameInstance(Optional.class)); + assertThat(col.getJavaType().getParam(0).getRawType(), sameInstance(BigInteger.class)); + assertThat(col.isOptional(), is(true)); + assertThat(col.isString(), is(false)); + assertThat(col.isNumber(), is(true)); + assertThat(col.isArray(), is(false)); + assertThat(col.isTemporal(), is(false)); + + col = MappingUtils.getMappingColumn(TestColType.class, "colBigDecimalOpt"); + assertThat(col.getJavaType().getRawType(), sameInstance(Optional.class)); + assertThat(col.getJavaType().getParam(0).getRawType(), sameInstance(BigDecimal.class)); + assertThat(col.isOptional(), is(true)); + assertThat(col.isString(), is(false)); + assertThat(col.isNumber(), is(true)); + assertThat(col.isArray(), is(false)); + assertThat(col.isTemporal(), is(false)); + + // temporal + col = MappingUtils.getMappingColumn(TestColType.class, "colLocalDateOpt"); + assertThat(col.getJavaType().getRawType(), sameInstance(Optional.class)); + assertThat(col.getJavaType().getParam(0).getRawType(), sameInstance(LocalDate.class)); + assertThat(col.isOptional(), is(true)); + assertThat(col.isString(), is(false)); + assertThat(col.isNumber(), is(false)); + assertThat(col.isArray(), is(false)); + assertThat(col.isTemporal(), is(true)); + + col = MappingUtils.getMappingColumn(TestColType.class, "colLocalDateTimeOpt"); + assertThat(col.getJavaType().getRawType(), sameInstance(Optional.class)); + assertThat(col.getJavaType().getParam(0).getRawType(), sameInstance(LocalDateTime.class)); + assertThat(col.isOptional(), is(true)); + assertThat(col.isString(), is(false)); + assertThat(col.isNumber(), is(false)); + assertThat(col.isArray(), is(false)); + assertThat(col.isTemporal(), is(true)); + + col = MappingUtils.getMappingColumn(TestColType.class, "colOffsetDateTimeOpt"); + assertThat(col.getJavaType().getRawType(), sameInstance(Optional.class)); + assertThat(col.getJavaType().getParam(0).getRawType(), sameInstance(OffsetDateTime.class)); + assertThat(col.isOptional(), is(true)); + assertThat(col.isString(), is(false)); + assertThat(col.isNumber(), is(false)); + assertThat(col.isArray(), is(false)); + assertThat(col.isTemporal(), is(true)); + + col = MappingUtils.getMappingColumn(TestColType.class, "colZonedDateTimeOpt"); + assertThat(col.getJavaType().getRawType(), sameInstance(Optional.class)); + assertThat(col.getJavaType().getParam(0).getRawType(), sameInstance(ZonedDateTime.class)); + assertThat(col.isOptional(), is(true)); + assertThat(col.isString(), is(false)); + assertThat(col.isNumber(), is(false)); + assertThat(col.isArray(), is(false)); + assertThat(col.isTemporal(), is(true)); + + col = MappingUtils.getMappingColumn(TestColType.class, "colLocalTimeOpt"); + assertThat(col.getJavaType().getRawType(), sameInstance(Optional.class)); + assertThat(col.getJavaType().getParam(0).getRawType(), sameInstance(LocalTime.class)); + assertThat(col.isOptional(), is(true)); + assertThat(col.isString(), is(false)); + assertThat(col.isNumber(), is(false)); + assertThat(col.isArray(), is(false)); + assertThat(col.isTemporal(), is(true)); + + col = MappingUtils.getMappingColumn(TestColType.class, "colOffsetTimeOpt"); + assertThat(col.getJavaType().getRawType(), sameInstance(Optional.class)); + assertThat(col.getJavaType().getParam(0).getRawType(), sameInstance(OffsetTime.class)); + assertThat(col.isOptional(), is(true)); + assertThat(col.isString(), is(false)); + assertThat(col.isNumber(), is(false)); + assertThat(col.isArray(), is(false)); + assertThat(col.isTemporal(), is(true)); + + col = MappingUtils.getMappingColumn(TestColType.class, "colYearOpt"); + assertThat(col.getJavaType().getRawType(), sameInstance(Optional.class)); + assertThat(col.getJavaType().getParam(0).getRawType(), sameInstance(Year.class)); + assertThat(col.isOptional(), is(true)); + assertThat(col.isString(), is(false)); + assertThat(col.isNumber(), is(false)); + assertThat(col.isArray(), is(false)); + assertThat(col.isTemporal(), is(true)); + + col = MappingUtils.getMappingColumn(TestColType.class, "colYearMonthOpt"); + assertThat(col.getJavaType().getRawType(), sameInstance(Optional.class)); + assertThat(col.getJavaType().getParam(0).getRawType(), sameInstance(YearMonth.class)); + assertThat(col.isOptional(), is(true)); + assertThat(col.isString(), is(false)); + assertThat(col.isNumber(), is(false)); + assertThat(col.isArray(), is(false)); + assertThat(col.isTemporal(), is(true)); + + // lagacy datetime + col = MappingUtils.getMappingColumn(TestColType.class, "colUtilDateOpt"); + assertThat(col.getJavaType().getRawType(), sameInstance(Optional.class)); + assertThat(col.getJavaType().getParam(0).getRawType(), sameInstance(java.util.Date.class)); + assertThat(col.isOptional(), is(true)); + assertThat(col.isString(), is(false)); + assertThat(col.isNumber(), is(false)); + assertThat(col.isArray(), is(false)); + assertThat(col.isTemporal(), is(false)); + + col = MappingUtils.getMappingColumn(TestColType.class, "colSqlDateOpt"); + assertThat(col.getJavaType().getRawType(), sameInstance(Optional.class)); + assertThat(col.getJavaType().getParam(0).getRawType(), sameInstance(java.sql.Date.class)); + assertThat(col.isOptional(), is(true)); + assertThat(col.isString(), is(false)); + assertThat(col.isNumber(), is(false)); + assertThat(col.isArray(), is(false)); + assertThat(col.isTemporal(), is(false)); + + col = MappingUtils.getMappingColumn(TestColType.class, "colSqlTimeOpt"); + assertThat(col.getJavaType().getRawType(), sameInstance(Optional.class)); + assertThat(col.getJavaType().getParam(0).getRawType(), sameInstance(java.sql.Time.class)); + assertThat(col.isOptional(), is(true)); + assertThat(col.isString(), is(false)); + assertThat(col.isNumber(), is(false)); + assertThat(col.isArray(), is(false)); + assertThat(col.isTemporal(), is(false)); + + col = MappingUtils.getMappingColumn(TestColType.class, "colSqlTimestampOpt"); + assertThat(col.getJavaType().getRawType(), sameInstance(Optional.class)); + assertThat(col.getJavaType().getParam(0).getRawType(), sameInstance(java.sql.Timestamp.class)); + assertThat(col.isOptional(), is(true)); + assertThat(col.isString(), is(false)); + assertThat(col.isNumber(), is(false)); + assertThat(col.isArray(), is(false)); + assertThat(col.isTemporal(), is(false)); + + } + + @Test + public void testMappingColumnTypeArray() throws Exception { + // string + MappingColumn col = MappingUtils.getMappingColumn(TestColType.class, "colStrArr"); + assertThat(col.getJavaType().getRawType(), sameInstance(String[].class)); + assertThat(col.isOptional(), is(false)); + assertThat(col.isString(), is(false)); + assertThat(col.isNumber(), is(false)); + assertThat(col.isArray(), is(true)); + assertThat(col.isTemporal(), is(false)); + + col = MappingUtils.getMappingColumn(TestColType.class, "colCharArr"); + assertThat(col.getJavaType().getRawType(), sameInstance(char[].class)); + assertThat(col.isOptional(), is(false)); + assertThat(col.isString(), is(false)); + assertThat(col.isNumber(), is(false)); + assertThat(col.isArray(), is(true)); + assertThat(col.isTemporal(), is(false)); + + col = MappingUtils.getMappingColumn(TestColType.class, "colCharacterArr"); + assertThat(col.getJavaType().getRawType(), sameInstance(Character[].class)); + assertThat(col.isOptional(), is(false)); + assertThat(col.isString(), is(false)); + assertThat(col.isNumber(), is(false)); + assertThat(col.isArray(), is(true)); + assertThat(col.isTemporal(), is(false)); + + // number + col = MappingUtils.getMappingColumn(TestColType.class, "colShortArr"); + assertThat(col.getJavaType().getRawType(), sameInstance(short[].class)); + assertThat(col.isOptional(), is(false)); + assertThat(col.isString(), is(false)); + assertThat(col.isNumber(), is(false)); + assertThat(col.isArray(), is(true)); + assertThat(col.isTemporal(), is(false)); + + col = MappingUtils.getMappingColumn(TestColType.class, "colShortTypeArr"); + assertThat(col.getJavaType().getRawType(), sameInstance(Short[].class)); + assertThat(col.isOptional(), is(false)); + assertThat(col.isString(), is(false)); + assertThat(col.isNumber(), is(false)); + assertThat(col.isArray(), is(true)); + assertThat(col.isTemporal(), is(false)); + + col = MappingUtils.getMappingColumn(TestColType.class, "colIntArr"); + assertThat(col.getJavaType().getRawType(), sameInstance(int[].class)); + assertThat(col.isOptional(), is(false)); + assertThat(col.isString(), is(false)); + assertThat(col.isNumber(), is(false)); + assertThat(col.isArray(), is(true)); + assertThat(col.isTemporal(), is(false)); + + col = MappingUtils.getMappingColumn(TestColType.class, "colIntTypeArr"); + assertThat(col.getJavaType().getRawType(), sameInstance(Integer[].class)); + assertThat(col.isOptional(), is(false)); + assertThat(col.isString(), is(false)); + assertThat(col.isNumber(), is(false)); + assertThat(col.isArray(), is(true)); + assertThat(col.isTemporal(), is(false)); + + col = MappingUtils.getMappingColumn(TestColType.class, "colLongArr"); + assertThat(col.getJavaType().getRawType(), sameInstance(long[].class)); + assertThat(col.isOptional(), is(false)); + assertThat(col.isString(), is(false)); + assertThat(col.isNumber(), is(false)); + assertThat(col.isArray(), is(true)); + assertThat(col.isTemporal(), is(false)); + + col = MappingUtils.getMappingColumn(TestColType.class, "colLongTypeArr"); + assertThat(col.getJavaType().getRawType(), sameInstance(Long[].class)); + assertThat(col.isOptional(), is(false)); + assertThat(col.isString(), is(false)); + assertThat(col.isNumber(), is(false)); + assertThat(col.isArray(), is(true)); + assertThat(col.isTemporal(), is(false)); + + col = MappingUtils.getMappingColumn(TestColType.class, "colFloatArr"); + assertThat(col.getJavaType().getRawType(), sameInstance(float[].class)); + assertThat(col.isOptional(), is(false)); + assertThat(col.isString(), is(false)); + assertThat(col.isNumber(), is(false)); + assertThat(col.isArray(), is(true)); + assertThat(col.isTemporal(), is(false)); + + col = MappingUtils.getMappingColumn(TestColType.class, "colFloatTypeArr"); + assertThat(col.getJavaType().getRawType(), sameInstance(Float[].class)); + assertThat(col.isOptional(), is(false)); + assertThat(col.isString(), is(false)); + assertThat(col.isNumber(), is(false)); + assertThat(col.isArray(), is(true)); + assertThat(col.isTemporal(), is(false)); + + col = MappingUtils.getMappingColumn(TestColType.class, "colDoubleArr"); + assertThat(col.getJavaType().getRawType(), sameInstance(double[].class)); + assertThat(col.isOptional(), is(false)); + assertThat(col.isString(), is(false)); + assertThat(col.isNumber(), is(false)); + assertThat(col.isArray(), is(true)); + assertThat(col.isTemporal(), is(false)); + + col = MappingUtils.getMappingColumn(TestColType.class, "colDoubleTypeArr"); + assertThat(col.getJavaType().getRawType(), sameInstance(Double[].class)); + assertThat(col.isOptional(), is(false)); + assertThat(col.isString(), is(false)); + assertThat(col.isNumber(), is(false)); + assertThat(col.isArray(), is(true)); + assertThat(col.isTemporal(), is(false)); + + col = MappingUtils.getMappingColumn(TestColType.class, "colBigIntegerArr"); + assertThat(col.getJavaType().getRawType(), sameInstance(BigInteger[].class)); + assertThat(col.isOptional(), is(false)); + assertThat(col.isString(), is(false)); + assertThat(col.isNumber(), is(false)); + assertThat(col.isArray(), is(true)); + assertThat(col.isTemporal(), is(false)); + + col = MappingUtils.getMappingColumn(TestColType.class, "colBigDecimalArr"); + assertThat(col.getJavaType().getRawType(), sameInstance(BigDecimal[].class)); + assertThat(col.isOptional(), is(false)); + assertThat(col.isString(), is(false)); + assertThat(col.isNumber(), is(false)); + assertThat(col.isArray(), is(true)); + assertThat(col.isTemporal(), is(false)); + + // temporal + col = MappingUtils.getMappingColumn(TestColType.class, "colLocalDateArr"); + assertThat(col.getJavaType().getRawType(), sameInstance(LocalDate[].class)); + assertThat(col.isOptional(), is(false)); + assertThat(col.isString(), is(false)); + assertThat(col.isNumber(), is(false)); + assertThat(col.isArray(), is(true)); + assertThat(col.isTemporal(), is(false)); + + col = MappingUtils.getMappingColumn(TestColType.class, "colLocalDateTimeArr"); + assertThat(col.getJavaType().getRawType(), sameInstance(LocalDateTime[].class)); + assertThat(col.isOptional(), is(false)); + assertThat(col.isString(), is(false)); + assertThat(col.isNumber(), is(false)); + assertThat(col.isArray(), is(true)); + assertThat(col.isTemporal(), is(false)); + + col = MappingUtils.getMappingColumn(TestColType.class, "colOffsetDateTimeArr"); + assertThat(col.getJavaType().getRawType(), sameInstance(OffsetDateTime[].class)); + assertThat(col.isOptional(), is(false)); + assertThat(col.isString(), is(false)); + assertThat(col.isNumber(), is(false)); + assertThat(col.isArray(), is(true)); + assertThat(col.isTemporal(), is(false)); + + col = MappingUtils.getMappingColumn(TestColType.class, "colZonedDateTimeArr"); + assertThat(col.getJavaType().getRawType(), sameInstance(ZonedDateTime[].class)); + assertThat(col.isOptional(), is(false)); + assertThat(col.isString(), is(false)); + assertThat(col.isNumber(), is(false)); + assertThat(col.isArray(), is(true)); + assertThat(col.isTemporal(), is(false)); + + col = MappingUtils.getMappingColumn(TestColType.class, "colLocalTimeArr"); + assertThat(col.getJavaType().getRawType(), sameInstance(LocalTime[].class)); + assertThat(col.isOptional(), is(false)); + assertThat(col.isString(), is(false)); + assertThat(col.isNumber(), is(false)); + assertThat(col.isArray(), is(true)); + assertThat(col.isTemporal(), is(false)); + + col = MappingUtils.getMappingColumn(TestColType.class, "colOffsetTimeArr"); + assertThat(col.getJavaType().getRawType(), sameInstance(OffsetTime[].class)); + assertThat(col.isOptional(), is(false)); + assertThat(col.isString(), is(false)); + assertThat(col.isNumber(), is(false)); + assertThat(col.isArray(), is(true)); + assertThat(col.isTemporal(), is(false)); + + col = MappingUtils.getMappingColumn(TestColType.class, "colYearArr"); + assertThat(col.getJavaType().getRawType(), sameInstance(Year[].class)); + assertThat(col.isOptional(), is(false)); + assertThat(col.isString(), is(false)); + assertThat(col.isNumber(), is(false)); + assertThat(col.isArray(), is(true)); + assertThat(col.isTemporal(), is(false)); + + col = MappingUtils.getMappingColumn(TestColType.class, "colYearMonthArr"); + assertThat(col.getJavaType().getRawType(), sameInstance(YearMonth[].class)); + assertThat(col.isOptional(), is(false)); + assertThat(col.isString(), is(false)); + assertThat(col.isNumber(), is(false)); + assertThat(col.isArray(), is(true)); + assertThat(col.isTemporal(), is(false)); + + // lagacy datetime + col = MappingUtils.getMappingColumn(TestColType.class, "colUtilDateArr"); + assertThat(col.getJavaType().getRawType(), sameInstance(java.util.Date[].class)); + assertThat(col.isOptional(), is(false)); + assertThat(col.isString(), is(false)); + assertThat(col.isNumber(), is(false)); + assertThat(col.isArray(), is(true)); + assertThat(col.isTemporal(), is(false)); + + col = MappingUtils.getMappingColumn(TestColType.class, "colSqlDateArr"); + assertThat(col.getJavaType().getRawType(), sameInstance(java.sql.Date[].class)); + assertThat(col.isOptional(), is(false)); + assertThat(col.isString(), is(false)); + assertThat(col.isNumber(), is(false)); + assertThat(col.isArray(), is(true)); + assertThat(col.isTemporal(), is(false)); + + col = MappingUtils.getMappingColumn(TestColType.class, "colSqlTimeArr"); + assertThat(col.getJavaType().getRawType(), sameInstance(java.sql.Time[].class)); + assertThat(col.isOptional(), is(false)); + assertThat(col.isString(), is(false)); + assertThat(col.isNumber(), is(false)); + assertThat(col.isArray(), is(true)); + assertThat(col.isTemporal(), is(false)); + + col = MappingUtils.getMappingColumn(TestColType.class, "colSqlTimestampArr"); + assertThat(col.getJavaType().getRawType(), sameInstance(java.sql.Timestamp[].class)); + assertThat(col.isOptional(), is(false)); + assertThat(col.isString(), is(false)); + assertThat(col.isNumber(), is(false)); + assertThat(col.isArray(), is(true)); + assertThat(col.isTemporal(), is(false)); + + } + + @Test + public void testClearCache() throws Exception { + MappingUtils.clearCache(); + } + + @Table(name = "TEST") + public static class TestColType { + private String colStr; + private char colChar; + private Character colCharacter; + private short colShort; + private Short colShortType; + private int colInt; + private Integer colIntType; + private long colLong; + private Long colLongType; + private float colFloat; + private Float colFloatType; + private double colDouble; + private Double colDoubleType; + private BigInteger colBigInteger; + private BigDecimal colBigDecimal; + private LocalDate colLocalDate; + private LocalDateTime colLocalDateTime; + private OffsetDateTime colOffsetDateTime; + private ZonedDateTime colZonedDateTime; + private LocalTime colLocalTime; + private OffsetTime colOffsetTime; + private Year colYear; + private YearMonth colYearMonth; + private java.util.Date colUtilDate; + private java.sql.Date colSqlDate; + private java.sql.Time colSqlTime; + private java.sql.Timestamp colSqlTimestamp; + + // Optional + private Optional colStrOpt; + private Optional colCharacterOpt; + private Optional colShortTypeOpt; + private Optional colIntTypeOpt; + private Optional colLongTypeOpt; + private Optional colFloatTypeOpt; + private Optional colDoubleTypeOpt; + private Optional colBigIntegerOpt; + private Optional colBigDecimalOpt; + private Optional colLocalDateOpt; + private Optional colLocalDateTimeOpt; + private Optional colOffsetDateTimeOpt; + private Optional colZonedDateTimeOpt; + private Optional colLocalTimeOpt; + private Optional colOffsetTimeOpt; + private Optional colYearOpt; + private Optional colYearMonthOpt; + private Optional colUtilDateOpt; + private Optional colSqlDateOpt; + private Optional colSqlTimeOpt; + private Optional colSqlTimestampOpt; + + // Array + private String[] colStrArr; + private char[] colCharArr; + private Character[] colCharacterArr; + private short[] colShortArr; + private Short[] colShortTypeArr; + private int[] colIntArr; + private Integer[] colIntTypeArr; + private long[] colLongArr; + private Long[] colLongTypeArr; + private float[] colFloatArr; + private Float[] colFloatTypeArr; + private double[] colDoubleArr; + private Double[] colDoubleTypeArr; + private BigInteger[] colBigIntegerArr; + private BigDecimal[] colBigDecimalArr; + private LocalDate[] colLocalDateArr; + private LocalDateTime[] colLocalDateTimeArr; + private OffsetDateTime[] colOffsetDateTimeArr; + private ZonedDateTime[] colZonedDateTimeArr; + private LocalTime[] colLocalTimeArr; + private OffsetTime[] colOffsetTimeArr; + private Year[] colYearArr; + private YearMonth[] colYearMonthArr; + private java.util.Date[] colUtilDateArr; + private java.sql.Date[] colSqlDateArr; + private java.sql.Time[] colSqlTimeArr; + private java.sql.Timestamp[] colSqlTimestampArr; + + public TestColType() { + } + + public String getColStr() { + return colStr; + } + + public void setColStr(final String colStr) { + this.colStr = colStr; + } + + public char getColChar() { + return colChar; + } + + public void setColChar(final char colChar) { + this.colChar = colChar; + } + + public Character getColCharacter() { + return colCharacter; + } + + public void setColCharacter(final Character colCharacter) { + this.colCharacter = colCharacter; + } + + public short getColShort() { + return colShort; + } + + public void setColShort(final short colShort) { + this.colShort = colShort; + } + + public Short getColShortType() { + return colShortType; + } + + public void setColShortType(final Short colShortType) { + this.colShortType = colShortType; + } + + public int getColInt() { + return colInt; + } + + public void setColInt(final int colInt) { + this.colInt = colInt; + } + + public Integer getColIntType() { + return colIntType; + } + + public void setColIntType(final Integer colIntType) { + this.colIntType = colIntType; + } + + public long getColLong() { + return colLong; + } + + public void setColLong(final long colLong) { + this.colLong = colLong; + } + + public Long getColLongType() { + return colLongType; + } + + public void setColLongType(final Long colLongType) { + this.colLongType = colLongType; + } + + public float getColFloat() { + return colFloat; + } + + public void setColFloat(final float colFloat) { + this.colFloat = colFloat; + } + + public Float getColFloatType() { + return colFloatType; + } + + public void setColFloatType(final Float colFloatType) { + this.colFloatType = colFloatType; + } + + public double getColDouble() { + return colDouble; + } + + public void setColDouble(final double colDouble) { + this.colDouble = colDouble; + } + + public Double getColDoubleType() { + return colDoubleType; + } + + public void setColDoubleType(final Double colDoubleType) { + this.colDoubleType = colDoubleType; + } + + public BigInteger getColBigInteger() { + return colBigInteger; + } + + public void setColBigInteger(final BigInteger colBigInteger) { + this.colBigInteger = colBigInteger; + } + + public BigDecimal getColBigDecimal() { + return colBigDecimal; + } + + public void setColBigDecimal(final BigDecimal colBigDecimal) { + this.colBigDecimal = colBigDecimal; + } + + public LocalDate getColLocalDate() { + return colLocalDate; + } + + public void setColLocalDate(final LocalDate colLocalDate) { + this.colLocalDate = colLocalDate; + } + + public LocalDateTime getColLocalDateTime() { + return colLocalDateTime; + } + + public void setColLocalDateTime(final LocalDateTime colLocalDateTime) { + this.colLocalDateTime = colLocalDateTime; + } + + public OffsetDateTime getColOffsetDateTime() { + return colOffsetDateTime; + } + + public void setColOffsetDateTime(final OffsetDateTime colOffsetDateTime) { + this.colOffsetDateTime = colOffsetDateTime; + } + + public ZonedDateTime getColZonedDateTime() { + return colZonedDateTime; + } + + public void setColZonedDateTime(final ZonedDateTime colZonedDateTime) { + this.colZonedDateTime = colZonedDateTime; + } + + public LocalTime getColLocalTime() { + return colLocalTime; + } + + public void setColLocalTime(final LocalTime colLocalTime) { + this.colLocalTime = colLocalTime; + } + + public OffsetTime getColOffsetTime() { + return colOffsetTime; + } + + public void setColOffsetTime(final OffsetTime colOffsetTime) { + this.colOffsetTime = colOffsetTime; + } + + public Year getColYear() { + return colYear; + } + + public void setColYear(final Year colYear) { + this.colYear = colYear; + } + + public YearMonth getColYearMonth() { + return colYearMonth; + } + + public void setColYearMonth(final YearMonth colYearMonth) { + this.colYearMonth = colYearMonth; + } + + public java.util.Date getColUtilDate() { + return colUtilDate; + } + + public void setColUtilDate(final java.util.Date colUtilDate) { + this.colUtilDate = colUtilDate; + } + + public java.sql.Date getColSqlDate() { + return colSqlDate; + } + + public void setColSqlDate(final java.sql.Date colSqlDate) { + this.colSqlDate = colSqlDate; + } + + public java.sql.Time getColSqlTime() { + return colSqlTime; + } + + public void setColSqlTime(final java.sql.Time colSqlTime) { + this.colSqlTime = colSqlTime; + } + + public java.sql.Timestamp getColSqlTimestamp() { + return colSqlTimestamp; + } + + public void setColSqlTimestamp(final java.sql.Timestamp colSqlTimestamp) { + this.colSqlTimestamp = colSqlTimestamp; + } + + public Optional getColStrOpt() { + return colStrOpt; + } + + public void setColStrOpt(final Optional colStrOpt) { + this.colStrOpt = colStrOpt; + } + + public Optional getColCharacterOpt() { + return colCharacterOpt; + } + + public void setColCharacterOpt(final Optional colCharacterOpt) { + this.colCharacterOpt = colCharacterOpt; + } + + public Optional getColShortTypeOpt() { + return colShortTypeOpt; + } + + public void setColShortTypeOpt(final Optional colShortTypeOpt) { + this.colShortTypeOpt = colShortTypeOpt; + } + + public Optional getColIntTypeOpt() { + return colIntTypeOpt; + } + + public void setColIntTypeOpt(final Optional colIntTypeOpt) { + this.colIntTypeOpt = colIntTypeOpt; + } + + public Optional getColLongTypeOpt() { + return colLongTypeOpt; + } + + public void setColLongTypeOpt(final Optional colLongTypeOpt) { + this.colLongTypeOpt = colLongTypeOpt; + } + + public Optional getColFloatTypeOpt() { + return colFloatTypeOpt; + } + + public void setColFloatTypeOpt(final Optional colFloatTypeOpt) { + this.colFloatTypeOpt = colFloatTypeOpt; + } + + public Optional getColDoubleTypeOpt() { + return colDoubleTypeOpt; + } + + public void setColDoubleTypeOpt(final Optional colDoubleTypeOpt) { + this.colDoubleTypeOpt = colDoubleTypeOpt; + } + + public Optional getColBigIntegerOpt() { + return colBigIntegerOpt; + } + + public void setColBigIntegerOpt(final Optional colBigIntegerOpt) { + this.colBigIntegerOpt = colBigIntegerOpt; + } + + public Optional getColBigDecimalOpt() { + return colBigDecimalOpt; + } + + public void setColBigDecimalOpt(final Optional colBigDecimalOpt) { + this.colBigDecimalOpt = colBigDecimalOpt; + } + + public Optional getColLocalDateOpt() { + return colLocalDateOpt; + } + + public void setColLocalDateOpt(final Optional colLocalDateOpt) { + this.colLocalDateOpt = colLocalDateOpt; + } + + public Optional getColLocalDateTimeOpt() { + return colLocalDateTimeOpt; + } + + public void setColLocalDateTimeOpt(final Optional colLocalDateTimeOpt) { + this.colLocalDateTimeOpt = colLocalDateTimeOpt; + } + + public Optional getColOffsetDateTimeOpt() { + return colOffsetDateTimeOpt; + } + + public void setColOffsetDateTimeOpt(final Optional colOffsetDateTimeOpt) { + this.colOffsetDateTimeOpt = colOffsetDateTimeOpt; + } + + public Optional getColZonedDateTimeOpt() { + return colZonedDateTimeOpt; + } + + public void setColZonedDateTimeOpt(final Optional colZonedDateTimeOpt) { + this.colZonedDateTimeOpt = colZonedDateTimeOpt; + } + + public Optional getColLocalTimeOpt() { + return colLocalTimeOpt; + } + + public void setColLocalTimeOpt(final Optional colLocalTimeOpt) { + this.colLocalTimeOpt = colLocalTimeOpt; + } + + public Optional getColOffsetTimeOpt() { + return colOffsetTimeOpt; + } + + public void setColOffsetTimeOpt(final Optional colOffsetTimeOpt) { + this.colOffsetTimeOpt = colOffsetTimeOpt; + } + + public Optional getColYearOpt() { + return colYearOpt; + } + + public void setColYearOpt(final Optional colYearOpt) { + this.colYearOpt = colYearOpt; + } + + public Optional getColYearMonthOpt() { + return colYearMonthOpt; + } + + public void setColYearMonthOpt(final Optional colYearMonthOpt) { + this.colYearMonthOpt = colYearMonthOpt; + } + + public Optional getColUtilDateOpt() { + return colUtilDateOpt; + } + + public void setColUtilDateOpt(final Optional colUtilDateOpt) { + this.colUtilDateOpt = colUtilDateOpt; + } + + public Optional getColSqlDateOpt() { + return colSqlDateOpt; + } + + public void setColSqlDateOpt(final Optional colSqlDateOpt) { + this.colSqlDateOpt = colSqlDateOpt; + } + + public Optional getColSqlTimeOpt() { + return colSqlTimeOpt; + } + + public void setColSqlTimeOpt(final Optional colSqlTimeOpt) { + this.colSqlTimeOpt = colSqlTimeOpt; + } + + public Optional getColSqlTimestampOpt() { + return colSqlTimestampOpt; + } + + public void setColSqlTimestampOpt(final Optional colSqlTimestampOpt) { + this.colSqlTimestampOpt = colSqlTimestampOpt; + } + + public String[] getColStrArr() { + return colStrArr; + } + + public void setColStrArr(final String[] colStrArr) { + this.colStrArr = colStrArr; + } + + public char[] getColCharArr() { + return colCharArr; + } + + public void setColCharArr(final char[] colCharArr) { + this.colCharArr = colCharArr; + } + + public Character[] getColCharacterArr() { + return colCharacterArr; + } + + public void setColCharacterArr(final Character[] colCharacterArr) { + this.colCharacterArr = colCharacterArr; + } + + public short[] getColShortArr() { + return colShortArr; + } + + public void setColShortArr(final short[] colShortArr) { + this.colShortArr = colShortArr; + } + + public Short[] getColShortTypeArr() { + return colShortTypeArr; + } + + public void setColShortTypeArr(final Short[] colShortTypeArr) { + this.colShortTypeArr = colShortTypeArr; + } + + public int[] getColIntArr() { + return colIntArr; + } + + public void setColIntArr(final int[] colIntArr) { + this.colIntArr = colIntArr; + } + + public Integer[] getColIntTypeArr() { + return colIntTypeArr; + } + + public void setColIntTypeArr(final Integer[] colIntTypeArr) { + this.colIntTypeArr = colIntTypeArr; + } + + public long[] getColLongArr() { + return colLongArr; + } + + public void setColLongArr(final long[] colLongArr) { + this.colLongArr = colLongArr; + } + + public Long[] getColLongTypeArr() { + return colLongTypeArr; + } + + public void setColLongTypeArr(final Long[] colLongTypeArr) { + this.colLongTypeArr = colLongTypeArr; + } + + public float[] getColFloatArr() { + return colFloatArr; + } + + public void setColFloatArr(final float[] colFloatArr) { + this.colFloatArr = colFloatArr; + } + + public Float[] getColFloatTypeArr() { + return colFloatTypeArr; + } + + public void setColFloatTypeArr(final Float[] colFloatTypeArr) { + this.colFloatTypeArr = colFloatTypeArr; + } + + public double[] getColDoubleArr() { + return colDoubleArr; + } + + public void setColDoubleArr(final double[] colDoubleArr) { + this.colDoubleArr = colDoubleArr; + } + + public Double[] getColDoubleTypeArr() { + return colDoubleTypeArr; + } + + public void setColDoubleTypeArr(final Double[] colDoubleTypeArr) { + this.colDoubleTypeArr = colDoubleTypeArr; + } + + public BigInteger[] getColBigIntegerArr() { + return colBigIntegerArr; + } + + public void setColBigIntegerArr(final BigInteger[] colBigIntegerArr) { + this.colBigIntegerArr = colBigIntegerArr; + } + + public BigDecimal[] getColBigDecimalArr() { + return colBigDecimalArr; + } + + public void setColBigDecimalArr(final BigDecimal[] colBigDecimalArr) { + this.colBigDecimalArr = colBigDecimalArr; + } + + public LocalDate[] getColLocalDateArr() { + return colLocalDateArr; + } + + public void setColLocalDateArr(final LocalDate[] colLocalDateArr) { + this.colLocalDateArr = colLocalDateArr; + } + + public LocalDateTime[] getColLocalDateTimeArr() { + return colLocalDateTimeArr; + } + + public void setColLocalDateTimeArr(final LocalDateTime[] colLocalDateTimeArr) { + this.colLocalDateTimeArr = colLocalDateTimeArr; + } + + public OffsetDateTime[] getColOffsetDateTimeArr() { + return colOffsetDateTimeArr; + } + + public void setColOffsetDateTimeArr(final OffsetDateTime[] colOffsetDateTimeArr) { + this.colOffsetDateTimeArr = colOffsetDateTimeArr; + } + + public ZonedDateTime[] getColZonedDateTimeArr() { + return colZonedDateTimeArr; + } + + public void setColZonedDateTimeArr(final ZonedDateTime[] colZonedDateTimeArr) { + this.colZonedDateTimeArr = colZonedDateTimeArr; + } + + public LocalTime[] getColLocalTimeArr() { + return colLocalTimeArr; + } + + public void setColLocalTimeArr(final LocalTime[] colLocalTimeArr) { + this.colLocalTimeArr = colLocalTimeArr; + } + + public OffsetTime[] getColOffsetTimeArr() { + return colOffsetTimeArr; + } + + public void setColOffsetTimeArr(final OffsetTime[] colOffsetTimeArr) { + this.colOffsetTimeArr = colOffsetTimeArr; + } + + public Year[] getColYearArr() { + return colYearArr; + } + + public void setColYearArr(final Year[] colYearArr) { + this.colYearArr = colYearArr; + } + + public YearMonth[] getColYearMonthArr() { + return colYearMonthArr; + } + + public void setColYearMonthArr(final YearMonth[] colYearMonthArr) { + this.colYearMonthArr = colYearMonthArr; + } + + public java.util.Date[] getColUtilDateArr() { + return colUtilDateArr; + } + + public void setColUtilDateArr(final java.util.Date[] colUtilDateArr) { + this.colUtilDateArr = colUtilDateArr; + } + + public java.sql.Date[] getColSqlDateArr() { + return colSqlDateArr; + } + + public void setColSqlDateArr(final java.sql.Date[] colSqlDateArr) { + this.colSqlDateArr = colSqlDateArr; + } + + public java.sql.Time[] getColSqlTimeArr() { + return colSqlTimeArr; + } + + public void setColSqlTimeArr(final java.sql.Time[] colSqlTimeArr) { + this.colSqlTimeArr = colSqlTimeArr; + } + + public java.sql.Timestamp[] getColSqlTimestampArr() { + return colSqlTimestampArr; + } + + public void setColSqlTimestampArr(final java.sql.Timestamp[] colSqlTimestampArr) { + this.colSqlTimestampArr = colSqlTimestampArr; + } + + } +} diff --git a/src/test/java/jp/co/future/uroborosql/mapping/TestEntity4.java b/src/test/java/jp/co/future/uroborosql/mapping/TestEntity4.java new file mode 100644 index 00000000..5b7d0b66 --- /dev/null +++ b/src/test/java/jp/co/future/uroborosql/mapping/TestEntity4.java @@ -0,0 +1,124 @@ +package jp.co.future.uroborosql.mapping; + +import java.math.BigDecimal; +import java.time.LocalDate; +import java.util.Objects; + +import jp.co.future.uroborosql.mapping.annotations.Table; +import jp.co.future.uroborosql.mapping.annotations.Version; + +@Table(name = "TEST") +public class TestEntity4 { + private Long id; + private String name; + private BigDecimal age; + private LocalDate birthday; + @Version + private Integer lockVersion = 0; + + public TestEntity4() { + } + + public TestEntity4(final Long id, final String name, final BigDecimal age, final LocalDate birthday) { + this.id = id; + this.name = name; + this.age = age; + this.birthday = birthday; + } + + public interface Names { + String Id = "id"; + String Name = "name"; + String Age = "age"; + String Birthday = "birthday"; + } + + public interface Cols { + String Id = "id"; + String Name = "name"; + String Age = "age"; + String Birthday = "birthday"; + } + + public Long getId() { + return this.id; + } + + public String getName() { + return this.name; + } + + public BigDecimal getAge() { + return this.age; + } + + public LocalDate getBirthday() { + return this.birthday; + } + + public void setId(final Long id) { + this.id = id; + } + + public void setName(final String name) { + this.name = name; + } + + public void setAge(final BigDecimal age) { + this.age = age; + } + + public void setBirthday(final LocalDate birthday) { + this.birthday = birthday; + } + + public Integer getLockVersion() { + return lockVersion; + } + + public void setLockVersion(final Integer lockVersion) { + this.lockVersion = lockVersion; + } + + @Override + public int hashCode() { + return Objects.hash(age, birthday, id, lockVersion, name); + } + + @Override + public boolean equals(final Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + TestEntity4 other = (TestEntity4) obj; + if (!Objects.equals(age, other.age)) { + return false; + } + if (!Objects.equals(birthday, other.birthday)) { + return false; + } + if (!Objects.equals(id, other.id)) { + return false; + } + if (!Objects.equals(lockVersion, other.lockVersion)) { + return false; + } + if (!Objects.equals(name, other.name)) { + return false; + } + return true; + } + + @Override + public String toString() { + return "TestEntity4 [id=" + id + ", name=" + name + ", age=" + age + ", birthday=" + birthday + ", lockVersion=" + + lockVersion + "]"; + } + +} diff --git a/src/test/java/jp/co/future/uroborosql/mapping/TestEntity5.java b/src/test/java/jp/co/future/uroborosql/mapping/TestEntity5.java new file mode 100644 index 00000000..3fae4f73 --- /dev/null +++ b/src/test/java/jp/co/future/uroborosql/mapping/TestEntity5.java @@ -0,0 +1,125 @@ +package jp.co.future.uroborosql.mapping; + +import java.math.BigDecimal; +import java.time.LocalDate; +import java.util.Objects; +import java.util.Optional; + +import jp.co.future.uroborosql.mapping.annotations.Table; +import jp.co.future.uroborosql.mapping.annotations.Version; + +@Table(name = "TEST") +public class TestEntity5 { + private Long id; + private String name; + private Optional age; + private LocalDate birthday; + @Version + private Integer lockVersion = 0; + + public TestEntity5() { + } + + public TestEntity5(final Long id, final String name, final Optional age, final LocalDate birthday) { + this.id = id; + this.name = name; + this.age = age; + this.birthday = birthday; + } + + public interface Names { + String Id = "id"; + String Name = "name"; + String Age = "age"; + String Birthday = "birthday"; + } + + public interface Cols { + String Id = "id"; + String Name = "name"; + String Age = "age"; + String Birthday = "birthday"; + } + + public Long getId() { + return this.id; + } + + public String getName() { + return this.name; + } + + public Optional getAge() { + return this.age; + } + + public LocalDate getBirthday() { + return this.birthday; + } + + public void setId(final Long id) { + this.id = id; + } + + public void setName(final String name) { + this.name = name; + } + + public void setAge(final Optional age) { + this.age = age; + } + + public void setBirthday(final LocalDate birthday) { + this.birthday = birthday; + } + + public Integer getLockVersion() { + return lockVersion; + } + + public void setLockVersion(final Integer lockVersion) { + this.lockVersion = lockVersion; + } + + @Override + public int hashCode() { + return Objects.hash(age, birthday, id, lockVersion, name); + } + + @Override + public boolean equals(final Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + TestEntity5 other = (TestEntity5) obj; + if (!Objects.equals(age, other.age)) { + return false; + } + if (!Objects.equals(birthday, other.birthday)) { + return false; + } + if (!Objects.equals(id, other.id)) { + return false; + } + if (!Objects.equals(lockVersion, other.lockVersion)) { + return false; + } + if (!Objects.equals(name, other.name)) { + return false; + } + return true; + } + + @Override + public String toString() { + return "TestEntity5 [id=" + id + ", name=" + name + ", age=" + age + ", birthday=" + birthday + ", lockVersion=" + + lockVersion + "]"; + } + +}