From d47789c70f3d1fc2e0471e1e76ba7baec2d4bb03 Mon Sep 17 00:00:00 2001 From: Hishida Masato Date: Fri, 19 Jul 2024 12:14:33 +0900 Subject: [PATCH] feat: ambiguous column name --- .../result/TsurugiResultIndexEntity.java | 764 ++++++ .../result/TsurugiResultNameEntity.java | 764 ++++++ .../tsurugidb/iceaxe/result/package-info.java | 4 + .../sql/result/IceaxeResultNameList.java | 191 ++ .../iceaxe/sql/result/TsurugiQueryResult.java | 23 +- .../sql/result/TsurugiResultEntity.java | 918 +------ .../sql/result/TsurugiResultIndexRecord.java | 949 +++++++ .../sql/result/TsurugiResultNameRecord.java | 949 +++++++ .../sql/result/TsurugiResultNextRecord.java | 897 +++++++ .../sql/result/TsurugiResultRecord.java | 2173 ++--------------- .../result/mapping/TgEntityResultMapping.java | 59 +- .../sql/result/IceaxeResultNameListTest.java | 178 ++ .../iceaxe/example/Example31Select.java | 42 +- 13 files changed, 5049 insertions(+), 2862 deletions(-) create mode 100755 modules/iceaxe-core/src/main/java/com/tsurugidb/iceaxe/result/TsurugiResultIndexEntity.java create mode 100755 modules/iceaxe-core/src/main/java/com/tsurugidb/iceaxe/result/TsurugiResultNameEntity.java create mode 100755 modules/iceaxe-core/src/main/java/com/tsurugidb/iceaxe/result/package-info.java create mode 100755 modules/iceaxe-core/src/main/java/com/tsurugidb/iceaxe/sql/result/IceaxeResultNameList.java create mode 100755 modules/iceaxe-core/src/main/java/com/tsurugidb/iceaxe/sql/result/TsurugiResultIndexRecord.java create mode 100755 modules/iceaxe-core/src/main/java/com/tsurugidb/iceaxe/sql/result/TsurugiResultNameRecord.java create mode 100755 modules/iceaxe-core/src/main/java/com/tsurugidb/iceaxe/sql/result/TsurugiResultNextRecord.java create mode 100755 modules/iceaxe-core/src/test/java/com/tsurugidb/iceaxe/sql/result/IceaxeResultNameListTest.java diff --git a/modules/iceaxe-core/src/main/java/com/tsurugidb/iceaxe/result/TsurugiResultIndexEntity.java b/modules/iceaxe-core/src/main/java/com/tsurugidb/iceaxe/result/TsurugiResultIndexEntity.java new file mode 100755 index 00000000..acd605f9 --- /dev/null +++ b/modules/iceaxe-core/src/main/java/com/tsurugidb/iceaxe/result/TsurugiResultIndexEntity.java @@ -0,0 +1,764 @@ +package com.tsurugidb.iceaxe.result; + +import java.math.BigDecimal; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.time.OffsetDateTime; +import java.time.OffsetTime; +import java.time.ZoneId; +import java.time.ZonedDateTime; +import java.util.Objects; +import java.util.Optional; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +import com.tsurugidb.iceaxe.util.IceaxeConvertUtil; + +/** + * Tsurugi Result Entity for index access. + * + * @since 1.5.0 + */ +public interface TsurugiResultIndexEntity { + + /** + * get value. + * + * @param index column index + * @return value + */ + public @Nullable Object getValueOrNull(int index); + + /** + * get convert utility. + * + * @return convert utility + */ + public IceaxeConvertUtil getConvertUtil(); + + // boolean + + /** + * get value as boolean. + * + * @param index column index + * @return value + * @throws NullPointerException if value is null + */ + public default boolean getBoolean(int index) { + var value = getBooleanOrNull(index); + return Objects.requireNonNull(value, () -> "getBoolean(" + index + ") is null"); + } + + /** + * get value as boolean. + * + * @param index column index + * @param defaultValue value to return if original value is null + * @return value + */ + public default boolean getBoolean(int index, boolean defaultValue) { + var value = getBooleanOrNull(index); + return (value != null) ? value : defaultValue; + } + + /** + * get value as boolean. + * + * @param index column index + * @return value + */ + public default @Nonnull Optional findBoolean(int index) { + var value = getBooleanOrNull(index); + return Optional.ofNullable(value); + } + + /** + * get value as boolean. + * + * @param index column index + * @return value + */ + public default @Nullable Boolean getBooleanOrNull(int index) { + var value = getValueOrNull(index); + return getConvertUtil().toBoolean(value); + } + + // int + + /** + * get value as int. + * + * @param index column index + * @return value + * @throws NullPointerException if value is null + */ + public default int getInt(int index) { + var value = getIntOrNull(index); + return Objects.requireNonNull(value, () -> "getInt(" + index + ") is null"); + } + + /** + * get value as int. + * + * @param index column index + * @param defaultValue value to return if original value is null + * @return value + */ + public default int getInt(int index, int defaultValue) { + var value = getIntOrNull(index); + return (value != null) ? value : defaultValue; + } + + /** + * get value as int. + * + * @param index column index + * @return value + */ + public default @Nonnull Optional findInt(int index) { + var value = getIntOrNull(index); + return Optional.ofNullable(value); + } + + /** + * get value as int. + * + * @param index column index + * @return value + */ + public default @Nullable Integer getIntOrNull(int index) { + var value = getValueOrNull(index); + return getConvertUtil().toInt(value); + } + + // long + + /** + * get value as long. + * + * @param index column index + * @return value + * @throws NullPointerException if value is null + */ + public default long getLong(int index) { + var value = getLongOrNull(index); + return Objects.requireNonNull(value, () -> "getLong(" + index + ") is null"); + } + + /** + * get value as long. + * + * @param index column index + * @param defaultValue value to return if original value is null + * @return value + */ + public default long getLong(int index, long defaultValue) { + var value = getLongOrNull(index); + return (value != null) ? value : defaultValue; + } + + /** + * get value as long. + * + * @param index column index + * @return value + */ + public default @Nonnull Optional findLong(int index) { + var value = getLongOrNull(index); + return Optional.ofNullable(value); + } + + /** + * get value as long. + * + * @param index column index + * @return value + */ + public default @Nullable Long getLongOrNull(int index) { + var value = getValueOrNull(index); + return getConvertUtil().toLong(value); + } + + // float + + /** + * get value as float. + * + * @param index column index + * @return value + * @throws NullPointerException if value is null + */ + public default float getFloat(int index) { + var value = getFloatOrNull(index); + return Objects.requireNonNull(value, () -> "getFloat(" + index + ") is null"); + } + + /** + * get value as float. + * + * @param index column index + * @param defaultValue value to return if original value is null + * @return value + */ + public default float getFloat(int index, float defaultValue) { + var value = getFloatOrNull(index); + return (value != null) ? value : defaultValue; + } + + /** + * get value as float. + * + * @param index column index + * @return value + */ + public default @Nonnull Optional findFloat(int index) { + var value = getFloatOrNull(index); + return Optional.ofNullable(value); + } + + /** + * get value as float. + * + * @param index column index + * @return value + */ + public default @Nullable Float getFloatOrNull(int index) { + var value = getValueOrNull(index); + return getConvertUtil().toFloat(value); + } + + // double + + /** + * get value as double. + * + * @param index column index + * @return value + * @throws NullPointerException if value is null + */ + public default double getDouble(int index) { + var value = getDoubleOrNull(index); + return Objects.requireNonNull(value, () -> "getDouble(" + index + ") is null"); + } + + /** + * get value as double. + * + * @param index column index + * @param defaultValue value to return if original value is null + * @return value + */ + public default double getDouble(int index, double defaultValue) { + var value = getDoubleOrNull(index); + return (value != null) ? value : defaultValue; + } + + /** + * get value as double. + * + * @param index column index + * @return value + */ + public default @Nonnull Optional findDouble(int index) { + var value = getDoubleOrNull(index); + return Optional.ofNullable(value); + } + + /** + * get value as double. + * + * @param index column index + * @return value + */ + public default @Nullable Double getDoubleOrNull(int index) { + var value = getValueOrNull(index); + return getConvertUtil().toDouble(value); + } + + // decimal + + /** + * get value as decimal. + * + * @param index column index + * @return value + * @throws NullPointerException if value is null + */ + public default @Nonnull BigDecimal getDecimal(int index) { + var value = getDecimalOrNull(index); + return Objects.requireNonNull(value, () -> "getDecimal(" + index + ") is null"); + } + + /** + * get value as decimal. + * + * @param index column index + * @param defaultValue value to return if original value is null + * @return value + */ + public default BigDecimal getDecimal(int index, BigDecimal defaultValue) { + var value = getDecimalOrNull(index); + return (value != null) ? value : defaultValue; + } + + /** + * get value as decimal. + * + * @param index column index + * @return value + */ + public default @Nonnull Optional findDecimal(int index) { + var value = getDecimalOrNull(index); + return Optional.ofNullable(value); + } + + /** + * get value as decimal. + * + * @param index column index + * @return value + */ + public default @Nullable BigDecimal getDecimalOrNull(int index) { + var value = getValueOrNull(index); + return getConvertUtil().toDecimal(value); + } + + // string + + /** + * get value as string. + * + * @param index column index + * @return value + * @throws NullPointerException if value is null + */ + public default @Nonnull String getString(int index) { + var value = getStringOrNull(index); + return Objects.requireNonNull(value, () -> "getString(" + index + ") is null"); + } + + /** + * get value as string. + * + * @param index column index + * @param defaultValue value to return if original value is null + * @return value + */ + public default String getString(int index, String defaultValue) { + var value = getStringOrNull(index); + return (value != null) ? value : defaultValue; + } + + /** + * get value as string. + * + * @param index column index + * @return value + */ + public default @Nonnull Optional findString(int index) { + var value = getStringOrNull(index); + return Optional.ofNullable(value); + } + + /** + * get value as string. + * + * @param index column index + * @return value + */ + public default @Nullable String getStringOrNull(int index) { + var value = getValueOrNull(index); + return getConvertUtil().toString(value); + } + + // byte[] + + /** + * get value as byte[]. + * + * @param index column index + * @return value + * @throws NullPointerException if value is null + */ + public default @Nonnull byte[] getBytes(int index) { + var value = getBytesOrNull(index); + return Objects.requireNonNull(value, () -> "getBytes(" + index + ") is null"); + } + + /** + * get value as byte[]. + * + * @param index column index + * @param defaultValue value to return if original value is null + * @return value + */ + public default byte[] getBytes(int index, byte[] defaultValue) { + var value = getBytesOrNull(index); + return (value != null) ? value : defaultValue; + } + + /** + * get value as byte[]. + * + * @param index column index + * @return value + */ + public default @Nonnull Optional findBytes(int index) { + var value = getBytesOrNull(index); + return Optional.ofNullable(value); + } + + /** + * get value as byte[]. + * + * @param index column index + * @return value + */ + public default @Nullable byte[] getBytesOrNull(int index) { + var value = getValueOrNull(index); + return getConvertUtil().toBytes(value); + } + + // boolean[] + + /** + * get value as boolean[]. + * + * @param index column index + * @return value + * @throws NullPointerException if value is null + */ + public default @Nonnull boolean[] getBits(int index) { + var value = getBitsOrNull(index); + return Objects.requireNonNull(value, () -> "getBits(" + index + ") is null"); + } + + /** + * get value as boolean[]. + * + * @param index column index + * @param defaultValue value to return if original value is null + * @return value + */ + public default boolean[] getBits(int index, boolean[] defaultValue) { + var value = getBitsOrNull(index); + return (value != null) ? value : defaultValue; + } + + /** + * get value as boolean[]. + * + * @param index column index + * @return value + */ + public default @Nonnull Optional findBits(int index) { + var value = getBitsOrNull(index); + return Optional.ofNullable(value); + } + + /** + * get value as boolean[]. + * + * @param index column index + * @return value + */ + public default @Nullable boolean[] getBitsOrNull(int index) { + var value = getValueOrNull(index); + return getConvertUtil().toBits(value); + } + + // date + + /** + * get value as date. + * + * @param index column index + * @return value + * @throws NullPointerException if value is null + */ + public default @Nonnull LocalDate getDate(int index) { + var value = getDateOrNull(index); + return Objects.requireNonNull(value, () -> "getDate(" + index + ") is null"); + } + + /** + * get value as date. + * + * @param index column index + * @param defaultValue value to return if original value is null + * @return value + */ + public default LocalDate getDate(int index, LocalDate defaultValue) { + var value = getDateOrNull(index); + return (value != null) ? value : defaultValue; + } + + /** + * get value as date. + * + * @param index column index + * @return value + */ + public default @Nonnull Optional findDate(int index) { + var value = getDateOrNull(index); + return Optional.ofNullable(value); + } + + /** + * get value as date. + * + * @param index column index + * @return value + */ + public default @Nullable LocalDate getDateOrNull(int index) { + var value = getValueOrNull(index); + return getConvertUtil().toDate(value); + } + + // time + + /** + * get value as time. + * + * @param index column index + * @return value + * @throws NullPointerException if value is null + */ + public default @Nonnull LocalTime getTime(int index) { + var value = getTimeOrNull(index); + return Objects.requireNonNull(value, () -> "getTime(" + index + ") is null"); + } + + /** + * get value as time. + * + * @param index column index + * @param defaultValue value to return if original value is null + * @return value + */ + public default LocalTime getTime(int index, LocalTime defaultValue) { + var value = getTimeOrNull(index); + return (value != null) ? value : defaultValue; + } + + /** + * get value as time. + * + * @param index column index + * @return value + */ + public default @Nonnull Optional findTime(int index) { + var value = getTimeOrNull(index); + return Optional.ofNullable(value); + } + + /** + * get value as time. + * + * @param index column index + * @return value + */ + public default @Nullable LocalTime getTimeOrNull(int index) { + var value = getValueOrNull(index); + return getConvertUtil().toTime(value); + } + + // dateTime + + /** + * get value as dateTime. + * + * @param index column index + * @return value + * @throws NullPointerException if value is null + */ + public default @Nonnull LocalDateTime getDateTime(int index) { + var value = getDateTimeOrNull(index); + return Objects.requireNonNull(value, () -> "getDateTime(" + index + ") is null"); + } + + /** + * get value as dateTime. + * + * @param index column index + * @param defaultValue value to return if original value is null + * @return value + */ + public default LocalDateTime getDateTime(int index, LocalDateTime defaultValue) { + var value = getDateTimeOrNull(index); + return (value != null) ? value : defaultValue; + } + + /** + * get value as dateTime. + * + * @param index column index + * @return value + */ + public default @Nonnull Optional findDateTime(int index) { + var value = getDateTimeOrNull(index); + return Optional.ofNullable(value); + } + + /** + * get value as dateTime. + * + * @param index column index + * @return value + */ + public default @Nullable LocalDateTime getDateTimeOrNull(int index) { + var value = getValueOrNull(index); + return getConvertUtil().toDateTime(value); + } + + // offset time + + /** + * get value as offset time. + * + * @param index column index + * @return value + * @throws NullPointerException if value is null + */ + public default @Nonnull OffsetTime getOffsetTime(int index) { + var value = getOffsetTimeOrNull(index); + return Objects.requireNonNull(value, () -> "getOffsetTime(" + index + ") is null"); + } + + /** + * get value as offset time. + * + * @param index column index + * @param defaultValue value to return if original value is null + * @return value + */ + public default OffsetTime getOffsetTime(int index, OffsetTime defaultValue) { + var value = getOffsetTimeOrNull(index); + return (value != null) ? value : defaultValue; + } + + /** + * get value as offset time. + * + * @param index column index + * @return value + */ + public default @Nonnull Optional findOffsetTime(int index) { + var value = getOffsetTimeOrNull(index); + return Optional.ofNullable(value); + } + + /** + * get value as offset time. + * + * @param index column index + * @return value + */ + public default @Nullable OffsetTime getOffsetTimeOrNull(int index) { + var value = getValueOrNull(index); + return getConvertUtil().toOffsetTime(value); + } + + // offset dateTime + + /** + * get value as offset dateTime. + * + * @param index column index + * @return value + * @throws NullPointerException if value is null + */ + public default @Nonnull OffsetDateTime getOffsetDateTime(int index) { + var value = getOffsetDateTimeOrNull(index); + return Objects.requireNonNull(value, () -> "getOffsetDateTime(" + index + ") is null"); + } + + /** + * get value as offset dateTime. + * + * @param index column index + * @param defaultValue value to return if original value is null + * @return value + */ + public default OffsetDateTime getOffsetDateTime(int index, OffsetDateTime defaultValue) { + var value = getOffsetDateTimeOrNull(index); + return (value != null) ? value : defaultValue; + } + + /** + * get value as offset dateTime. + * + * @param index column index + * @return value + */ + public default @Nonnull Optional findOffsetDateTime(int index) { + var value = getOffsetDateTimeOrNull(index); + return Optional.ofNullable(value); + } + + /** + * get value as offset dateTime. + * + * @param index column index + * @return value + */ + public default @Nullable OffsetDateTime getOffsetDateTimeOrNull(int index) { + var value = getValueOrNull(index); + return getConvertUtil().toOffsetDateTime(value); + } + + // zoned dateTime + + /** + * get value as zoned dateTime. + * + * @param index column index + * @param zone time-zone + * @return value + * @throws NullPointerException if value is null + */ + public default @Nonnull ZonedDateTime getZonedDateTime(int index, @Nonnull ZoneId zone) { + var value = getZonedDateTimeOrNull(index, zone); + return Objects.requireNonNull(value, () -> "getZonedDateTime(" + index + ") is null"); + } + + /** + * get value as zoned dateTime. + * + * @param index column index + * @param zone time-zone + * @param defaultValue value to return if original value is null + * @return value + */ + public default ZonedDateTime getZonedDateTime(int index, @Nonnull ZoneId zone, ZonedDateTime defaultValue) { + var value = getZonedDateTimeOrNull(index, zone); + return (value != null) ? value : defaultValue; + } + + /** + * get value as zoned dateTime. + * + * @param index column index + * @param zone time-zone + * @return value + */ + public default @Nonnull Optional findZonedDateTime(int index, @Nonnull ZoneId zone) { + var value = getZonedDateTimeOrNull(index, zone); + return Optional.ofNullable(value); + } + + /** + * get value as zoned dateTime. + * + * @param index column index + * @param zone time-zone + * @return value + */ + public default @Nullable ZonedDateTime getZonedDateTimeOrNull(int index, @Nonnull ZoneId zone) { + var value = getValueOrNull(index); + return getConvertUtil().toZonedDateTime(value, zone); + } +} diff --git a/modules/iceaxe-core/src/main/java/com/tsurugidb/iceaxe/result/TsurugiResultNameEntity.java b/modules/iceaxe-core/src/main/java/com/tsurugidb/iceaxe/result/TsurugiResultNameEntity.java new file mode 100755 index 00000000..26418039 --- /dev/null +++ b/modules/iceaxe-core/src/main/java/com/tsurugidb/iceaxe/result/TsurugiResultNameEntity.java @@ -0,0 +1,764 @@ +package com.tsurugidb.iceaxe.result; + +import java.math.BigDecimal; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.time.OffsetDateTime; +import java.time.OffsetTime; +import java.time.ZoneId; +import java.time.ZonedDateTime; +import java.util.Objects; +import java.util.Optional; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +import com.tsurugidb.iceaxe.util.IceaxeConvertUtil; + +/** + * Tsurugi Result Entity for name access. + * + * @since 1.5.0 + */ +public interface TsurugiResultNameEntity { + + /** + * get value. + * + * @param name column name + * @return value + */ + public @Nullable Object getValueOrNull(String name); + + /** + * get convert utility. + * + * @return convert utility + */ + public IceaxeConvertUtil getConvertUtil(); + + // boolean + + /** + * get value as boolean. + * + * @param name column name + * @return value + * @throws NullPointerException if value is null + */ + public default boolean getBoolean(String name) { + var value = getBooleanOrNull(name); + return Objects.requireNonNull(value, () -> "getBoolean(" + name + ") is null"); + } + + /** + * get value as boolean. + * + * @param name column name + * @param defaultValue value to return if original value is null + * @return value + */ + public default boolean getBoolean(String name, boolean defaultValue) { + var value = getBooleanOrNull(name); + return (value != null) ? value : defaultValue; + } + + /** + * get value as boolean. + * + * @param name column name + * @return value + */ + public default @Nonnull Optional findBoolean(String name) { + var value = getBooleanOrNull(name); + return Optional.ofNullable(value); + } + + /** + * get value as boolean. + * + * @param name column name + * @return value + */ + public default @Nullable Boolean getBooleanOrNull(String name) { + var value = getValueOrNull(name); + return getConvertUtil().toBoolean(value); + } + + // int + + /** + * get value as int. + * + * @param name column name + * @return value + * @throws NullPointerException if value is null + */ + public default int getInt(String name) { + var value = getIntOrNull(name); + return Objects.requireNonNull(value, () -> "getInt(" + name + ") is null"); + } + + /** + * get value as int. + * + * @param name column name + * @param defaultValue value to return if original value is null + * @return value + */ + public default int getInt(String name, int defaultValue) { + var value = getIntOrNull(name); + return (value != null) ? value : defaultValue; + } + + /** + * get value as int. + * + * @param name column name + * @return value + */ + public default @Nonnull Optional findInt(String name) { + var value = getIntOrNull(name); + return Optional.ofNullable(value); + } + + /** + * get value as int. + * + * @param name column name + * @return value + */ + public default @Nullable Integer getIntOrNull(String name) { + var value = getValueOrNull(name); + return getConvertUtil().toInt(value); + } + + // long + + /** + * get value as long. + * + * @param name column name + * @return value + * @throws NullPointerException if value is null + */ + public default long getLong(String name) { + var value = getLongOrNull(name); + return Objects.requireNonNull(value, () -> "getLong(" + name + ") is null"); + } + + /** + * get value as long. + * + * @param name column name + * @param defaultValue value to return if original value is null + * @return value + */ + public default long getLong(String name, long defaultValue) { + var value = getLongOrNull(name); + return (value != null) ? value : defaultValue; + } + + /** + * get value as long. + * + * @param name column name + * @return value + */ + public default @Nonnull Optional findLong(String name) { + var value = getLongOrNull(name); + return Optional.ofNullable(value); + } + + /** + * get value as long. + * + * @param name column name + * @return value + */ + public default @Nullable Long getLongOrNull(String name) { + var value = getValueOrNull(name); + return getConvertUtil().toLong(value); + } + + // float + + /** + * get value as float. + * + * @param name column name + * @return value + * @throws NullPointerException if value is null + */ + public default float getFloat(String name) { + var value = getFloatOrNull(name); + return Objects.requireNonNull(value, () -> "getFloat(" + name + ") is null"); + } + + /** + * get value as float. + * + * @param name column name + * @param defaultValue value to return if original value is null + * @return value + */ + public default float getFloat(String name, float defaultValue) { + var value = getFloatOrNull(name); + return (value != null) ? value : defaultValue; + } + + /** + * get value as float. + * + * @param name column name + * @return value + */ + public default @Nonnull Optional findFloat(String name) { + var value = getFloatOrNull(name); + return Optional.ofNullable(value); + } + + /** + * get value as float. + * + * @param name column name + * @return value + */ + public default @Nullable Float getFloatOrNull(String name) { + var value = getValueOrNull(name); + return getConvertUtil().toFloat(value); + } + + // double + + /** + * get value as double. + * + * @param name column name + * @return value + * @throws NullPointerException if value is null + */ + public default double getDouble(String name) { + var value = getDoubleOrNull(name); + return Objects.requireNonNull(value, () -> "getDouble(" + name + ") is null"); + } + + /** + * get value as double. + * + * @param name column name + * @param defaultValue value to return if original value is null + * @return value + */ + public default double getDouble(String name, double defaultValue) { + var value = getDoubleOrNull(name); + return (value != null) ? value : defaultValue; + } + + /** + * get value as double. + * + * @param name column name + * @return value + */ + public default @Nonnull Optional findDouble(String name) { + var value = getDoubleOrNull(name); + return Optional.ofNullable(value); + } + + /** + * get value as double. + * + * @param name column name + * @return value + */ + public default @Nullable Double getDoubleOrNull(String name) { + var value = getValueOrNull(name); + return getConvertUtil().toDouble(value); + } + + // decimal + + /** + * get value as decimal. + * + * @param name column name + * @return value + * @throws NullPointerException if value is null + */ + public default @Nonnull BigDecimal getDecimal(String name) { + var value = getDecimalOrNull(name); + return Objects.requireNonNull(value, () -> "getDecimal(" + name + ") is null"); + } + + /** + * get value as decimal. + * + * @param name column name + * @param defaultValue value to return if original value is null + * @return value + */ + public default BigDecimal getDecimal(String name, BigDecimal defaultValue) { + var value = getDecimalOrNull(name); + return (value != null) ? value : defaultValue; + } + + /** + * get value as decimal. + * + * @param name column name + * @return value + */ + public default @Nonnull Optional findDecimal(String name) { + var value = getDecimalOrNull(name); + return Optional.ofNullable(value); + } + + /** + * get value as decimal. + * + * @param name column name + * @return value + */ + public default @Nullable BigDecimal getDecimalOrNull(String name) { + var value = getValueOrNull(name); + return getConvertUtil().toDecimal(value); + } + + // string + + /** + * get value as string. + * + * @param name column name + * @return value + * @throws NullPointerException if value is null + */ + public default @Nonnull String getString(String name) { + var value = getStringOrNull(name); + return Objects.requireNonNull(value, () -> "getString(" + name + ") is null"); + } + + /** + * get value as string. + * + * @param name column name + * @param defaultValue value to return if original value is null + * @return value + */ + public default String getString(String name, String defaultValue) { + var value = getStringOrNull(name); + return (value != null) ? value : defaultValue; + } + + /** + * get value as string. + * + * @param name column name + * @return value + */ + public default @Nonnull Optional findString(String name) { + var value = getStringOrNull(name); + return Optional.ofNullable(value); + } + + /** + * get value as string. + * + * @param name column name + * @return value + */ + public default @Nullable String getStringOrNull(String name) { + var value = getValueOrNull(name); + return getConvertUtil().toString(value); + } + + // byte[] + + /** + * get value as byte[]. + * + * @param name column name + * @return value + * @throws NullPointerException if value is null + */ + public default @Nonnull byte[] getBytes(String name) { + var value = getBytesOrNull(name); + return Objects.requireNonNull(value, () -> "getBytes(" + name + ") is null"); + } + + /** + * get value as byte[]. + * + * @param name column name + * @param defaultValue value to return if original value is null + * @return value + */ + public default byte[] getBytes(String name, byte[] defaultValue) { + var value = getBytesOrNull(name); + return (value != null) ? value : defaultValue; + } + + /** + * get value as byte[]. + * + * @param name column name + * @return value + */ + public default @Nonnull Optional findBytes(String name) { + var value = getBytesOrNull(name); + return Optional.ofNullable(value); + } + + /** + * get value as byte[]. + * + * @param name column name + * @return value + */ + public default @Nullable byte[] getBytesOrNull(String name) { + var value = getValueOrNull(name); + return getConvertUtil().toBytes(value); + } + + // boolean[] + + /** + * get value as boolean[]. + * + * @param name column name + * @return value + * @throws NullPointerException if value is null + */ + public default @Nonnull boolean[] getBits(String name) { + var value = getBitsOrNull(name); + return Objects.requireNonNull(value, () -> "getBits(" + name + ") is null"); + } + + /** + * get value as boolean[]. + * + * @param name column name + * @param defaultValue value to return if original value is null + * @return value + */ + public default boolean[] getBits(String name, boolean[] defaultValue) { + var value = getBitsOrNull(name); + return (value != null) ? value : defaultValue; + } + + /** + * get value as boolean[]. + * + * @param name column name + * @return value + */ + public default @Nonnull Optional findBits(String name) { + var value = getBitsOrNull(name); + return Optional.ofNullable(value); + } + + /** + * get value as boolean[]. + * + * @param name column name + * @return value + */ + public default @Nullable boolean[] getBitsOrNull(String name) { + var value = getValueOrNull(name); + return getConvertUtil().toBits(value); + } + + // date + + /** + * get value as date. + * + * @param name column name + * @return value + * @throws NullPointerException if value is null + */ + public default @Nonnull LocalDate getDate(String name) { + var value = getDateOrNull(name); + return Objects.requireNonNull(value, () -> "getDate(" + name + ") is null"); + } + + /** + * get value as date. + * + * @param name column name + * @param defaultValue value to return if original value is null + * @return value + */ + public default LocalDate getDate(String name, LocalDate defaultValue) { + var value = getDateOrNull(name); + return (value != null) ? value : defaultValue; + } + + /** + * get value as date. + * + * @param name column name + * @return value + */ + public default @Nonnull Optional findDate(String name) { + var value = getDateOrNull(name); + return Optional.ofNullable(value); + } + + /** + * get value as date. + * + * @param name column name + * @return value + */ + public default @Nullable LocalDate getDateOrNull(String name) { + var value = getValueOrNull(name); + return getConvertUtil().toDate(value); + } + + // time + + /** + * get value as time. + * + * @param name column name + * @return value + * @throws NullPointerException if value is null + */ + public default @Nonnull LocalTime getTime(String name) { + var value = getTimeOrNull(name); + return Objects.requireNonNull(value, () -> "getTime(" + name + ") is null"); + } + + /** + * get value as time. + * + * @param name column name + * @param defaultValue value to return if original value is null + * @return value + */ + public default LocalTime getTime(String name, LocalTime defaultValue) { + var value = getTimeOrNull(name); + return (value != null) ? value : defaultValue; + } + + /** + * get value as time. + * + * @param name column name + * @return value + */ + public default @Nonnull Optional findTime(String name) { + var value = getTimeOrNull(name); + return Optional.ofNullable(value); + } + + /** + * get value as time. + * + * @param name column name + * @return value + */ + public default @Nullable LocalTime getTimeOrNull(String name) { + var value = getValueOrNull(name); + return getConvertUtil().toTime(value); + } + + // dateTime + + /** + * get value as dateTime. + * + * @param name column name + * @return value + * @throws NullPointerException if value is null + */ + public default @Nonnull LocalDateTime getDateTime(String name) { + var value = getDateTimeOrNull(name); + return Objects.requireNonNull(value, () -> "getDateTime(" + name + ") is null"); + } + + /** + * get value as dateTime. + * + * @param name column name + * @param defaultValue value to return if original value is null + * @return value + */ + public default LocalDateTime getDateTime(String name, LocalDateTime defaultValue) { + var value = getDateTimeOrNull(name); + return (value != null) ? value : defaultValue; + } + + /** + * get value as dateTime. + * + * @param name column name + * @return value + */ + public default @Nonnull Optional findDateTime(String name) { + var value = getDateTimeOrNull(name); + return Optional.ofNullable(value); + } + + /** + * get value as dateTime. + * + * @param name column name + * @return value + */ + public default @Nullable LocalDateTime getDateTimeOrNull(String name) { + var value = getValueOrNull(name); + return getConvertUtil().toDateTime(value); + } + + // offset time + + /** + * get value as offset time. + * + * @param name column name + * @return value + * @throws NullPointerException if value is null + */ + public default @Nonnull OffsetTime getOffsetTime(String name) { + var value = getOffsetTimeOrNull(name); + return Objects.requireNonNull(value, () -> "getOffsetTime(" + name + ") is null"); + } + + /** + * get value as offset time. + * + * @param name column name + * @param defaultValue value to return if original value is null + * @return value + */ + public default OffsetTime getOffsetTime(String name, OffsetTime defaultValue) { + var value = getOffsetTimeOrNull(name); + return (value != null) ? value : defaultValue; + } + + /** + * get value as offset time. + * + * @param name column name + * @return value + */ + public default @Nonnull Optional findOffsetTime(String name) { + var value = getOffsetTimeOrNull(name); + return Optional.ofNullable(value); + } + + /** + * get value as offset time. + * + * @param name column name + * @return value + */ + public default @Nullable OffsetTime getOffsetTimeOrNull(String name) { + var value = getValueOrNull(name); + return getConvertUtil().toOffsetTime(value); + } + + // offset dateTime + + /** + * get value as offset dateTime. + * + * @param name column name + * @return value + * @throws NullPointerException if value is null + */ + public default @Nonnull OffsetDateTime getOffsetDateTime(String name) { + var value = getOffsetDateTimeOrNull(name); + return Objects.requireNonNull(value, () -> "getOffsetDateTime(" + name + ") is null"); + } + + /** + * get value as offset dateTime. + * + * @param name column name + * @param defaultValue value to return if original value is null + * @return value + */ + public default OffsetDateTime getOffsetDateTime(String name, OffsetDateTime defaultValue) { + var value = getOffsetDateTimeOrNull(name); + return (value != null) ? value : defaultValue; + } + + /** + * get value as offset dateTime. + * + * @param name column name + * @return value + */ + public default @Nonnull Optional findOffsetDateTime(String name) { + var value = getOffsetDateTimeOrNull(name); + return Optional.ofNullable(value); + } + + /** + * get value as offset dateTime. + * + * @param name column name + * @return value + */ + public default @Nullable OffsetDateTime getOffsetDateTimeOrNull(String name) { + var value = getValueOrNull(name); + return getConvertUtil().toOffsetDateTime(value); + } + + // zoned dateTime + + /** + * get value as zoned dateTime. + * + * @param name column name + * @param zone time-zone + * @return value + * @throws NullPointerException if value is null + */ + public default @Nonnull ZonedDateTime getZonedDateTime(String name, @Nonnull ZoneId zone) { + var value = getZonedDateTimeOrNull(name, zone); + return Objects.requireNonNull(value, () -> "getZonedDateTime(" + name + ") is null"); + } + + /** + * get value as zoned dateTime. + * + * @param name column name + * @param zone time-zone + * @param defaultValue value to return if original value is null + * @return value + */ + public default ZonedDateTime getZonedDateTime(String name, @Nonnull ZoneId zone, ZonedDateTime defaultValue) { + var value = getZonedDateTimeOrNull(name, zone); + return (value != null) ? value : defaultValue; + } + + /** + * get value as zoned dateTime. + * + * @param name column name + * @param zone time-zone + * @return value + */ + public default @Nonnull Optional findZonedDateTime(String name, @Nonnull ZoneId zone) { + var value = getZonedDateTimeOrNull(name, zone); + return Optional.ofNullable(value); + } + + /** + * get value as zoned dateTime. + * + * @param name column name + * @param zone time-zone + * @return value + */ + public default @Nullable ZonedDateTime getZonedDateTimeOrNull(String name, @Nonnull ZoneId zone) { + var value = getValueOrNull(name); + return getConvertUtil().toZonedDateTime(value, zone); + } +} diff --git a/modules/iceaxe-core/src/main/java/com/tsurugidb/iceaxe/result/package-info.java b/modules/iceaxe-core/src/main/java/com/tsurugidb/iceaxe/result/package-info.java new file mode 100755 index 00000000..3e5730fb --- /dev/null +++ b/modules/iceaxe-core/src/main/java/com/tsurugidb/iceaxe/result/package-info.java @@ -0,0 +1,4 @@ +/** + * Iceaxe result classes. + */ +package com.tsurugidb.iceaxe.result; \ No newline at end of file diff --git a/modules/iceaxe-core/src/main/java/com/tsurugidb/iceaxe/sql/result/IceaxeResultNameList.java b/modules/iceaxe-core/src/main/java/com/tsurugidb/iceaxe/sql/result/IceaxeResultNameList.java new file mode 100755 index 00000000..677e302a --- /dev/null +++ b/modules/iceaxe-core/src/main/java/com/tsurugidb/iceaxe/sql/result/IceaxeResultNameList.java @@ -0,0 +1,191 @@ +package com.tsurugidb.iceaxe.sql.result; + +import java.text.MessageFormat; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.annotation.concurrent.ThreadSafe; + +import com.tsurugidb.iceaxe.util.IceaxeInternal; +import com.tsurugidb.sql.proto.SqlCommon.Column; + +/** + * name utility. + * + * @since 1.5.0 + */ +@IceaxeInternal +@ThreadSafe +public class IceaxeResultNameList { + + /** + * ambiguous name policy. + * + * @since 1.5.0 + */ + public enum IceaxeAmbiguousNamePolicy { + /** error. */ + ERROR, + /** get first column. */ + FIRST, + /** get last column. */ + LAST, + } + + /** + * create name utility. + * + * @param lowColumnList low column list + * @return name utility + */ + public static IceaxeResultNameList of(List lowColumnList) { + var nameList = toNameList(lowColumnList); + return new IceaxeResultNameList(nameList); + } + + /** + * convert to name list. + * + * @param lowColumnList low column list + * @return name list + */ + public static List toNameList(List lowColumnList) { + var nameList = new ArrayList(lowColumnList.size()); + int i = 0; + for (var lowColumn : lowColumnList) { + var name = getColumnName(lowColumn, i++); + nameList.add(name); + } + return nameList; + } + + private static String getColumnName(Column lowColumn, int index) { + var lowName = lowColumn.getName(); + if (lowName == null || lowName.isEmpty()) { + return "@#" + index; + } + return lowName; + } + + private final List nameList; + + private Map> nameIndexMap = null; + + /** + * Creates a new instance. + * + * @param nameList name list + */ + public IceaxeResultNameList(List nameList) { + this.nameList = List.copyOf(nameList); + } + + /** + * get name list. + * + * @return name list + */ + public List getNameList() { + return this.nameList; + } + + /** + * get size. + * + * @return size of name list + */ + public int size() { + return nameList.size(); + } + + /** + * get name. + * + * @param index column index + * @return column name + */ + public String getName(int index) { + return nameList.get(index); + } + + /** + * get index. + * + * @param name column name + * @param policy ambiguous name policy + * @return column index + */ + public int getIndex(String name, IceaxeAmbiguousNamePolicy policy) { + var indexMap = getNameIndexMap(); + List indexList = indexMap.get(name); + if (indexList == null) { + throw new IllegalArgumentException(MessageFormat.format("not found column. name={0}", name)); + } + + if (indexList.size() == 1) { + return indexList.get(0); + } + + switch (policy) { + case ERROR: + throw new IllegalArgumentException(MessageFormat.format("column is ambiguous. name={0}", name)); + case FIRST: + return indexList.get(0); // getHead() + case LAST: + return indexList.get(indexList.size() - 1); // getLast() + default: + throw new UnsupportedOperationException(MessageFormat.format("unsupported policy. policy={0}", policy)); + } + } + + /** + * get index. + * + * @param name column name + * @param subIndex index for same name + * @return column index + */ + public int getIndex(String name, int subIndex) { + var indexMap = getNameIndexMap(); + List indexList = indexMap.get(name); + if (indexList == null) { + throw new IllegalArgumentException(MessageFormat.format("not found column. name={0}", name)); + } + + if (0 <= subIndex && subIndex < indexList.size()) { + return indexList.get(subIndex); + } + + throw new IllegalArgumentException(MessageFormat.format("not found column. name={0}, subIndex={1}", name, subIndex)); + } + + /** + * get name-index map. + * + * @return name-index map + */ + protected Map> getNameIndexMap() { + if (this.nameIndexMap == null) { + var map = new HashMap>(nameList.size()); + for (int i = 0; i < nameList.size(); i++) { + String name = nameList.get(i); + List indexList = map.computeIfAbsent(name, k -> new ArrayList<>(2)); + indexList.add(i); + } + this.nameIndexMap = map; + } + return this.nameIndexMap; + } + + @Override + public String toString() { + var map = this.nameIndexMap; + if (map != null) { + return getClass().getSimpleName() + map; + } + + return getClass().getSimpleName() + nameList; + } +} diff --git a/modules/iceaxe-core/src/main/java/com/tsurugidb/iceaxe/sql/result/TsurugiQueryResult.java b/modules/iceaxe-core/src/main/java/com/tsurugidb/iceaxe/sql/result/TsurugiQueryResult.java index e69b9eed..6521514f 100755 --- a/modules/iceaxe-core/src/main/java/com/tsurugidb/iceaxe/sql/result/TsurugiQueryResult.java +++ b/modules/iceaxe-core/src/main/java/com/tsurugidb/iceaxe/sql/result/TsurugiQueryResult.java @@ -359,25 +359,14 @@ public int getReadCount() { */ public List getNameList() throws IOException, InterruptedException, TsurugiTransactionException { try { - return getNameList(this, getLowResultSet()); + var lowColumnList = getLowColumnList(this, getLowResultSet()); + return IceaxeResultNameList.toNameList(lowColumnList); } catch (Throwable e) { event(e, listener -> listener.readException(this, e)); throw e; } } - static List getNameList(TsurugiQueryResult rs, ResultSet lowResultSet) throws IOException, InterruptedException, TsurugiTransactionException { - var lowColumnList = getLowColumnList(rs, lowResultSet); - var size = lowColumnList.size(); - var list = new ArrayList(size); - int i = 0; - for (var lowColumn : lowColumnList) { - var name = getColumnName(lowColumn, i++); - list.add(name); - } - return list; - } - static List getLowColumnList(TsurugiQueryResult rs, ResultSet lowResultSet) throws IOException, InterruptedException, TsurugiTransactionException { try { var lowMetadata = lowResultSet.getMetadata(); @@ -387,14 +376,6 @@ static List getLowColumnList(TsurugiQueryResult rs, ResultS } } - static String getColumnName(Column lowColumn, int index) { - var lowName = lowColumn.getName(); - if (lowName == null || lowName.isEmpty()) { - return "@#" + index; - } - return lowName; - } - // read /** diff --git a/modules/iceaxe-core/src/main/java/com/tsurugidb/iceaxe/sql/result/TsurugiResultEntity.java b/modules/iceaxe-core/src/main/java/com/tsurugidb/iceaxe/sql/result/TsurugiResultEntity.java index b816b61c..d483fcf6 100755 --- a/modules/iceaxe-core/src/main/java/com/tsurugidb/iceaxe/sql/result/TsurugiResultEntity.java +++ b/modules/iceaxe-core/src/main/java/com/tsurugidb/iceaxe/sql/result/TsurugiResultEntity.java @@ -1,32 +1,47 @@ package com.tsurugidb.iceaxe.sql.result; import java.io.IOException; -import java.math.BigDecimal; -import java.time.LocalDate; -import java.time.LocalDateTime; -import java.time.LocalTime; -import java.time.OffsetDateTime; -import java.time.OffsetTime; -import java.time.ZoneId; -import java.time.ZonedDateTime; -import java.util.LinkedHashMap; import java.util.List; -import java.util.Map; import java.util.Objects; -import java.util.Optional; import javax.annotation.Nonnull; import javax.annotation.Nullable; import javax.annotation.concurrent.ThreadSafe; +import com.tsurugidb.iceaxe.result.TsurugiResultIndexEntity; +import com.tsurugidb.iceaxe.result.TsurugiResultNameEntity; +import com.tsurugidb.iceaxe.sql.result.IceaxeResultNameList.IceaxeAmbiguousNamePolicy; import com.tsurugidb.iceaxe.transaction.exception.TsurugiTransactionException; import com.tsurugidb.iceaxe.util.IceaxeConvertUtil; +import com.tsurugidb.iceaxe.util.IceaxeInternal; /** - * Tsurugi Result Record. + * Tsurugi Result Entity. */ @ThreadSafe -public class TsurugiResultEntity { +public class TsurugiResultEntity implements TsurugiResultIndexEntity, TsurugiResultNameEntity { + + private static IceaxeAmbiguousNamePolicy defaultAmbiguousNamePolicy = IceaxeAmbiguousNamePolicy.FIRST; + + /** + * set default ambiguous name policy. + * + * @param policy default ambiguous name policy + * @since X.X.X + */ + public static void setDefaultAmbiguousNamePolicy(IceaxeAmbiguousNamePolicy policy) { + defaultAmbiguousNamePolicy = Objects.requireNonNull(policy); + } + + /** + * get default ambiguous name policy. + * + * @return default ambiguous name policy + * @since X.X.X + */ + public static IceaxeAmbiguousNamePolicy getDefaultAmbiguousNamePolicy() { + return defaultAmbiguousNamePolicy; + } /** * create entity. @@ -38,20 +53,33 @@ public class TsurugiResultEntity { * @throws TsurugiTransactionException if server error occurs while retrieving the column data */ public static TsurugiResultEntity of(TsurugiResultRecord record) throws IOException, InterruptedException, TsurugiTransactionException { - var entity = new TsurugiResultEntity(); + IceaxeResultNameList nameList = record.getResultNameList(); + + var values = new Object[nameList.size()]; + record.readValues(values); + + var entity = new TsurugiResultEntity(nameList, values); entity.setConvertUtil(record.getConvertUtil()); - while (record.moveCurrentColumnNext()) { - var name = record.getCurrentColumnName(); - var value = record.fetchCurrentColumnValue(); - entity.add(name, value); - } return entity; } + private final IceaxeResultNameList resultNameList; + private final Object[] values; + private IceaxeAmbiguousNamePolicy ambiguousNamePolicy = null; private IceaxeConvertUtil convertUtil = IceaxeConvertUtil.INSTANCE; - /** Map<name, value> */ - private final Map valueMap = new LinkedHashMap<>(); - private List nameList; + + /** + * Creates a new instance. + * + * @param nameList name utility + * @param values column values + * @since X.X.X + */ + @IceaxeInternal + protected TsurugiResultEntity(IceaxeResultNameList nameList, Object[] values) { + this.resultNameList = nameList; + this.values = values; + } /** * set convert type utility. @@ -62,14 +90,9 @@ public void setConvertUtil(IceaxeConvertUtil convertUtil) { this.convertUtil = convertUtil; } - /** - * add value. - * - * @param name column name - * @param value column value - */ - protected void add(String name, Object value) { - valueMap.put(name, value); + @Override + public IceaxeConvertUtil getConvertUtil() { + return this.convertUtil; } /** @@ -78,13 +101,13 @@ protected void add(String name, Object value) { * @return list of column name */ public @Nonnull List getNameList() { - if (this.nameList == null) { - var set = valueMap.keySet(); - this.nameList = List.of(set.toArray(new String[set.size()])); - } - return this.nameList; + return this.resultNameList.getNameList(); } + /* + * get by index + */ + /** * get column name. * @@ -96,808 +119,87 @@ public String getName(int index) { return getNameList().get(index); } - /** - * get column value. - * - * @param name column name - * @return column value - */ - protected @Nullable Object getValue(String name) { - var value = valueMap.get(name); - if (value == null) { - if (!valueMap.containsKey(name)) { - throw new IllegalArgumentException("not found column. name=" + name); - } - } - return value; - } - - // boolean - - /** - * get column value as boolean. - * - * @param name column name - * @return column value - * @throws NullPointerException if value is null - */ - public boolean getBoolean(String name) { - var value = getBooleanOrNull(name); - Objects.requireNonNull(value); - return value; - } - - /** - * get column value as boolean. - * - * @param name column name - * @param defaultValue value to return if column value is null - * @return column value - */ - public boolean getBoolean(String name, boolean defaultValue) { - var value = getBooleanOrNull(name); - if (value == null) { - return defaultValue; - } - return value; - } - - /** - * get column value as boolean. - * - * @param name column name - * @return column value - */ - public @Nonnull Optional findBoolean(String name) { - var value = getBooleanOrNull(name); - return Optional.ofNullable(value); - } - - /** - * get column value as boolean. - * - * @param name column name - * @return column value - */ - public @Nullable Boolean getBooleanOrNull(String name) { - var value = getValue(name); - return convertUtil.toBoolean(value); - } - - // int - - /** - * get column value as int. - * - * @param name column name - * @return column value - * @throws NullPointerException if value is null - */ - public int getInt(String name) { - var value = getIntOrNull(name); - Objects.requireNonNull(value); - return value; - } - - /** - * get column value as int. - * - * @param name column name - * @param defaultValue value to return if column value is null - * @return column value - */ - public int getInt(String name, int defaultValue) { - var value = getIntOrNull(name); - if (value == null) { - return defaultValue; - } - return value; - } - - /** - * get column value as int. - * - * @param name column name - * @return column value - */ - public @Nonnull Optional findInt(String name) { - var value = getIntOrNull(name); - return Optional.ofNullable(value); - } - - /** - * get column value as int. - * - * @param name column name - * @return column value - */ - public @Nullable Integer getIntOrNull(String name) { - var value = getValue(name); - return convertUtil.toInt(value); - } - - // long - - /** - * get column value as long. - * - * @param name column name - * @return column value - * @throws NullPointerException if value is null - */ - public long getLong(String name) { - var value = getLongOrNull(name); - Objects.requireNonNull(value); - return value; - } - - /** - * get column value as long. - * - * @param name column name - * @param defaultValue value to return if column value is null - * @return column value - */ - public long getLong(String name, long defaultValue) { - var value = getLongOrNull(name); - if (value == null) { - return defaultValue; - } - return value; - } - - /** - * get column value as long. - * - * @param name column name - * @return column value - */ - public @Nonnull Optional findLong(String name) { - var value = getLongOrNull(name); - return Optional.ofNullable(value); - } - - /** - * get column value as long. - * - * @param name column name - * @return column value - */ - public @Nullable Long getLongOrNull(String name) { - var value = getValue(name); - return convertUtil.toLong(value); - } - - // float - - /** - * get column value as float. - * - * @param name column name - * @return column value - * @throws NullPointerException if value is null - */ - public float getFloat(String name) { - var value = getFloatOrNull(name); - Objects.requireNonNull(value); - return value; - } - - /** - * get column value as float. - * - * @param name column name - * @param defaultValue value to return if column value is null - * @return column value - */ - public float getFloat(String name, float defaultValue) { - var value = getFloatOrNull(name); - if (value == null) { - return defaultValue; - } - return value; - } - - /** - * get column value as float. - * - * @param name column name - * @return column value - */ - public @Nonnull Optional findFloat(String name) { - var value = getFloatOrNull(name); - return Optional.ofNullable(value); - } - - /** - * get column value as float. - * - * @param name column name - * @return column value - */ - public @Nullable Float getFloatOrNull(String name) { - var value = getValue(name); - return convertUtil.toFloat(value); - } - - // double - - /** - * get column value as double. - * - * @param name column name - * @return column value - * @throws NullPointerException if value is null - */ - public double getDouble(String name) { - var value = getDoubleOrNull(name); - Objects.requireNonNull(value); - return value; - } - - /** - * get column value as double. - * - * @param name column name - * @param defaultValue value to return if column value is null - * @return column value - */ - public double getDouble(String name, double defaultValue) { - var value = getDoubleOrNull(name); - if (value == null) { - return defaultValue; - } - return value; - } - - /** - * get column value as double. - * - * @param name column name - * @return column value - */ - public @Nonnull Optional findDouble(String name) { - var value = getDoubleOrNull(name); - return Optional.ofNullable(value); - } - - /** - * get column value as double. - * - * @param name column name - * @return column value - */ - public @Nullable Double getDoubleOrNull(String name) { - var value = getValue(name); - return convertUtil.toDouble(value); - } - - // decimal - - /** - * get column value as decimal. - * - * @param name column name - * @return column value - * @throws NullPointerException if value is null - */ - public @Nonnull BigDecimal getDecimal(String name) { - var value = getDecimalOrNull(name); - Objects.requireNonNull(value); - return value; - } - - /** - * get column value as decimal. - * - * @param name column name - * @param defaultValue value to return if column value is null - * @return column value - */ - public BigDecimal getDecimal(String name, BigDecimal defaultValue) { - var value = getDecimalOrNull(name); - if (value == null) { - return defaultValue; - } - return value; - } - - /** - * get column value as decimal. - * - * @param name column name - * @return column value - */ - public @Nonnull Optional findDecimal(String name) { - var value = getDecimalOrNull(name); - return Optional.ofNullable(value); - } - - /** - * get column value as decimal. - * - * @param name column name - * @return column value - */ - public @Nullable BigDecimal getDecimalOrNull(String name) { - var value = getValue(name); - return convertUtil.toDecimal(value); - } - - // string - - /** - * get column value as String. - * - * @param name column name - * @return column value - * @throws NullPointerException if value is null - */ - public @Nonnull String getString(String name) { - var value = getStringOrNull(name); - Objects.requireNonNull(value); - return value; - } - - /** - * get column value as String. - * - * @param name column name - * @param defaultValue value to return if column value is null - * @return column value - */ - public String getString(String name, String defaultValue) { - var value = getStringOrNull(name); - if (value == null) { - return defaultValue; - } - return value; - } - - /** - * get column value as String. - * - * @param name column name - * @return column value - */ - public @Nonnull Optional findString(String name) { - var value = getStringOrNull(name); - return Optional.ofNullable(value); - } - - /** - * get column value as String. - * - * @param name column name - * @return column value - */ - public @Nullable String getStringOrNull(String name) { - var value = getValue(name); - return convertUtil.toString(value); - } - - // byte[] - - /** - * get column value as byte[]. - * - * @param name column name - * @return column value - * @throws NullPointerException if value is null - */ - public @Nonnull byte[] getBytes(String name) { - var value = getBytesOrNull(name); - Objects.requireNonNull(value); - return value; - } - - /** - * get column value as byte[]. - * - * @param name column name - * @param defaultValue value to return if column value is null - * @return column value - */ - public byte[] getBytes(String name, byte[] defaultValue) { - var value = getBytesOrNull(name); - if (value == null) { - return defaultValue; - } - return value; - } - - /** - * get column value as byte[]. - * - * @param name column name - * @return column value - */ - public @Nonnull Optional findBytes(String name) { - var value = getBytesOrNull(name); - return Optional.ofNullable(value); - } - - /** - * get column value as byte[]. - * - * @param name column name - * @return column value - */ - public @Nullable byte[] getBytesOrNull(String name) { - var value = getValue(name); - return convertUtil.toBytes(value); - } - - // boolean[] - - /** - * get column value as boolean[]. - * - * @param name column name - * @return column value - * @throws NullPointerException if value is null - */ - public @Nonnull boolean[] getBits(String name) { - var value = getBitsOrNull(name); - Objects.requireNonNull(value); - return value; - } - - /** - * get column value as boolean[]. - * - * @param name column name - * @param defaultValue value to return if column value is null - * @return column value - */ - public boolean[] getBits(String name, boolean[] defaultValue) { - var value = getBitsOrNull(name); - if (value == null) { - return defaultValue; - } - return value; - } - - /** - * get column value as boolean[]. - * - * @param name column name - * @return column value - */ - public @Nonnull Optional findBits(String name) { - var value = getBitsOrNull(name); - return Optional.ofNullable(value); - } - - /** - * get column value as boolean[]. - * - * @param name column name - * @return column value - */ - public @Nullable boolean[] getBitsOrNull(String name) { - var value = getValue(name); - return convertUtil.toBits(value); - } - - // date - - /** - * get column value as date. - * - * @param name column name - * @return column value - * @throws NullPointerException if value is null - */ - public @Nonnull LocalDate getDate(String name) { - var value = getDateOrNull(name); - Objects.requireNonNull(value); - return value; - } - - /** - * get column value as date. - * - * @param name column name - * @param defaultValue value to return if column value is null - * @return column value - */ - public LocalDate getDate(String name, LocalDate defaultValue) { - var value = getDateOrNull(name); - if (value == null) { - return defaultValue; - } - return value; - } - - /** - * get column value as date. - * - * @param name column name - * @return column value - */ - public @Nonnull Optional findDate(String name) { - var value = getDateOrNull(name); - return Optional.ofNullable(value); - } - - /** - * get column value as date. - * - * @param name column name - * @return column value - */ - public @Nullable LocalDate getDateOrNull(String name) { - var value = getValue(name); - return convertUtil.toDate(value); - } - - // time - - /** - * get column value as time. - * - * @param name column name - * @return column value - * @throws NullPointerException if value is null - */ - public @Nonnull LocalTime getTime(String name) { - var value = getTimeOrNull(name); - Objects.requireNonNull(value); - return value; - } - - /** - * get column value as time. - * - * @param name column name - * @param defaultValue value to return if column value is null - * @return column value - */ - public LocalTime getTime(String name, LocalTime defaultValue) { - var value = getTimeOrNull(name); - if (value == null) { - return defaultValue; - } - return value; - } - - /** - * get column value as time. - * - * @param name column name - * @return column value - */ - public @Nonnull Optional findTime(String name) { - var value = getTimeOrNull(name); - return Optional.ofNullable(value); - } - - /** - * get column value as time. - * - * @param name column name - * @return column value - */ - public @Nullable LocalTime getTimeOrNull(String name) { - var value = getValue(name); - return convertUtil.toTime(value); - } - - // dateTime - - /** - * get column value as dateTime. - * - * @param name column name - * @return column value - * @throws NullPointerException if value is null - */ - public @Nonnull LocalDateTime getDateTime(String name) { - var value = getDateTimeOrNull(name); - Objects.requireNonNull(value); - return value; - } - - /** - * get column value as dateTime. - * - * @param name column name - * @param defaultValue value to return if column value is null - * @return column value - */ - public LocalDateTime getDateTime(String name, LocalDateTime defaultValue) { - var value = getDateTimeOrNull(name); - if (value == null) { - return defaultValue; - } - return value; - } - - /** - * get column value as dateTime. - * - * @param name column name - * @return column value - */ - public @Nonnull Optional findDateTime(String name) { - var value = getDateTimeOrNull(name); - return Optional.ofNullable(value); - } - - /** - * get column value as dateTime. - * - * @param name column name - * @return column value - */ - public @Nullable LocalDateTime getDateTimeOrNull(String name) { - var value = getValue(name); - return convertUtil.toDateTime(value); - } - - // offset time - - /** - * get column value as offset time. - * - * @param name column name - * @return column value - * @throws NullPointerException if value is null - */ - public @Nonnull OffsetTime getOffsetTime(String name) { - var value = getOffsetTimeOrNull(name); - Objects.requireNonNull(value); - return value; - } - - /** - * get column value as offset time. - * - * @param name column name - * @param defaultValue value to return if column value is null - * @return column value - */ - public OffsetTime getOffsetTime(String name, OffsetTime defaultValue) { - var value = getOffsetTimeOrNull(name); - if (value == null) { - return defaultValue; - } - return value; - } - - /** - * get column value as offset time. - * - * @param name column name - * @return column value - */ - public @Nonnull Optional findOffsetTime(String name) { - var value = getOffsetTimeOrNull(name); - return Optional.ofNullable(value); - } - - /** - * get column value as offset time. - * - * @param name column name - * @return column value - */ - public @Nullable OffsetTime getOffsetTimeOrNull(String name) { - var value = getValue(name); - return convertUtil.toOffsetTime(value); - } - - // offset dateTime - - /** - * get column value as offset dateTime. - * - * @param name column name - * @return column value - * @throws NullPointerException if value is null - */ - public @Nonnull OffsetDateTime getOffsetDateTime(String name) { - var value = getOffsetDateTimeOrNull(name); - Objects.requireNonNull(value); - return value; + @Override + public @Nullable Object getValueOrNull(int index) { + return values[index]; } - /** - * get column value as offset dateTime. - * - * @param name column name - * @param defaultValue value to return if column value is null - * @return column value + /* + * get by name */ - public OffsetDateTime getOffsetDateTime(String name, OffsetDateTime defaultValue) { - var value = getOffsetDateTimeOrNull(name); - if (value == null) { - return defaultValue; - } - return value; - } /** - * get column value as offset dateTime. + * set ambiguous name policy. * - * @param name column name - * @return column value + * @param policy ambiguous name policy + * @since X.X.X */ - public @Nonnull Optional findOffsetDateTime(String name) { - var value = getOffsetDateTimeOrNull(name); - return Optional.ofNullable(value); + public void setAmbiguousNamePolicy(IceaxeAmbiguousNamePolicy policy) { + this.ambiguousNamePolicy = policy; } /** - * get column value as offset dateTime. + * get ambiguous name policy. * - * @param name column name - * @return column value + * @return ambiguous name policy + * @since X.X.X */ - public @Nullable OffsetDateTime getOffsetDateTimeOrNull(String name) { - var value = getValue(name); - return convertUtil.toOffsetDateTime(value); + public IceaxeAmbiguousNamePolicy getAmbiguousNamePolicy() { + return this.ambiguousNamePolicy; } - // zoned dateTime - /** - * get column value as ZonedDateTime. + * get index. * * @param name column name - * @param zone time-zone - * @return column value - * @throws NullPointerException if value is null - */ - public @Nonnull ZonedDateTime getZonedDateTime(String name, @Nonnull ZoneId zone) { - var value = getZonedDateTimeOrNull(name, zone); - Objects.requireNonNull(value); - return value; - } - - /** - * get column value as ZonedDateTime. - * - * @param name column name - * @param zone time-zone - * @param defaultValue value to return if column value is null - * @return column value + * @return column index + * @see #setAmbiguousNamePolicy(IceaxeAmbiguousNamePolicy) + * @since X.X.X */ - public ZonedDateTime getZonedDateTime(String name, @Nonnull ZoneId zone, ZonedDateTime defaultValue) { - var value = getZonedDateTimeOrNull(name, zone); - if (value == null) { - return defaultValue; + public int getIndex(String name) { + var policy = this.ambiguousNamePolicy; + if (policy == null) { + policy = defaultAmbiguousNamePolicy; } - return value; + return resultNameList.getIndex(name, policy); } /** - * get column value as ZonedDateTime. + * get index. * - * @param name column name - * @param zone time-zone - * @return column value + * @param name column name + * @param subIndex index for same name + * @return column index + * @since X.X.X */ - public @Nonnull Optional findZonedDateTime(String name, @Nonnull ZoneId zone) { - var value = getZonedDateTimeOrNull(name, zone); - return Optional.ofNullable(value); + public int getIndex(String name, int subIndex) { + return resultNameList.getIndex(name, subIndex); } - /** - * get column value as ZonedDateTime. - * - * @param name column name - * @param zone time-zone - * @return column value - */ - public @Nullable ZonedDateTime getZonedDateTimeOrNull(String name, @Nonnull ZoneId zone) { - var value = getValue(name); - return convertUtil.toZonedDateTime(value, zone); + @Override + public @Nullable Object getValueOrNull(String name) { + int index = getIndex(name); + return getValueOrNull(index); } @Override public String toString() { - return getClass().getSimpleName() + valueMap; + var sb = new StringBuilder(256); + sb.append(getClass().getSimpleName()); + sb.append('{'); + var nameList = getNameList(); + for (int i = 0; i < values.length; i++) { + if (i != 0) { + sb.append(", "); + } + + String name = nameList.get(i); + Object value = values[i]; + sb.append(name); + sb.append('='); + sb.append(value); + } + sb.append('}'); + return sb.toString(); } } diff --git a/modules/iceaxe-core/src/main/java/com/tsurugidb/iceaxe/sql/result/TsurugiResultIndexRecord.java b/modules/iceaxe-core/src/main/java/com/tsurugidb/iceaxe/sql/result/TsurugiResultIndexRecord.java new file mode 100755 index 00000000..2df5c8bb --- /dev/null +++ b/modules/iceaxe-core/src/main/java/com/tsurugidb/iceaxe/sql/result/TsurugiResultIndexRecord.java @@ -0,0 +1,949 @@ +package com.tsurugidb.iceaxe.sql.result; + +import java.io.IOException; +import java.math.BigDecimal; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.time.OffsetDateTime; +import java.time.OffsetTime; +import java.time.ZoneId; +import java.time.ZonedDateTime; +import java.util.Objects; +import java.util.Optional; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +import com.tsurugidb.iceaxe.transaction.exception.TsurugiTransactionException; +import com.tsurugidb.iceaxe.util.IceaxeConvertUtil; + +/** + * Tsurugi Result Record for index access. + * + * @since 1.5.0 + */ +public interface TsurugiResultIndexRecord { + + /** + * get value. + * + * @param index column index + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public @Nullable Object getValueOrNull(int index) throws IOException, InterruptedException, TsurugiTransactionException; + + /** + * get convert utility. + * + * @return convert utility + */ + public IceaxeConvertUtil getConvertUtil(); + + // boolean + + /** + * get value as boolean. + * + * @param index column index + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + * @throws NullPointerException if value is null + */ + public default boolean getBoolean(int index) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getBooleanOrNull(index); + return Objects.requireNonNull(value, () -> "getBoolean(" + index + ") is null"); + } + + /** + * get value as boolean. + * + * @param index column index + * @param defaultValue value to return if original value is null + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default boolean getBoolean(int index, boolean defaultValue) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getBooleanOrNull(index); + return (value != null) ? value : defaultValue; + } + + /** + * get value as boolean. + * + * @param index column index + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default @Nonnull Optional findBoolean(int index) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getBooleanOrNull(index); + return Optional.ofNullable(value); + } + + /** + * get value as boolean. + * + * @param index column index + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default @Nullable Boolean getBooleanOrNull(int index) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getValueOrNull(index); + return getConvertUtil().toBoolean(value); + } + + // int + + /** + * get value as int. + * + * @param index column index + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + * @throws NullPointerException if value is null + */ + public default int getInt(int index) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getIntOrNull(index); + return Objects.requireNonNull(value, () -> "getInt(" + index + ") is null"); + } + + /** + * get value as int. + * + * @param index column index + * @param defaultValue value to return if original value is null + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default int getInt(int index, int defaultValue) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getIntOrNull(index); + return (value != null) ? value : defaultValue; + } + + /** + * get value as int. + * + * @param index column index + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default @Nonnull Optional findInt(int index) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getIntOrNull(index); + return Optional.ofNullable(value); + } + + /** + * get value as int. + * + * @param index column index + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default @Nullable Integer getIntOrNull(int index) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getValueOrNull(index); + return getConvertUtil().toInt(value); + } + + // long + + /** + * get value as long. + * + * @param index column index + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + * @throws NullPointerException if value is null + */ + public default long getLong(int index) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getLongOrNull(index); + return Objects.requireNonNull(value, () -> "getLong(" + index + ") is null"); + } + + /** + * get value as long. + * + * @param index column index + * @param defaultValue value to return if original value is null + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default long getLong(int index, long defaultValue) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getLongOrNull(index); + return (value != null) ? value : defaultValue; + } + + /** + * get value as long. + * + * @param index column index + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default @Nonnull Optional findLong(int index) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getLongOrNull(index); + return Optional.ofNullable(value); + } + + /** + * get value as long. + * + * @param index column index + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default @Nullable Long getLongOrNull(int index) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getValueOrNull(index); + return getConvertUtil().toLong(value); + } + + // float + + /** + * get value as float. + * + * @param index column index + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + * @throws NullPointerException if value is null + */ + public default float getFloat(int index) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getFloatOrNull(index); + return Objects.requireNonNull(value, () -> "getFloat(" + index + ") is null"); + } + + /** + * get value as float. + * + * @param index column index + * @param defaultValue value to return if original value is null + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default float getFloat(int index, float defaultValue) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getFloatOrNull(index); + return (value != null) ? value : defaultValue; + } + + /** + * get value as float. + * + * @param index column index + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default @Nonnull Optional findFloat(int index) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getFloatOrNull(index); + return Optional.ofNullable(value); + } + + /** + * get value as float. + * + * @param index column index + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default @Nullable Float getFloatOrNull(int index) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getValueOrNull(index); + return getConvertUtil().toFloat(value); + } + + // double + + /** + * get value as double. + * + * @param index column index + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + * @throws NullPointerException if value is null + */ + public default double getDouble(int index) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getDoubleOrNull(index); + return Objects.requireNonNull(value, () -> "getDouble(" + index + ") is null"); + } + + /** + * get value as double. + * + * @param index column index + * @param defaultValue value to return if original value is null + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default double getDouble(int index, double defaultValue) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getDoubleOrNull(index); + return (value != null) ? value : defaultValue; + } + + /** + * get value as double. + * + * @param index column index + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default @Nonnull Optional findDouble(int index) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getDoubleOrNull(index); + return Optional.ofNullable(value); + } + + /** + * get value as double. + * + * @param index column index + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default @Nullable Double getDoubleOrNull(int index) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getValueOrNull(index); + return getConvertUtil().toDouble(value); + } + + // decimal + + /** + * get value as decimal. + * + * @param index column index + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + * @throws NullPointerException if value is null + */ + public default @Nonnull BigDecimal getDecimal(int index) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getDecimalOrNull(index); + return Objects.requireNonNull(value, () -> "getDecimal(" + index + ") is null"); + } + + /** + * get value as decimal. + * + * @param index column index + * @param defaultValue value to return if original value is null + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default BigDecimal getDecimal(int index, BigDecimal defaultValue) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getDecimalOrNull(index); + return (value != null) ? value : defaultValue; + } + + /** + * get value as decimal. + * + * @param index column index + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default @Nonnull Optional findDecimal(int index) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getDecimalOrNull(index); + return Optional.ofNullable(value); + } + + /** + * get value as decimal. + * + * @param index column index + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default @Nullable BigDecimal getDecimalOrNull(int index) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getValueOrNull(index); + return getConvertUtil().toDecimal(value); + } + + // string + + /** + * get value as string. + * + * @param index column index + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + * @throws NullPointerException if value is null + */ + public default @Nonnull String getString(int index) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getStringOrNull(index); + return Objects.requireNonNull(value, () -> "getString(" + index + ") is null"); + } + + /** + * get value as string. + * + * @param index column index + * @param defaultValue value to return if original value is null + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default String getString(int index, String defaultValue) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getStringOrNull(index); + return (value != null) ? value : defaultValue; + } + + /** + * get value as string. + * + * @param index column index + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default @Nonnull Optional findString(int index) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getStringOrNull(index); + return Optional.ofNullable(value); + } + + /** + * get value as string. + * + * @param index column index + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default @Nullable String getStringOrNull(int index) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getValueOrNull(index); + return getConvertUtil().toString(value); + } + + // byte[] + + /** + * get value as byte[]. + * + * @param index column index + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + * @throws NullPointerException if value is null + */ + public default @Nonnull byte[] getBytes(int index) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getBytesOrNull(index); + return Objects.requireNonNull(value, () -> "getBytes(" + index + ") is null"); + } + + /** + * get value as byte[]. + * + * @param index column index + * @param defaultValue value to return if original value is null + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default byte[] getBytes(int index, byte[] defaultValue) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getBytesOrNull(index); + return (value != null) ? value : defaultValue; + } + + /** + * get value as byte[]. + * + * @param index column index + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default @Nonnull Optional findBytes(int index) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getBytesOrNull(index); + return Optional.ofNullable(value); + } + + /** + * get value as byte[]. + * + * @param index column index + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default @Nullable byte[] getBytesOrNull(int index) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getValueOrNull(index); + return getConvertUtil().toBytes(value); + } + + // boolean[] + + /** + * get value as boolean[]. + * + * @param index column index + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + * @throws NullPointerException if value is null + */ + public default @Nonnull boolean[] getBits(int index) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getBitsOrNull(index); + return Objects.requireNonNull(value, () -> "getBits(" + index + ") is null"); + } + + /** + * get value as boolean[]. + * + * @param index column index + * @param defaultValue value to return if original value is null + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default boolean[] getBits(int index, boolean[] defaultValue) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getBitsOrNull(index); + return (value != null) ? value : defaultValue; + } + + /** + * get value as boolean[]. + * + * @param index column index + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default @Nonnull Optional findBits(int index) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getBitsOrNull(index); + return Optional.ofNullable(value); + } + + /** + * get value as boolean[]. + * + * @param index column index + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default @Nullable boolean[] getBitsOrNull(int index) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getValueOrNull(index); + return getConvertUtil().toBits(value); + } + + // date + + /** + * get value as date. + * + * @param index column index + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + * @throws NullPointerException if value is null + */ + public default @Nonnull LocalDate getDate(int index) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getDateOrNull(index); + return Objects.requireNonNull(value, () -> "getDate(" + index + ") is null"); + } + + /** + * get value as date. + * + * @param index column index + * @param defaultValue value to return if original value is null + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default LocalDate getDate(int index, LocalDate defaultValue) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getDateOrNull(index); + return (value != null) ? value : defaultValue; + } + + /** + * get value as date. + * + * @param index column index + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default @Nonnull Optional findDate(int index) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getDateOrNull(index); + return Optional.ofNullable(value); + } + + /** + * get value as date. + * + * @param index column index + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default @Nullable LocalDate getDateOrNull(int index) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getValueOrNull(index); + return getConvertUtil().toDate(value); + } + + // time + + /** + * get value as time. + * + * @param index column index + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + * @throws NullPointerException if value is null + */ + public default @Nonnull LocalTime getTime(int index) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getTimeOrNull(index); + return Objects.requireNonNull(value, () -> "getTime(" + index + ") is null"); + } + + /** + * get value as time. + * + * @param index column index + * @param defaultValue value to return if original value is null + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default LocalTime getTime(int index, LocalTime defaultValue) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getTimeOrNull(index); + return (value != null) ? value : defaultValue; + } + + /** + * get value as time. + * + * @param index column index + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default @Nonnull Optional findTime(int index) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getTimeOrNull(index); + return Optional.ofNullable(value); + } + + /** + * get value as time. + * + * @param index column index + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default @Nullable LocalTime getTimeOrNull(int index) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getValueOrNull(index); + return getConvertUtil().toTime(value); + } + + // dateTime + + /** + * get value as dateTime. + * + * @param index column index + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + * @throws NullPointerException if value is null + */ + public default @Nonnull LocalDateTime getDateTime(int index) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getDateTimeOrNull(index); + return Objects.requireNonNull(value, () -> "getDateTime(" + index + ") is null"); + } + + /** + * get value as dateTime. + * + * @param index column index + * @param defaultValue value to return if original value is null + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default LocalDateTime getDateTime(int index, LocalDateTime defaultValue) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getDateTimeOrNull(index); + return (value != null) ? value : defaultValue; + } + + /** + * get value as dateTime. + * + * @param index column index + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default @Nonnull Optional findDateTime(int index) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getDateTimeOrNull(index); + return Optional.ofNullable(value); + } + + /** + * get value as dateTime. + * + * @param index column index + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default @Nullable LocalDateTime getDateTimeOrNull(int index) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getValueOrNull(index); + return getConvertUtil().toDateTime(value); + } + + // offset time + + /** + * get value as offset time. + * + * @param index column index + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + * @throws NullPointerException if value is null + */ + public default @Nonnull OffsetTime getOffsetTime(int index) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getOffsetTimeOrNull(index); + return Objects.requireNonNull(value, () -> "getOffsetTime(" + index + ") is null"); + } + + /** + * get value as offset time. + * + * @param index column index + * @param defaultValue value to return if original value is null + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default OffsetTime getOffsetTime(int index, OffsetTime defaultValue) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getOffsetTimeOrNull(index); + return (value != null) ? value : defaultValue; + } + + /** + * get value as offset time. + * + * @param index column index + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default @Nonnull Optional findOffsetTime(int index) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getOffsetTimeOrNull(index); + return Optional.ofNullable(value); + } + + /** + * get value as offset time. + * + * @param index column index + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default @Nullable OffsetTime getOffsetTimeOrNull(int index) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getValueOrNull(index); + return getConvertUtil().toOffsetTime(value); + } + + // offset dateTime + + /** + * get value as offset dateTime. + * + * @param index column index + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + * @throws NullPointerException if value is null + */ + public default @Nonnull OffsetDateTime getOffsetDateTime(int index) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getOffsetDateTimeOrNull(index); + return Objects.requireNonNull(value, () -> "getOffsetDateTime(" + index + ") is null"); + } + + /** + * get value as offset dateTime. + * + * @param index column index + * @param defaultValue value to return if original value is null + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default OffsetDateTime getOffsetDateTime(int index, OffsetDateTime defaultValue) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getOffsetDateTimeOrNull(index); + return (value != null) ? value : defaultValue; + } + + /** + * get value as offset dateTime. + * + * @param index column index + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default @Nonnull Optional findOffsetDateTime(int index) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getOffsetDateTimeOrNull(index); + return Optional.ofNullable(value); + } + + /** + * get value as offset dateTime. + * + * @param index column index + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default @Nullable OffsetDateTime getOffsetDateTimeOrNull(int index) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getValueOrNull(index); + return getConvertUtil().toOffsetDateTime(value); + } + + // zoned dateTime + + /** + * get value as zoned dateTime. + * + * @param index column index + * @param zone time-zone + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + * @throws NullPointerException if value is null + */ + public default @Nonnull ZonedDateTime getZonedDateTime(int index, @Nonnull ZoneId zone) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getZonedDateTimeOrNull(index, zone); + return Objects.requireNonNull(value, () -> "getZonedDateTime(" + index + ") is null"); + } + + /** + * get value as zoned dateTime. + * + * @param index column index + * @param zone time-zone + * @param defaultValue value to return if original value is null + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default ZonedDateTime getZonedDateTime(int index, @Nonnull ZoneId zone, ZonedDateTime defaultValue) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getZonedDateTimeOrNull(index, zone); + return (value != null) ? value : defaultValue; + } + + /** + * get value as zoned dateTime. + * + * @param index column index + * @param zone time-zone + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default @Nonnull Optional findZonedDateTime(int index, @Nonnull ZoneId zone) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getZonedDateTimeOrNull(index, zone); + return Optional.ofNullable(value); + } + + /** + * get value as zoned dateTime. + * + * @param index column index + * @param zone time-zone + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default @Nullable ZonedDateTime getZonedDateTimeOrNull(int index, @Nonnull ZoneId zone) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getValueOrNull(index); + return getConvertUtil().toZonedDateTime(value, zone); + } +} diff --git a/modules/iceaxe-core/src/main/java/com/tsurugidb/iceaxe/sql/result/TsurugiResultNameRecord.java b/modules/iceaxe-core/src/main/java/com/tsurugidb/iceaxe/sql/result/TsurugiResultNameRecord.java new file mode 100755 index 00000000..49e9b662 --- /dev/null +++ b/modules/iceaxe-core/src/main/java/com/tsurugidb/iceaxe/sql/result/TsurugiResultNameRecord.java @@ -0,0 +1,949 @@ +package com.tsurugidb.iceaxe.sql.result; + +import java.io.IOException; +import java.math.BigDecimal; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.time.OffsetDateTime; +import java.time.OffsetTime; +import java.time.ZoneId; +import java.time.ZonedDateTime; +import java.util.Objects; +import java.util.Optional; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +import com.tsurugidb.iceaxe.transaction.exception.TsurugiTransactionException; +import com.tsurugidb.iceaxe.util.IceaxeConvertUtil; + +/** + * Tsurugi Result Record for name access. + * + * @since 1.5.0 + */ +public interface TsurugiResultNameRecord { + + /** + * get value. + * + * @param name column name + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public @Nullable Object getValueOrNull(String name) throws IOException, InterruptedException, TsurugiTransactionException; + + /** + * get convert utility. + * + * @return convert utility + */ + public IceaxeConvertUtil getConvertUtil(); + + // boolean + + /** + * get value as boolean. + * + * @param name column name + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + * @throws NullPointerException if value is null + */ + public default boolean getBoolean(String name) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getBooleanOrNull(name); + return Objects.requireNonNull(value, () -> "getBoolean(" + name + ") is null"); + } + + /** + * get value as boolean. + * + * @param name column name + * @param defaultValue value to return if original value is null + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default boolean getBoolean(String name, boolean defaultValue) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getBooleanOrNull(name); + return (value != null) ? value : defaultValue; + } + + /** + * get value as boolean. + * + * @param name column name + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default @Nonnull Optional findBoolean(String name) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getBooleanOrNull(name); + return Optional.ofNullable(value); + } + + /** + * get value as boolean. + * + * @param name column name + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default @Nullable Boolean getBooleanOrNull(String name) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getValueOrNull(name); + return getConvertUtil().toBoolean(value); + } + + // int + + /** + * get value as int. + * + * @param name column name + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + * @throws NullPointerException if value is null + */ + public default int getInt(String name) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getIntOrNull(name); + return Objects.requireNonNull(value, () -> "getInt(" + name + ") is null"); + } + + /** + * get value as int. + * + * @param name column name + * @param defaultValue value to return if original value is null + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default int getInt(String name, int defaultValue) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getIntOrNull(name); + return (value != null) ? value : defaultValue; + } + + /** + * get value as int. + * + * @param name column name + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default @Nonnull Optional findInt(String name) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getIntOrNull(name); + return Optional.ofNullable(value); + } + + /** + * get value as int. + * + * @param name column name + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default @Nullable Integer getIntOrNull(String name) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getValueOrNull(name); + return getConvertUtil().toInt(value); + } + + // long + + /** + * get value as long. + * + * @param name column name + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + * @throws NullPointerException if value is null + */ + public default long getLong(String name) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getLongOrNull(name); + return Objects.requireNonNull(value, () -> "getLong(" + name + ") is null"); + } + + /** + * get value as long. + * + * @param name column name + * @param defaultValue value to return if original value is null + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default long getLong(String name, long defaultValue) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getLongOrNull(name); + return (value != null) ? value : defaultValue; + } + + /** + * get value as long. + * + * @param name column name + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default @Nonnull Optional findLong(String name) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getLongOrNull(name); + return Optional.ofNullable(value); + } + + /** + * get value as long. + * + * @param name column name + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default @Nullable Long getLongOrNull(String name) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getValueOrNull(name); + return getConvertUtil().toLong(value); + } + + // float + + /** + * get value as float. + * + * @param name column name + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + * @throws NullPointerException if value is null + */ + public default float getFloat(String name) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getFloatOrNull(name); + return Objects.requireNonNull(value, () -> "getFloat(" + name + ") is null"); + } + + /** + * get value as float. + * + * @param name column name + * @param defaultValue value to return if original value is null + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default float getFloat(String name, float defaultValue) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getFloatOrNull(name); + return (value != null) ? value : defaultValue; + } + + /** + * get value as float. + * + * @param name column name + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default @Nonnull Optional findFloat(String name) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getFloatOrNull(name); + return Optional.ofNullable(value); + } + + /** + * get value as float. + * + * @param name column name + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default @Nullable Float getFloatOrNull(String name) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getValueOrNull(name); + return getConvertUtil().toFloat(value); + } + + // double + + /** + * get value as double. + * + * @param name column name + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + * @throws NullPointerException if value is null + */ + public default double getDouble(String name) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getDoubleOrNull(name); + return Objects.requireNonNull(value, () -> "getDouble(" + name + ") is null"); + } + + /** + * get value as double. + * + * @param name column name + * @param defaultValue value to return if original value is null + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default double getDouble(String name, double defaultValue) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getDoubleOrNull(name); + return (value != null) ? value : defaultValue; + } + + /** + * get value as double. + * + * @param name column name + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default @Nonnull Optional findDouble(String name) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getDoubleOrNull(name); + return Optional.ofNullable(value); + } + + /** + * get value as double. + * + * @param name column name + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default @Nullable Double getDoubleOrNull(String name) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getValueOrNull(name); + return getConvertUtil().toDouble(value); + } + + // decimal + + /** + * get value as decimal. + * + * @param name column name + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + * @throws NullPointerException if value is null + */ + public default @Nonnull BigDecimal getDecimal(String name) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getDecimalOrNull(name); + return Objects.requireNonNull(value, () -> "getDecimal(" + name + ") is null"); + } + + /** + * get value as decimal. + * + * @param name column name + * @param defaultValue value to return if original value is null + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default BigDecimal getDecimal(String name, BigDecimal defaultValue) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getDecimalOrNull(name); + return (value != null) ? value : defaultValue; + } + + /** + * get value as decimal. + * + * @param name column name + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default @Nonnull Optional findDecimal(String name) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getDecimalOrNull(name); + return Optional.ofNullable(value); + } + + /** + * get value as decimal. + * + * @param name column name + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default @Nullable BigDecimal getDecimalOrNull(String name) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getValueOrNull(name); + return getConvertUtil().toDecimal(value); + } + + // string + + /** + * get value as string. + * + * @param name column name + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + * @throws NullPointerException if value is null + */ + public default @Nonnull String getString(String name) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getStringOrNull(name); + return Objects.requireNonNull(value, () -> "getString(" + name + ") is null"); + } + + /** + * get value as string. + * + * @param name column name + * @param defaultValue value to return if original value is null + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default String getString(String name, String defaultValue) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getStringOrNull(name); + return (value != null) ? value : defaultValue; + } + + /** + * get value as string. + * + * @param name column name + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default @Nonnull Optional findString(String name) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getStringOrNull(name); + return Optional.ofNullable(value); + } + + /** + * get value as string. + * + * @param name column name + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default @Nullable String getStringOrNull(String name) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getValueOrNull(name); + return getConvertUtil().toString(value); + } + + // byte[] + + /** + * get value as byte[]. + * + * @param name column name + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + * @throws NullPointerException if value is null + */ + public default @Nonnull byte[] getBytes(String name) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getBytesOrNull(name); + return Objects.requireNonNull(value, () -> "getBytes(" + name + ") is null"); + } + + /** + * get value as byte[]. + * + * @param name column name + * @param defaultValue value to return if original value is null + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default byte[] getBytes(String name, byte[] defaultValue) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getBytesOrNull(name); + return (value != null) ? value : defaultValue; + } + + /** + * get value as byte[]. + * + * @param name column name + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default @Nonnull Optional findBytes(String name) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getBytesOrNull(name); + return Optional.ofNullable(value); + } + + /** + * get value as byte[]. + * + * @param name column name + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default @Nullable byte[] getBytesOrNull(String name) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getValueOrNull(name); + return getConvertUtil().toBytes(value); + } + + // boolean[] + + /** + * get value as boolean[]. + * + * @param name column name + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + * @throws NullPointerException if value is null + */ + public default @Nonnull boolean[] getBits(String name) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getBitsOrNull(name); + return Objects.requireNonNull(value, () -> "getBits(" + name + ") is null"); + } + + /** + * get value as boolean[]. + * + * @param name column name + * @param defaultValue value to return if original value is null + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default boolean[] getBits(String name, boolean[] defaultValue) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getBitsOrNull(name); + return (value != null) ? value : defaultValue; + } + + /** + * get value as boolean[]. + * + * @param name column name + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default @Nonnull Optional findBits(String name) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getBitsOrNull(name); + return Optional.ofNullable(value); + } + + /** + * get value as boolean[]. + * + * @param name column name + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default @Nullable boolean[] getBitsOrNull(String name) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getValueOrNull(name); + return getConvertUtil().toBits(value); + } + + // date + + /** + * get value as date. + * + * @param name column name + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + * @throws NullPointerException if value is null + */ + public default @Nonnull LocalDate getDate(String name) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getDateOrNull(name); + return Objects.requireNonNull(value, () -> "getDate(" + name + ") is null"); + } + + /** + * get value as date. + * + * @param name column name + * @param defaultValue value to return if original value is null + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default LocalDate getDate(String name, LocalDate defaultValue) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getDateOrNull(name); + return (value != null) ? value : defaultValue; + } + + /** + * get value as date. + * + * @param name column name + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default @Nonnull Optional findDate(String name) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getDateOrNull(name); + return Optional.ofNullable(value); + } + + /** + * get value as date. + * + * @param name column name + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default @Nullable LocalDate getDateOrNull(String name) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getValueOrNull(name); + return getConvertUtil().toDate(value); + } + + // time + + /** + * get value as time. + * + * @param name column name + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + * @throws NullPointerException if value is null + */ + public default @Nonnull LocalTime getTime(String name) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getTimeOrNull(name); + return Objects.requireNonNull(value, () -> "getTime(" + name + ") is null"); + } + + /** + * get value as time. + * + * @param name column name + * @param defaultValue value to return if original value is null + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default LocalTime getTime(String name, LocalTime defaultValue) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getTimeOrNull(name); + return (value != null) ? value : defaultValue; + } + + /** + * get value as time. + * + * @param name column name + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default @Nonnull Optional findTime(String name) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getTimeOrNull(name); + return Optional.ofNullable(value); + } + + /** + * get value as time. + * + * @param name column name + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default @Nullable LocalTime getTimeOrNull(String name) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getValueOrNull(name); + return getConvertUtil().toTime(value); + } + + // dateTime + + /** + * get value as dateTime. + * + * @param name column name + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + * @throws NullPointerException if value is null + */ + public default @Nonnull LocalDateTime getDateTime(String name) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getDateTimeOrNull(name); + return Objects.requireNonNull(value, () -> "getDateTime(" + name + ") is null"); + } + + /** + * get value as dateTime. + * + * @param name column name + * @param defaultValue value to return if original value is null + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default LocalDateTime getDateTime(String name, LocalDateTime defaultValue) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getDateTimeOrNull(name); + return (value != null) ? value : defaultValue; + } + + /** + * get value as dateTime. + * + * @param name column name + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default @Nonnull Optional findDateTime(String name) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getDateTimeOrNull(name); + return Optional.ofNullable(value); + } + + /** + * get value as dateTime. + * + * @param name column name + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default @Nullable LocalDateTime getDateTimeOrNull(String name) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getValueOrNull(name); + return getConvertUtil().toDateTime(value); + } + + // offset time + + /** + * get value as offset time. + * + * @param name column name + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + * @throws NullPointerException if value is null + */ + public default @Nonnull OffsetTime getOffsetTime(String name) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getOffsetTimeOrNull(name); + return Objects.requireNonNull(value, () -> "getOffsetTime(" + name + ") is null"); + } + + /** + * get value as offset time. + * + * @param name column name + * @param defaultValue value to return if original value is null + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default OffsetTime getOffsetTime(String name, OffsetTime defaultValue) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getOffsetTimeOrNull(name); + return (value != null) ? value : defaultValue; + } + + /** + * get value as offset time. + * + * @param name column name + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default @Nonnull Optional findOffsetTime(String name) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getOffsetTimeOrNull(name); + return Optional.ofNullable(value); + } + + /** + * get value as offset time. + * + * @param name column name + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default @Nullable OffsetTime getOffsetTimeOrNull(String name) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getValueOrNull(name); + return getConvertUtil().toOffsetTime(value); + } + + // offset dateTime + + /** + * get value as offset dateTime. + * + * @param name column name + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + * @throws NullPointerException if value is null + */ + public default @Nonnull OffsetDateTime getOffsetDateTime(String name) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getOffsetDateTimeOrNull(name); + return Objects.requireNonNull(value, () -> "getOffsetDateTime(" + name + ") is null"); + } + + /** + * get value as offset dateTime. + * + * @param name column name + * @param defaultValue value to return if original value is null + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default OffsetDateTime getOffsetDateTime(String name, OffsetDateTime defaultValue) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getOffsetDateTimeOrNull(name); + return (value != null) ? value : defaultValue; + } + + /** + * get value as offset dateTime. + * + * @param name column name + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default @Nonnull Optional findOffsetDateTime(String name) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getOffsetDateTimeOrNull(name); + return Optional.ofNullable(value); + } + + /** + * get value as offset dateTime. + * + * @param name column name + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default @Nullable OffsetDateTime getOffsetDateTimeOrNull(String name) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getValueOrNull(name); + return getConvertUtil().toOffsetDateTime(value); + } + + // zoned dateTime + + /** + * get value as zoned dateTime. + * + * @param name column name + * @param zone time-zone + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + * @throws NullPointerException if value is null + */ + public default @Nonnull ZonedDateTime getZonedDateTime(String name, @Nonnull ZoneId zone) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getZonedDateTimeOrNull(name, zone); + return Objects.requireNonNull(value, () -> "getZonedDateTime(" + name + ") is null"); + } + + /** + * get value as zoned dateTime. + * + * @param name column name + * @param zone time-zone + * @param defaultValue value to return if original value is null + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default ZonedDateTime getZonedDateTime(String name, @Nonnull ZoneId zone, ZonedDateTime defaultValue) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getZonedDateTimeOrNull(name, zone); + return (value != null) ? value : defaultValue; + } + + /** + * get value as zoned dateTime. + * + * @param name column name + * @param zone time-zone + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default @Nonnull Optional findZonedDateTime(String name, @Nonnull ZoneId zone) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getZonedDateTimeOrNull(name, zone); + return Optional.ofNullable(value); + } + + /** + * get value as zoned dateTime. + * + * @param name column name + * @param zone time-zone + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default @Nullable ZonedDateTime getZonedDateTimeOrNull(String name, @Nonnull ZoneId zone) throws IOException, InterruptedException, TsurugiTransactionException { + var value = getValueOrNull(name); + return getConvertUtil().toZonedDateTime(value, zone); + } +} diff --git a/modules/iceaxe-core/src/main/java/com/tsurugidb/iceaxe/sql/result/TsurugiResultNextRecord.java b/modules/iceaxe-core/src/main/java/com/tsurugidb/iceaxe/sql/result/TsurugiResultNextRecord.java new file mode 100755 index 00000000..932d1f15 --- /dev/null +++ b/modules/iceaxe-core/src/main/java/com/tsurugidb/iceaxe/sql/result/TsurugiResultNextRecord.java @@ -0,0 +1,897 @@ +package com.tsurugidb.iceaxe.sql.result; + +import java.io.IOException; +import java.math.BigDecimal; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.time.OffsetDateTime; +import java.time.OffsetTime; +import java.time.ZoneId; +import java.time.ZonedDateTime; +import java.util.Objects; +import java.util.Optional; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +import com.tsurugidb.iceaxe.transaction.exception.TsurugiTransactionException; +import com.tsurugidb.iceaxe.util.IceaxeConvertUtil; +import com.tsurugidb.iceaxe.util.IceaxeInternal; + +/** + * Tsurugi Result Record for sequential access. + * + * @since 1.5.0 + */ +public interface TsurugiResultNextRecord { + + /** + * get current value and move next column. + * + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public @Nullable Object nextValueOrNull() throws IOException, InterruptedException, TsurugiTransactionException; + + /** + * get convert utility. + * + * @return convert utility + */ + public IceaxeConvertUtil getConvertUtil(); + + /** + * get current column index. + * + * @return currenct olumn index + */ + @IceaxeInternal + /* protected */ int getCurrentColumnIndex(); + + // boolean + + /** + * get current value as boolean and move next column. + * + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + * @throws NullPointerException if value is null + */ + public default boolean nextBoolean() throws IOException, InterruptedException, TsurugiTransactionException { + var value = nextBooleanOrNull(); + return Objects.requireNonNull(value, () -> "nextBoolean(" + getCurrentColumnIndex() + ") is null"); + } + + /** + * get current value as boolean and move next column. + * + * @param defaultValue value to return if original value is null + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default boolean nextBoolean(boolean defaultValue) throws IOException, InterruptedException, TsurugiTransactionException { + var value = nextBooleanOrNull(); + return (value != null) ? value : defaultValue; + } + + /** + * get current value as boolean and move next column. + * + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default @Nonnull Optional nextBooleanOpt() throws IOException, InterruptedException, TsurugiTransactionException { + var value = nextBooleanOrNull(); + return Optional.ofNullable(value); + } + + /** + * get current value as boolean and move next column. + * + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default @Nullable Boolean nextBooleanOrNull() throws IOException, InterruptedException, TsurugiTransactionException { + var value = nextValueOrNull(); + return getConvertUtil().toBoolean(value); + } + + // int + + /** + * get current value as int and move next column. + * + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + * @throws NullPointerException if value is null + */ + public default int nextInt() throws IOException, InterruptedException, TsurugiTransactionException { + var value = nextIntOrNull(); + return Objects.requireNonNull(value, () -> "nextInt(" + getCurrentColumnIndex() + ") is null"); + } + + /** + * get current value as int and move next column. + * + * @param defaultValue value to return if original value is null + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default int nextInt(int defaultValue) throws IOException, InterruptedException, TsurugiTransactionException { + var value = nextIntOrNull(); + return (value != null) ? value : defaultValue; + } + + /** + * get current value as int and move next column. + * + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default @Nonnull Optional nextIntOpt() throws IOException, InterruptedException, TsurugiTransactionException { + var value = nextIntOrNull(); + return Optional.ofNullable(value); + } + + /** + * get current value as int and move next column. + * + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default @Nullable Integer nextIntOrNull() throws IOException, InterruptedException, TsurugiTransactionException { + var value = nextValueOrNull(); + return getConvertUtil().toInt(value); + } + + // long + + /** + * get current value as long and move next column. + * + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + * @throws NullPointerException if value is null + */ + public default long nextLong() throws IOException, InterruptedException, TsurugiTransactionException { + var value = nextLongOrNull(); + return Objects.requireNonNull(value, () -> "nextLong(" + getCurrentColumnIndex() + ") is null"); + } + + /** + * get current value as long and move next column. + * + * @param defaultValue value to return if original value is null + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default long nextLong(long defaultValue) throws IOException, InterruptedException, TsurugiTransactionException { + var value = nextLongOrNull(); + return (value != null) ? value : defaultValue; + } + + /** + * get current value as long and move next column. + * + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default @Nonnull Optional nextLongOpt() throws IOException, InterruptedException, TsurugiTransactionException { + var value = nextLongOrNull(); + return Optional.ofNullable(value); + } + + /** + * get current value as long and move next column. + * + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default @Nullable Long nextLongOrNull() throws IOException, InterruptedException, TsurugiTransactionException { + var value = nextValueOrNull(); + return getConvertUtil().toLong(value); + } + + // float + + /** + * get current value as float and move next column. + * + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + * @throws NullPointerException if value is null + */ + public default float nextFloat() throws IOException, InterruptedException, TsurugiTransactionException { + var value = nextFloatOrNull(); + return Objects.requireNonNull(value, () -> "nextFloat(" + getCurrentColumnIndex() + ") is null"); + } + + /** + * get current value as float and move next column. + * + * @param defaultValue value to return if original value is null + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default float nextFloat(float defaultValue) throws IOException, InterruptedException, TsurugiTransactionException { + var value = nextFloatOrNull(); + return (value != null) ? value : defaultValue; + } + + /** + * get current value as float and move next column. + * + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default @Nonnull Optional nextFloatOpt() throws IOException, InterruptedException, TsurugiTransactionException { + var value = nextFloatOrNull(); + return Optional.ofNullable(value); + } + + /** + * get current value as float and move next column. + * + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default @Nullable Float nextFloatOrNull() throws IOException, InterruptedException, TsurugiTransactionException { + var value = nextValueOrNull(); + return getConvertUtil().toFloat(value); + } + + // double + + /** + * get current value as double and move next column. + * + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + * @throws NullPointerException if value is null + */ + public default double nextDouble() throws IOException, InterruptedException, TsurugiTransactionException { + var value = nextDoubleOrNull(); + return Objects.requireNonNull(value, () -> "nextDouble(" + getCurrentColumnIndex() + ") is null"); + } + + /** + * get current value as double and move next column. + * + * @param defaultValue value to return if original value is null + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default double nextDouble(double defaultValue) throws IOException, InterruptedException, TsurugiTransactionException { + var value = nextDoubleOrNull(); + return (value != null) ? value : defaultValue; + } + + /** + * get current value as double and move next column. + * + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default @Nonnull Optional nextDoubleOpt() throws IOException, InterruptedException, TsurugiTransactionException { + var value = nextDoubleOrNull(); + return Optional.ofNullable(value); + } + + /** + * get current value as double and move next column. + * + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default @Nullable Double nextDoubleOrNull() throws IOException, InterruptedException, TsurugiTransactionException { + var value = nextValueOrNull(); + return getConvertUtil().toDouble(value); + } + + // decimal + + /** + * get current value as decimal and move next column. + * + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + * @throws NullPointerException if value is null + */ + public default @Nonnull BigDecimal nextDecimal() throws IOException, InterruptedException, TsurugiTransactionException { + var value = nextDecimalOrNull(); + return Objects.requireNonNull(value, () -> "nextDecimal(" + getCurrentColumnIndex() + ") is null"); + } + + /** + * get current value as decimal and move next column. + * + * @param defaultValue value to return if original value is null + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default BigDecimal nextDecimal(BigDecimal defaultValue) throws IOException, InterruptedException, TsurugiTransactionException { + var value = nextDecimalOrNull(); + return (value != null) ? value : defaultValue; + } + + /** + * get current value as decimal and move next column. + * + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default @Nonnull Optional nextDecimalOpt() throws IOException, InterruptedException, TsurugiTransactionException { + var value = nextDecimalOrNull(); + return Optional.ofNullable(value); + } + + /** + * get current value as decimal and move next column. + * + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default @Nullable BigDecimal nextDecimalOrNull() throws IOException, InterruptedException, TsurugiTransactionException { + var value = nextValueOrNull(); + return getConvertUtil().toDecimal(value); + } + + // string + + /** + * get current value as string and move next column. + * + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + * @throws NullPointerException if value is null + */ + public default @Nonnull String nextString() throws IOException, InterruptedException, TsurugiTransactionException { + var value = nextStringOrNull(); + return Objects.requireNonNull(value, () -> "nextString(" + getCurrentColumnIndex() + ") is null"); + } + + /** + * get current value as string and move next column. + * + * @param defaultValue value to return if original value is null + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default String nextString(String defaultValue) throws IOException, InterruptedException, TsurugiTransactionException { + var value = nextStringOrNull(); + return (value != null) ? value : defaultValue; + } + + /** + * get current value as string and move next column. + * + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default @Nonnull Optional nextStringOpt() throws IOException, InterruptedException, TsurugiTransactionException { + var value = nextStringOrNull(); + return Optional.ofNullable(value); + } + + /** + * get current value as string and move next column. + * + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default @Nullable String nextStringOrNull() throws IOException, InterruptedException, TsurugiTransactionException { + var value = nextValueOrNull(); + return getConvertUtil().toString(value); + } + + // byte[] + + /** + * get current value as byte[] and move next column. + * + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + * @throws NullPointerException if value is null + */ + public default @Nonnull byte[] nextBytes() throws IOException, InterruptedException, TsurugiTransactionException { + var value = nextBytesOrNull(); + return Objects.requireNonNull(value, () -> "nextBytes(" + getCurrentColumnIndex() + ") is null"); + } + + /** + * get current value as byte[] and move next column. + * + * @param defaultValue value to return if original value is null + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default byte[] nextBytes(byte[] defaultValue) throws IOException, InterruptedException, TsurugiTransactionException { + var value = nextBytesOrNull(); + return (value != null) ? value : defaultValue; + } + + /** + * get current value as byte[] and move next column. + * + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default @Nonnull Optional nextBytesOpt() throws IOException, InterruptedException, TsurugiTransactionException { + var value = nextBytesOrNull(); + return Optional.ofNullable(value); + } + + /** + * get current value as byte[] and move next column. + * + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default @Nullable byte[] nextBytesOrNull() throws IOException, InterruptedException, TsurugiTransactionException { + var value = nextValueOrNull(); + return getConvertUtil().toBytes(value); + } + + // boolean[] + + /** + * get current value as boolean[] and move next column. + * + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + * @throws NullPointerException if value is null + */ + public default @Nonnull boolean[] nextBits() throws IOException, InterruptedException, TsurugiTransactionException { + var value = nextBitsOrNull(); + return Objects.requireNonNull(value, () -> "nextBits(" + getCurrentColumnIndex() + ") is null"); + } + + /** + * get current value as boolean[] and move next column. + * + * @param defaultValue value to return if original value is null + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default boolean[] nextBits(boolean[] defaultValue) throws IOException, InterruptedException, TsurugiTransactionException { + var value = nextBitsOrNull(); + return (value != null) ? value : defaultValue; + } + + /** + * get current value as boolean[] and move next column. + * + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default @Nonnull Optional nextBitsOpt() throws IOException, InterruptedException, TsurugiTransactionException { + var value = nextBitsOrNull(); + return Optional.ofNullable(value); + } + + /** + * get current value as boolean[] and move next column. + * + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default @Nullable boolean[] nextBitsOrNull() throws IOException, InterruptedException, TsurugiTransactionException { + var value = nextValueOrNull(); + return getConvertUtil().toBits(value); + } + + // date + + /** + * get current value as date and move next column. + * + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + * @throws NullPointerException if value is null + */ + public default @Nonnull LocalDate nextDate() throws IOException, InterruptedException, TsurugiTransactionException { + var value = nextDateOrNull(); + return Objects.requireNonNull(value, () -> "nextDate(" + getCurrentColumnIndex() + ") is null"); + } + + /** + * get current value as date and move next column. + * + * @param defaultValue value to return if original value is null + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default LocalDate nextDate(LocalDate defaultValue) throws IOException, InterruptedException, TsurugiTransactionException { + var value = nextDateOrNull(); + return (value != null) ? value : defaultValue; + } + + /** + * get current value as date and move next column. + * + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default @Nonnull Optional nextDateOpt() throws IOException, InterruptedException, TsurugiTransactionException { + var value = nextDateOrNull(); + return Optional.ofNullable(value); + } + + /** + * get current value as date and move next column. + * + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default @Nullable LocalDate nextDateOrNull() throws IOException, InterruptedException, TsurugiTransactionException { + var value = nextValueOrNull(); + return getConvertUtil().toDate(value); + } + + // time + + /** + * get current value as time and move next column. + * + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + * @throws NullPointerException if value is null + */ + public default @Nonnull LocalTime nextTime() throws IOException, InterruptedException, TsurugiTransactionException { + var value = nextTimeOrNull(); + return Objects.requireNonNull(value, () -> "nextTime(" + getCurrentColumnIndex() + ") is null"); + } + + /** + * get current value as time and move next column. + * + * @param defaultValue value to return if original value is null + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default LocalTime nextTime(LocalTime defaultValue) throws IOException, InterruptedException, TsurugiTransactionException { + var value = nextTimeOrNull(); + return (value != null) ? value : defaultValue; + } + + /** + * get current value as time and move next column. + * + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default @Nonnull Optional nextTimeOpt() throws IOException, InterruptedException, TsurugiTransactionException { + var value = nextTimeOrNull(); + return Optional.ofNullable(value); + } + + /** + * get current value as time and move next column. + * + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default @Nullable LocalTime nextTimeOrNull() throws IOException, InterruptedException, TsurugiTransactionException { + var value = nextValueOrNull(); + return getConvertUtil().toTime(value); + } + + // dateTime + + /** + * get current value as dateTime and move next column. + * + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + * @throws NullPointerException if value is null + */ + public default @Nonnull LocalDateTime nextDateTime() throws IOException, InterruptedException, TsurugiTransactionException { + var value = nextDateTimeOrNull(); + return Objects.requireNonNull(value, () -> "nextDateTime(" + getCurrentColumnIndex() + ") is null"); + } + + /** + * get current value as dateTime and move next column. + * + * @param defaultValue value to return if original value is null + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default LocalDateTime nextDateTime(LocalDateTime defaultValue) throws IOException, InterruptedException, TsurugiTransactionException { + var value = nextDateTimeOrNull(); + return (value != null) ? value : defaultValue; + } + + /** + * get current value as dateTime and move next column. + * + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default @Nonnull Optional nextDateTimeOpt() throws IOException, InterruptedException, TsurugiTransactionException { + var value = nextDateTimeOrNull(); + return Optional.ofNullable(value); + } + + /** + * get current value as dateTime and move next column. + * + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default @Nullable LocalDateTime nextDateTimeOrNull() throws IOException, InterruptedException, TsurugiTransactionException { + var value = nextValueOrNull(); + return getConvertUtil().toDateTime(value); + } + + // offset time + + /** + * get current value as offset time and move next column. + * + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + * @throws NullPointerException if value is null + */ + public default @Nonnull OffsetTime nextOffsetTime() throws IOException, InterruptedException, TsurugiTransactionException { + var value = nextOffsetTimeOrNull(); + return Objects.requireNonNull(value, () -> "nextOffsetTime(" + getCurrentColumnIndex() + ") is null"); + } + + /** + * get current value as offset time and move next column. + * + * @param defaultValue value to return if original value is null + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default OffsetTime nextOffsetTime(OffsetTime defaultValue) throws IOException, InterruptedException, TsurugiTransactionException { + var value = nextOffsetTimeOrNull(); + return (value != null) ? value : defaultValue; + } + + /** + * get current value as offset time and move next column. + * + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default @Nonnull Optional nextOffsetTimeOpt() throws IOException, InterruptedException, TsurugiTransactionException { + var value = nextOffsetTimeOrNull(); + return Optional.ofNullable(value); + } + + /** + * get current value as offset time and move next column. + * + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default @Nullable OffsetTime nextOffsetTimeOrNull() throws IOException, InterruptedException, TsurugiTransactionException { + var value = nextValueOrNull(); + return getConvertUtil().toOffsetTime(value); + } + + // offset dateTime + + /** + * get current value as offset dateTime and move next column. + * + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + * @throws NullPointerException if value is null + */ + public default @Nonnull OffsetDateTime nextOffsetDateTime() throws IOException, InterruptedException, TsurugiTransactionException { + var value = nextOffsetDateTimeOrNull(); + return Objects.requireNonNull(value, () -> "nextOffsetDateTime(" + getCurrentColumnIndex() + ") is null"); + } + + /** + * get current value as offset dateTime and move next column. + * + * @param defaultValue value to return if original value is null + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default OffsetDateTime nextOffsetDateTime(OffsetDateTime defaultValue) throws IOException, InterruptedException, TsurugiTransactionException { + var value = nextOffsetDateTimeOrNull(); + return (value != null) ? value : defaultValue; + } + + /** + * get current value as offset dateTime and move next column. + * + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default @Nonnull Optional nextOffsetDateTimeOpt() throws IOException, InterruptedException, TsurugiTransactionException { + var value = nextOffsetDateTimeOrNull(); + return Optional.ofNullable(value); + } + + /** + * get current value as offset dateTime and move next column. + * + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default @Nullable OffsetDateTime nextOffsetDateTimeOrNull() throws IOException, InterruptedException, TsurugiTransactionException { + var value = nextValueOrNull(); + return getConvertUtil().toOffsetDateTime(value); + } + + // zoned dateTime + + /** + * get current value as zoned dateTime and move next column. + * + * @param zone time-zone + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + * @throws NullPointerException if value is null + */ + public default @Nonnull ZonedDateTime nextZonedDateTime(@Nonnull ZoneId zone) throws IOException, InterruptedException, TsurugiTransactionException { + var value = nextZonedDateTimeOrNull(zone); + return Objects.requireNonNull(value, () -> "nextZonedDateTime(" + getCurrentColumnIndex() + ") is null"); + } + + /** + * get current value as zoned dateTime and move next column. + * + * @param zone time-zone + * @param defaultValue value to return if original value is null + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default ZonedDateTime nextZonedDateTime(@Nonnull ZoneId zone, ZonedDateTime defaultValue) throws IOException, InterruptedException, TsurugiTransactionException { + var value = nextZonedDateTimeOrNull(zone); + return (value != null) ? value : defaultValue; + } + + /** + * get current value as zoned dateTime and move next column. + * + * @param zone time-zone + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default @Nonnull Optional nextZonedDateTimeOpt(@Nonnull ZoneId zone) throws IOException, InterruptedException, TsurugiTransactionException { + var value = nextZonedDateTimeOrNull(zone); + return Optional.ofNullable(value); + } + + /** + * get current value as zoned dateTime and move next column. + * + * @param zone time-zone + * @return value + * @throws IOException if an I/O error occurs while retrieving the column data + * @throws InterruptedException if interrupted while retrieving the column data + * @throws TsurugiTransactionException if server error occurs while retrieving the column data + */ + public default @Nullable ZonedDateTime nextZonedDateTimeOrNull(@Nonnull ZoneId zone) throws IOException, InterruptedException, TsurugiTransactionException { + var value = nextValueOrNull(); + return getConvertUtil().toZonedDateTime(value, zone); + } +} diff --git a/modules/iceaxe-core/src/main/java/com/tsurugidb/iceaxe/sql/result/TsurugiResultRecord.java b/modules/iceaxe-core/src/main/java/com/tsurugidb/iceaxe/sql/result/TsurugiResultRecord.java index 0444301e..55406510 100755 --- a/modules/iceaxe-core/src/main/java/com/tsurugidb/iceaxe/sql/result/TsurugiResultRecord.java +++ b/modules/iceaxe-core/src/main/java/com/tsurugidb/iceaxe/sql/result/TsurugiResultRecord.java @@ -1,20 +1,9 @@ package com.tsurugidb.iceaxe.sql.result; import java.io.IOException; -import java.math.BigDecimal; -import java.text.MessageFormat; -import java.time.LocalDate; -import java.time.LocalDateTime; -import java.time.LocalTime; -import java.time.OffsetDateTime; -import java.time.OffsetTime; -import java.time.ZoneId; -import java.time.ZonedDateTime; -import java.util.LinkedHashMap; +import java.util.ArrayList; import java.util.List; -import java.util.Map; import java.util.Objects; -import java.util.Optional; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -24,10 +13,10 @@ import org.slf4j.LoggerFactory; import com.tsurugidb.iceaxe.sql.TgDataType; +import com.tsurugidb.iceaxe.sql.result.IceaxeResultNameList.IceaxeAmbiguousNamePolicy; import com.tsurugidb.iceaxe.transaction.exception.TsurugiTransactionException; import com.tsurugidb.iceaxe.util.IceaxeConvertUtil; -import com.tsurugidb.sql.proto.SqlCommon.AtomType; -import com.tsurugidb.sql.proto.SqlCommon.Column; +import com.tsurugidb.iceaxe.util.IceaxeInternal; import com.tsurugidb.tsubakuro.exception.ServerException; import com.tsurugidb.tsubakuro.sql.ResultSet; @@ -50,9 +39,9 @@ * } * * - *

name group

+ *

name/index group

*

- * Get the value by specifying the column name. + * Get the value by specifying the column name or index. *

* *
@@ -61,6 +50,12 @@
  * entity.setZzz(record.getString("zzz"));
  * 
* + *
+ * entity.setFoo(record.getInt(0));
+ * entity.setBar(record.getLong(1));
+ * entity.setZzz(record.getString(2));
+ * 
+ * *

next group

*

* Move to the next column and get the value of the current column.
@@ -81,51 +76,42 @@ *

*/ @NotThreadSafe -public class TsurugiResultRecord { +public class TsurugiResultRecord implements TsurugiResultIndexRecord, TsurugiResultNameRecord, TsurugiResultNextRecord { private static final Logger LOG = LoggerFactory.getLogger(TsurugiResultRecord.class); + private static IceaxeAmbiguousNamePolicy defaultAmbiguousNamePolicy = IceaxeAmbiguousNamePolicy.FIRST; + /** - * column value. + * set default ambiguous name policy. + * + * @param policy default ambiguous name policy + * @since X.X.X */ - protected /* record */ static class TsurugiResultColumnValue { - private final int index; - private final Object value; - - /** - * Creates a new instance. - * - * @param index column index - * @param value column value - */ - public TsurugiResultColumnValue(int index, Object value) { - this.index = index; - this.value = value; - } - - /** - * get column index. - * - * @return column index - */ - public int index() { - return index; - } + public static void setDefaultAmbiguousNamePolicy(IceaxeAmbiguousNamePolicy policy) { + defaultAmbiguousNamePolicy = Objects.requireNonNull(policy); + } - /** - * get column value. - * - * @return column value - */ - public Object value() { - return value; - } + /** + * get default ambiguous name policy. + * + * @return default ambiguous name policy + * @since X.X.X + */ + public static IceaxeAmbiguousNamePolicy getDefaultAmbiguousNamePolicy() { + return defaultAmbiguousNamePolicy; } private final TsurugiQueryResult ownerResult; private final ResultSet lowResultSet; private final IceaxeConvertUtil convertUtil; + private IceaxeAmbiguousNamePolicy ambiguousNamePolicy = null; + + private IceaxeResultNameList resultNameList = null; + private List typeList = null; + private int currentColumnIndex; - private Map columnMap; + private Object[] values = null; + private boolean isValuesAvailable; /** * Creates a new instance. @@ -143,18 +129,63 @@ protected TsurugiResultRecord(TsurugiQueryResult result, ResultSet lowResultS void reset() { this.currentColumnIndex = -1; - if (this.columnMap != null) { - columnMap.clear(); + this.isValuesAvailable = false; + } + + @Override + public IceaxeConvertUtil getConvertUtil() { + return this.convertUtil; + } + + /** + * get name list. + * + * @return list of column name + * @throws IOException if an I/O error occurs while retrieving metadata + * @throws InterruptedException if interrupted while retrieving metadata + * @throws TsurugiTransactionException if server error occurs while retrieving metadata + */ + public @Nonnull List getNameList() throws IOException, InterruptedException, TsurugiTransactionException { + return getResultNameList().getNameList(); + } + + /** + * get name utility. + * + * @return name utility + * @throws IOException if an I/O error occurs while retrieving metadata + * @throws InterruptedException if interrupted while retrieving metadata + * @throws TsurugiTransactionException if server error occurs while retrieving metadata + * @since X.X.X + */ + @IceaxeInternal + public IceaxeResultNameList getResultNameList() throws IOException, InterruptedException, TsurugiTransactionException { + if (this.resultNameList == null) { + var lowColumnList = TsurugiQueryResult.getLowColumnList(ownerResult, lowResultSet); + this.resultNameList = IceaxeResultNameList.of(lowColumnList); } + return this.resultNameList; } /** - * get convert type utility. + * get data type list. * - * @return convert type utility + * @return list of data type + * @throws IOException if an I/O error occurs while retrieving metadata + * @throws InterruptedException if interrupted while retrieving metadata + * @throws TsurugiTransactionException if server error occurs while retrieving metadata */ - public IceaxeConvertUtil getConvertUtil() { - return this.convertUtil; + protected @Nonnull List getTypeList() throws IOException, InterruptedException, TsurugiTransactionException { + if (this.typeList == null) { + var lowColumnList = TsurugiQueryResult.getLowColumnList(ownerResult, lowResultSet); + var list = new ArrayList(lowColumnList.size()); + for (var lowColumn : lowColumnList) { + var type = TgDataType.of(lowColumn.getAtomType()); + list.add(type); + } + this.typeList = List.copyOf(list); + } + return this.typeList; } /* @@ -188,18 +219,10 @@ public boolean moveCurrentColumnNext() throws IOException, InterruptedException, } } - /** - * get low column. - * - * @param index column index - * @return low column - * @throws IOException if an I/O error occurs while retrieving metadata - * @throws InterruptedException if interrupted while retrieving metadata - * @throws TsurugiTransactionException if server error occurs while retrieving metadata - */ - protected @Nonnull Column getLowColumn(int index) throws IOException, InterruptedException, TsurugiTransactionException { - var lowColumnList = TsurugiQueryResult.getLowColumnList(ownerResult, lowResultSet); - return lowColumnList.get(index); + @IceaxeInternal + @Override + public int getCurrentColumnIndex() { + return this.currentColumnIndex; } /** @@ -212,8 +235,7 @@ public boolean moveCurrentColumnNext() throws IOException, InterruptedException, * @see #moveCurrentColumnNext() */ public @Nonnull String getCurrentColumnName() throws IOException, InterruptedException, TsurugiTransactionException { - var lowColumn = getLowColumn(currentColumnIndex); - return TsurugiQueryResult.getColumnName(lowColumn, currentColumnIndex); + return getNameList().get(currentColumnIndex); } /** @@ -226,21 +248,7 @@ public boolean moveCurrentColumnNext() throws IOException, InterruptedException, * @see #moveCurrentColumnNext() */ public @Nonnull TgDataType getCurrentColumnType() throws IOException, InterruptedException, TsurugiTransactionException { - var lowType = getCurrentColumnLowType(); - return TgDataType.of(lowType); - } - - /** - * get current column low type. - * - * @return low data type - * @throws IOException if an I/O error occurs while retrieving metadata - * @throws InterruptedException if interrupted while retrieving metadata - * @throws TsurugiTransactionException if server error occurs while retrieving metadata - */ - protected @Nonnull AtomType getCurrentColumnLowType() throws IOException, InterruptedException, TsurugiTransactionException { - var lowColumn = getLowColumn(currentColumnIndex); - return lowColumn.getAtomType(); + return getType(currentColumnIndex); } /** @@ -256,7 +264,7 @@ public boolean moveCurrentColumnNext() throws IOException, InterruptedException, if (lowResultSet.isNull()) { return null; } - var lowType = getCurrentColumnLowType(); + var lowType = getCurrentColumnType().getLowDataType(); try { switch (lowType) { case BOOLEAN: @@ -298,1998 +306,157 @@ public boolean moveCurrentColumnNext() throws IOException, InterruptedException, } /* - * get by name + * get by index */ - /** - * get name list. - * - * @return list of column name - * @throws IOException if an I/O error occurs while retrieving metadata - * @throws InterruptedException if interrupted while retrieving metadata - * @throws TsurugiTransactionException if server error occurs while retrieving metadata - */ - public @Nonnull List getNameList() throws IOException, InterruptedException, TsurugiTransactionException { - return TsurugiQueryResult.getNameList(ownerResult, lowResultSet); - } - - /** - * get column value map. - * - * @return column value map - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - */ - protected @Nonnull Map getColumnMap() throws IOException, InterruptedException, TsurugiTransactionException { - if (this.columnMap == null) { - this.columnMap = new LinkedHashMap<>(); - } - if (columnMap.isEmpty()) { - while (moveCurrentColumnNext()) { - var name = getCurrentColumnName(); - var value = fetchCurrentColumnValue(); - var column = new TsurugiResultColumnValue(currentColumnIndex, value); - columnMap.put(name, column); + @Override + public @Nullable Object getValueOrNull(int index) throws IOException, InterruptedException, TsurugiTransactionException { + if (!isValuesAvailable) { + if (this.values == null) { + int size = getResultNameList().size(); + this.values = new Object[size]; } - } - return this.columnMap; - } - /** - * get column value. - * - * @param name column name - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - */ - protected @Nonnull TsurugiResultColumnValue getColumn(String name) throws IOException, InterruptedException, TsurugiTransactionException { - var map = getColumnMap(); - var column = map.get(name); - if (column == null) { - throw new IllegalArgumentException("not found column. name=" + name); + readValues(this.values); + + this.isValuesAvailable = true; } - return column; + return values[index]; } - /** - * get value. - * - * @param name column name - * @return value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - */ - public @Nullable Object getValue(String name) throws IOException, InterruptedException, TsurugiTransactionException { - var column = getColumn(name); - return column.value(); + void readValues(Object[] values) throws IOException, InterruptedException, TsurugiTransactionException { + int i = 0; + while (moveCurrentColumnNext()) { + var value = fetchCurrentColumnValue(); + values[i++] = value; + } + if (i != values.length) { + throw new IllegalStateException(String.format("column size unmatch. readColumn=%d, columnSize=%d", i, values.length)); + } } /** * get data type. * - * @param name column name + * @param index column index * @return data type * @throws IOException if an I/O error occurs while retrieving the column data * @throws InterruptedException if interrupted while retrieving the column data * @throws TsurugiTransactionException if server error occurs while retrieving the column data */ - public @Nonnull TgDataType getType(String name) throws IOException, InterruptedException, TsurugiTransactionException { - var column = getColumn(name); - var lowColumn = getLowColumn(column.index()); - var lowType = lowColumn.getAtomType(); - return TgDataType.of(lowType); - } - - private static void requireNonNull(String name, Object value, String getterName) { - Objects.requireNonNull(value, () -> MessageFormat.format("TsurugiResultRecord.{0}({1}) is null", getterName, name)); - } - - // boolean - - /** - * get column value as boolean. - * - * @param name column name - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - * @throws NullPointerException if value is null - */ - public boolean getBoolean(String name) throws IOException, InterruptedException, TsurugiTransactionException { - var value = getBooleanOrNull(name); - requireNonNull(name, value, "getBoolean"); - return value; + public @Nonnull TgDataType getType(int index) throws IOException, InterruptedException, TsurugiTransactionException { + return getTypeList().get(index); } - /** - * get column value as boolean. - * - * @param name column name - * @param defaultValue value to return if column value is null - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data + /* + * get by name */ - public boolean getBoolean(String name, boolean defaultValue) throws IOException, InterruptedException, TsurugiTransactionException { - var value = getBooleanOrNull(name); - if (value == null) { - return defaultValue; - } - return value; - } /** - * get column value as boolean. + * set ambiguous name policy. * - * @param name column name - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data + * @param policy ambiguous name policy + * @since X.X.X */ - public @Nonnull Optional findBoolean(String name) throws IOException, InterruptedException, TsurugiTransactionException { - var value = getBooleanOrNull(name); - return Optional.ofNullable(value); + public void setAmbiguousNamePolicy(IceaxeAmbiguousNamePolicy policy) { + this.ambiguousNamePolicy = policy; } /** - * get column value as boolean. + * get ambiguous name policy. * - * @param name column name - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data + * @return ambiguous name policy + * @since X.X.X */ - public @Nullable Boolean getBooleanOrNull(String name) throws IOException, InterruptedException, TsurugiTransactionException { - var lowValue = getValue(name); - return convertUtil.toBoolean(lowValue); + public IceaxeAmbiguousNamePolicy getAmbiguousNamePolicy() { + return this.ambiguousNamePolicy; } - // int - /** - * get column value as int. + * get index. * * @param name column name - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - * @throws NullPointerException if value is null - */ - public int getInt(String name) throws IOException, InterruptedException, TsurugiTransactionException { - var value = getIntOrNull(name); - requireNonNull(name, value, "getInt"); - return value; - } - - /** - * get column value as int. - * - * @param name column name - * @param defaultValue value to return if column value is null - * @return column value + * @return column index + * @see #setAmbiguousNamePolicy(IceaxeAmbiguousNamePolicy) * @throws IOException if an I/O error occurs while retrieving the column data * @throws InterruptedException if interrupted while retrieving the column data * @throws TsurugiTransactionException if server error occurs while retrieving the column data + * @since X.X.X */ - public int getInt(String name, int defaultValue) throws IOException, InterruptedException, TsurugiTransactionException { - var value = getIntOrNull(name); - if (value == null) { - return defaultValue; + public int getIndex(String name) throws IOException, InterruptedException, TsurugiTransactionException { + var policy = this.ambiguousNamePolicy; + if (policy == null) { + policy = defaultAmbiguousNamePolicy; } - return value; - } - - /** - * get column value as int. - * - * @param name column name - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - */ - public @Nonnull Optional findInt(String name) throws IOException, InterruptedException, TsurugiTransactionException { - var value = getIntOrNull(name); - return Optional.ofNullable(value); - } - - /** - * get column value as int. - * - * @param name column name - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - */ - public @Nullable Integer getIntOrNull(String name) throws IOException, InterruptedException, TsurugiTransactionException { - var lowValue = getValue(name); - return convertUtil.toInt(lowValue); - } - - // long - - /** - * get column value as long. - * - * @param name column name - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - * @throws NullPointerException if value is null - */ - public long getLong(String name) throws IOException, InterruptedException, TsurugiTransactionException { - var value = getLongOrNull(name); - requireNonNull(name, value, "getLong"); - return value; + return getResultNameList().getIndex(name, policy); } /** - * get column value as long. + * get index. * - * @param name column name - * @param defaultValue value to return if column value is null - * @return column value + * @param name column name + * @param subIndex index for same name + * @return column index * @throws IOException if an I/O error occurs while retrieving the column data * @throws InterruptedException if interrupted while retrieving the column data * @throws TsurugiTransactionException if server error occurs while retrieving the column data + * @since X.X.X */ - public long getLong(String name, long defaultValue) throws IOException, InterruptedException, TsurugiTransactionException { - var value = getLongOrNull(name); - if (value == null) { - return defaultValue; - } - return value; + public int getIndex(String name, int subIndex) throws IOException, InterruptedException, TsurugiTransactionException { + return getResultNameList().getIndex(name, subIndex); } - /** - * get column value as long. - * - * @param name column name - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - */ - public @Nonnull Optional findLong(String name) throws IOException, InterruptedException, TsurugiTransactionException { - var value = getLongOrNull(name); - return Optional.ofNullable(value); + @Override + public @Nullable Object getValueOrNull(String name) throws IOException, InterruptedException, TsurugiTransactionException { + int index = getIndex(name); + return getValueOrNull(index); } /** - * get column value as long. + * get data type. * * @param name column name - * @return column value + * @return data type * @throws IOException if an I/O error occurs while retrieving the column data * @throws InterruptedException if interrupted while retrieving the column data * @throws TsurugiTransactionException if server error occurs while retrieving the column data */ - public @Nullable Long getLongOrNull(String name) throws IOException, InterruptedException, TsurugiTransactionException { - var lowValue = getValue(name); - return convertUtil.toLong(lowValue); + public @Nonnull TgDataType getType(String name) throws IOException, InterruptedException, TsurugiTransactionException { + int index = getIndex(name); + return getType(index); } - // float - - /** - * get column value as float. - * - * @param name column name - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - * @throws NullPointerException if value is null + /* + * next */ - public float getFloat(String name) throws IOException, InterruptedException, TsurugiTransactionException { - var value = getFloatOrNull(name); - requireNonNull(name, value, "getFloat"); - return value; - } /** - * get column value as float. + * move next column. * - * @param name column name - * @param defaultValue value to return if column value is null - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data + * @throws IOException if an I/O error occurs while retrieving the next column data + * @throws InterruptedException if interrupted while retrieving the next column data + * @throws TsurugiTransactionException if server error occurs while retrieving the next column data + * @throws IllegalStateException if not found next column */ - public float getFloat(String name, float defaultValue) throws IOException, InterruptedException, TsurugiTransactionException { - var value = getFloatOrNull(name); - if (value == null) { - return defaultValue; + public void nextColumn() throws IOException, InterruptedException, TsurugiTransactionException { + boolean exists = moveCurrentColumnNext(); + if (!exists) { + throw new IllegalStateException("not found next column"); } - return value; - } - - /** - * get column value as float. - * - * @param name column name - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - */ - public @Nonnull Optional findFloat(String name) throws IOException, InterruptedException, TsurugiTransactionException { - var value = getFloatOrNull(name); - return Optional.ofNullable(value); - } - - /** - * get column value as float. - * - * @param name column name - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - */ - public @Nullable Float getFloatOrNull(String name) throws IOException, InterruptedException, TsurugiTransactionException { - var lowValue = getValue(name); - return convertUtil.toFloat(lowValue); - } - - // double - - /** - * get column value as double. - * - * @param name column name - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - * @throws NullPointerException if value is null - */ - public double getDouble(String name) throws IOException, InterruptedException, TsurugiTransactionException { - var value = getDoubleOrNull(name); - requireNonNull(name, value, "getDouble"); - return value; } /** - * get column value as double. + * get current column value and move next column. * - * @param name column name - * @param defaultValue value to return if column value is null * @return column value * @throws IOException if an I/O error occurs while retrieving the column data * @throws InterruptedException if interrupted while retrieving the column data * @throws TsurugiTransactionException if server error occurs while retrieving the column data */ - public double getDouble(String name, float defaultValue) throws IOException, InterruptedException, TsurugiTransactionException { - var value = getDoubleOrNull(name); - if (value == null) { - return defaultValue; - } - return value; - } - - /** - * get column value as double. - * - * @param name column name - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - */ - public @Nonnull Optional findDouble(String name) throws IOException, InterruptedException, TsurugiTransactionException { - var value = getDoubleOrNull(name); - return Optional.ofNullable(value); - } - - /** - * get column value as double. - * - * @param name column name - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - */ - public @Nullable Double getDoubleOrNull(String name) throws IOException, InterruptedException, TsurugiTransactionException { - var lowValue = getValue(name); - return convertUtil.toDouble(lowValue); - } - - // decimal - - /** - * get column value as decimal. - * - * @param name column name - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - * @throws NullPointerException if value is null - */ - public @Nonnull BigDecimal getDecimal(String name) throws IOException, InterruptedException, TsurugiTransactionException { - var value = getDecimalOrNull(name); - requireNonNull(name, value, "getDecimal"); - return value; - } - - /** - * get column value as decimal. - * - * @param name column name - * @param defaultValue value to return if column value is null - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - */ - public BigDecimal getDecimal(String name, BigDecimal defaultValue) throws IOException, InterruptedException, TsurugiTransactionException { - var value = getDecimalOrNull(name); - if (value == null) { - return defaultValue; - } - return value; - } - - /** - * get column value as decimal. - * - * @param name column name - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - */ - public @Nonnull Optional findDecimal(String name) throws IOException, InterruptedException, TsurugiTransactionException { - var value = getDecimalOrNull(name); - return Optional.ofNullable(value); - } - - /** - * get column value as decimal. - * - * @param name column name - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - */ - public @Nullable BigDecimal getDecimalOrNull(String name) throws IOException, InterruptedException, TsurugiTransactionException { - var lowValue = getValue(name); - return convertUtil.toDecimal(lowValue); - } - - // string - - /** - * get column value as String. - * - * @param name column name - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - * @throws NullPointerException if value is null - */ - public @Nonnull String getString(String name) throws IOException, InterruptedException, TsurugiTransactionException { - var value = getStringOrNull(name); - requireNonNull(name, value, "getString"); - return value; - } - - /** - * get column value as String. - * - * @param name column name - * @param defaultValue value to return if column value is null - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - */ - public String getString(String name, String defaultValue) throws IOException, InterruptedException, TsurugiTransactionException { - var value = getStringOrNull(name); - if (value == null) { - return defaultValue; - } - return value; - } - - /** - * get column value as String. - * - * @param name column name - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - */ - public @Nonnull Optional findString(String name) throws IOException, InterruptedException, TsurugiTransactionException { - var value = getStringOrNull(name); - return Optional.ofNullable(value); - } - - /** - * get column value as String. - * - * @param name column name - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - */ - public @Nullable String getStringOrNull(String name) throws IOException, InterruptedException, TsurugiTransactionException { - var lowValue = getValue(name); - return convertUtil.toString(lowValue); - } - - // byte[] - - /** - * get column value as byte[]. - * - * @param name column name - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - * @throws NullPointerException if value is null - */ - public @Nonnull byte[] getBytes(String name) throws IOException, InterruptedException, TsurugiTransactionException { - var value = getBytesOrNull(name); - requireNonNull(name, value, "getBytes"); - return value; - } - - /** - * get column value as byte[]. - * - * @param name column name - * @param defaultValue value to return if column value is null - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - */ - public byte[] getBytes(String name, byte[] defaultValue) throws IOException, InterruptedException, TsurugiTransactionException { - var value = getBytesOrNull(name); - if (value == null) { - return defaultValue; - } - return value; - } - - /** - * get column value as byte[]. - * - * @param name column name - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - */ - public @Nonnull Optional findBytes(String name) throws IOException, InterruptedException, TsurugiTransactionException { - var value = getBytesOrNull(name); - return Optional.ofNullable(value); - } - - /** - * get column value as byte[]. - * - * @param name column name - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - */ - public @Nullable byte[] getBytesOrNull(String name) throws IOException, InterruptedException, TsurugiTransactionException { - var lowValue = getValue(name); - return convertUtil.toBytes(lowValue); - } - - // boolean[] - - /** - * get column value as boolean[]. - * - * @param name column name - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - * @throws NullPointerException if value is null - */ - public @Nonnull boolean[] getBits(String name) throws IOException, InterruptedException, TsurugiTransactionException { - var value = getBitsOrNull(name); - requireNonNull(name, value, "getBits"); - return value; - } - - /** - * get column value as boolean[]. - * - * @param name column name - * @param defaultValue value to return if column value is null - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - */ - public boolean[] getBits(String name, boolean[] defaultValue) throws IOException, InterruptedException, TsurugiTransactionException { - var value = getBitsOrNull(name); - if (value == null) { - return defaultValue; - } - return value; - } - - /** - * get column value as boolean[]. - * - * @param name column name - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - */ - public @Nonnull Optional findBits(String name) throws IOException, InterruptedException, TsurugiTransactionException { - var value = getBitsOrNull(name); - return Optional.ofNullable(value); - } - - /** - * get column value as boolean[]. - * - * @param name column name - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - */ - public @Nullable boolean[] getBitsOrNull(String name) throws IOException, InterruptedException, TsurugiTransactionException { - var lowValue = getValue(name); - return convertUtil.toBits(lowValue); - } - - // date - - /** - * get column value as date. - * - * @param name column name - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - * @throws NullPointerException if value is null - */ - public @Nonnull LocalDate getDate(String name) throws IOException, InterruptedException, TsurugiTransactionException { - var value = getDateOrNull(name); - requireNonNull(name, value, "getDate"); - return value; - } - - /** - * get column value as date. - * - * @param name column name - * @param defaultValue value to return if column value is null - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - */ - public LocalDate getDate(String name, LocalDate defaultValue) throws IOException, InterruptedException, TsurugiTransactionException { - var value = getDateOrNull(name); - if (value == null) { - return defaultValue; - } - return value; - } - - /** - * get column value as date. - * - * @param name column name - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - */ - public @Nonnull Optional findDate(String name) throws IOException, InterruptedException, TsurugiTransactionException { - var value = getDateOrNull(name); - return Optional.ofNullable(value); - } - - /** - * get column value as date. - * - * @param name column name - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - */ - public @Nullable LocalDate getDateOrNull(String name) throws IOException, InterruptedException, TsurugiTransactionException { - var lowValue = getValue(name); - return convertUtil.toDate(lowValue); - } - - // time - - /** - * get column value as time. - * - * @param name column name - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - * @throws NullPointerException if value is null - */ - public @Nonnull LocalTime getTime(String name) throws IOException, InterruptedException, TsurugiTransactionException { - var value = getTimeOrNull(name); - requireNonNull(name, value, "getTime"); - return value; - } - - /** - * get column value as time. - * - * @param name column name - * @param defaultValue value to return if column value is null - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - */ - public LocalTime getTime(String name, LocalTime defaultValue) throws IOException, InterruptedException, TsurugiTransactionException { - var value = getTimeOrNull(name); - if (value == null) { - return defaultValue; - } - return value; - } - - /** - * get column value as time. - * - * @param name column name - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - */ - public @Nonnull Optional findTime(String name) throws IOException, InterruptedException, TsurugiTransactionException { - var value = getTimeOrNull(name); - return Optional.ofNullable(value); - } - - /** - * get column value as time. - * - * @param name column name - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - */ - public @Nullable LocalTime getTimeOrNull(String name) throws IOException, InterruptedException, TsurugiTransactionException { - var lowValue = getValue(name); - return convertUtil.toTime(lowValue); - } - - // date time - - /** - * get column value as dateTime. - * - * @param name column name - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - * @throws NullPointerException if value is null - */ - public @Nonnull LocalDateTime getDateTime(String name) throws IOException, InterruptedException, TsurugiTransactionException { - var value = getDateTimeOrNull(name); - requireNonNull(name, value, "getDateTime"); - return value; - } - - /** - * get column value as dateTime. - * - * @param name column name - * @param defaultValue value to return if column value is null - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - */ - public LocalDateTime getDateTime(String name, LocalDateTime defaultValue) throws IOException, InterruptedException, TsurugiTransactionException { - var value = getDateTimeOrNull(name); - if (value == null) { - return defaultValue; - } - return value; - } - - /** - * get column value as dateTime. - * - * @param name column name - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - */ - public @Nonnull Optional findDateTime(String name) throws IOException, InterruptedException, TsurugiTransactionException { - var value = getDateTimeOrNull(name); - return Optional.ofNullable(value); - } - - /** - * get column value as dateTime. - * - * @param name column name - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - */ - public @Nullable LocalDateTime getDateTimeOrNull(String name) throws IOException, InterruptedException, TsurugiTransactionException { - var lowValue = getValue(name); - return convertUtil.toDateTime(lowValue); - } - - // offset time - - /** - * get column value as offset time. - * - * @param name column name - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - * @throws NullPointerException if value is null - */ - public @Nonnull OffsetTime getOffsetTime(String name) throws IOException, InterruptedException, TsurugiTransactionException { - var value = getOffsetTimeOrNull(name); - requireNonNull(name, value, "getOffsetTime"); - return value; - } - - /** - * get column value as offset time. - * - * @param name column name - * @param defaultValue value to return if column value is null - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - */ - public OffsetTime getOffsetTime(String name, OffsetTime defaultValue) throws IOException, InterruptedException, TsurugiTransactionException { - var value = getOffsetTimeOrNull(name); - if (value == null) { - return defaultValue; - } - return value; - } - - /** - * get column value as offset time. - * - * @param name column name - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - */ - public @Nonnull Optional findOffsetTime(String name) throws IOException, InterruptedException, TsurugiTransactionException { - var value = getOffsetTimeOrNull(name); - return Optional.ofNullable(value); - } - - /** - * get column value as offset time. - * - * @param name column name - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - */ - public @Nullable OffsetTime getOffsetTimeOrNull(String name) throws IOException, InterruptedException, TsurugiTransactionException { - var lowValue = getValue(name); - return convertUtil.toOffsetTime(lowValue); - } - - // offset dateTime - - /** - * get column value as offset dateTime. - * - * @param name column name - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - * @throws NullPointerException if value is null - */ - public @Nonnull OffsetDateTime getOffsetDateTime(String name) throws IOException, InterruptedException, TsurugiTransactionException { - var value = getOffsetDateTimeOrNull(name); - requireNonNull(name, value, "getOffsetDateTime"); - return value; - } - - /** - * get column value as offset dateTime. - * - * @param name column name - * @param defaultValue value to return if column value is null - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - */ - public OffsetDateTime getOffsetDateTime(String name, OffsetDateTime defaultValue) throws IOException, InterruptedException, TsurugiTransactionException { - var value = getOffsetDateTimeOrNull(name); - if (value == null) { - return defaultValue; - } - return value; - } - - /** - * get column value as offset dateTime. - * - * @param name column name - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - */ - public @Nonnull Optional findOffsetDateTime(String name) throws IOException, InterruptedException, TsurugiTransactionException { - var value = getOffsetDateTimeOrNull(name); - return Optional.ofNullable(value); - } - - /** - * get column value as offset dateTime. - * - * @param name column name - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - */ - public @Nullable OffsetDateTime getOffsetDateTimeOrNull(String name) throws IOException, InterruptedException, TsurugiTransactionException { - var lowValue = getValue(name); - return convertUtil.toOffsetDateTime(lowValue); - } - - // zoned dateTime - - /** - * get column value as ZonedDateTime. - * - * @param name column name - * @param zone time-zone - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - * @throws NullPointerException if value is null - */ - public @Nonnull ZonedDateTime getZonedDateTime(String name, ZoneId zone) throws IOException, InterruptedException, TsurugiTransactionException { - var value = getZonedDateTimeOrNull(name, zone); - requireNonNull(name, value, "getZonedDateTime"); - return value; - } - - /** - * get column value as ZonedDateTime. - * - * @param name column name - * @param zone time-zone - * @param defaultValue value to return if column value is null - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - */ - public ZonedDateTime getZonedDateTime(String name, ZoneId zone, ZonedDateTime defaultValue) throws IOException, InterruptedException, TsurugiTransactionException { - var value = getZonedDateTimeOrNull(name, zone); - if (value == null) { - return defaultValue; - } - return value; - } - - /** - * get column value as ZonedDateTime. - * - * @param name column name - * @param zone time-zone - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - */ - public @Nonnull Optional findZonedDateTime(String name, ZoneId zone) throws IOException, InterruptedException, TsurugiTransactionException { - var value = getZonedDateTimeOrNull(name, zone); - return Optional.ofNullable(value); - } - - /** - * get column value as ZonedDateTime. - * - * @param name column name - * @param zone time-zone - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - */ - public @Nullable ZonedDateTime getZonedDateTimeOrNull(String name, ZoneId zone) throws IOException, InterruptedException, TsurugiTransactionException { - var lowValue = getValue(name); - return convertUtil.toZonedDateTime(lowValue, zone); - } - - /* - * next - */ - - /** - * move next column. - * - * @throws IOException if an I/O error occurs while retrieving the next column data - * @throws InterruptedException if interrupted while retrieving the next column data - * @throws TsurugiTransactionException if server error occurs while retrieving the next column data - * @throws IllegalStateException if not found next column - */ - public void nextColumn() throws IOException, InterruptedException, TsurugiTransactionException { - boolean exists = moveCurrentColumnNext(); - if (!exists) { - throw new IllegalStateException("not found next column"); - } - } - - /** - * get current column value and move next column. - * - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - */ - protected @Nullable Object nextLowValue() throws IOException, InterruptedException, TsurugiTransactionException { - nextColumn(); - return fetchCurrentColumnValue(); - } - - private void requireNonNull(Object value, String getterName) { - Objects.requireNonNull(value, () -> MessageFormat.format("TsurugiResultRecord.{0}({1}) is null", getterName, currentColumnIndex)); - } - - // boolean - - /** - * get current column value as boolean and move next column. - * - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - * @throws NullPointerException if value is null - */ - public boolean nextBoolean() throws IOException, InterruptedException, TsurugiTransactionException { - var value = nextBooleanOrNull(); - requireNonNull(value, "nextBoolean"); - return value; - } - - /** - * get current column value as boolean and move next column. - * - * @param defaultValue value to return if column value is null - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - */ - public boolean nextBoolean(boolean defaultValue) throws IOException, InterruptedException, TsurugiTransactionException { - var value = nextBooleanOrNull(); - if (value == null) { - return defaultValue; - } - return value; - } - - /** - * get current column value as boolean and move next column. - * - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - */ - public @Nonnull Optional nextBooleanOpt() throws IOException, InterruptedException, TsurugiTransactionException { - var value = nextBooleanOrNull(); - return Optional.ofNullable(value); - } - - /** - * get current column value as boolean and move next column. - * - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - */ - public @Nullable Boolean nextBooleanOrNull() throws IOException, InterruptedException, TsurugiTransactionException { - var lowValue = nextLowValue(); - return convertUtil.toBoolean(lowValue); - } - - // int - - /** - * get current column value as int and move next column. - * - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - * @throws NullPointerException if value is null - */ - public int nextInt() throws IOException, InterruptedException, TsurugiTransactionException { - var value = nextIntOrNull(); - requireNonNull(value, "nextInt"); - return value; - } - - /** - * get current column value as int and move next column. - * - * @param defaultValue value to return if column value is null - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - */ - public int nextInt(int defaultValue) throws IOException, InterruptedException, TsurugiTransactionException { - var value = nextIntOrNull(); - if (value == null) { - return defaultValue; - } - return value; - } - - /** - * get current column value as int and move next column. - * - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - */ - public @Nonnull Optional nextIntOpt() throws IOException, InterruptedException, TsurugiTransactionException { - var value = nextIntOrNull(); - return Optional.ofNullable(value); - } - - /** - * get current column value as int and move next column. - * - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - */ - public @Nullable Integer nextIntOrNull() throws IOException, InterruptedException, TsurugiTransactionException { - var lowValue = nextLowValue(); - return convertUtil.toInt(lowValue); - } - - // long - - /** - * get current column value as long and move next column. - * - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - * @throws NullPointerException if value is null - */ - public long nextLong() throws IOException, InterruptedException, TsurugiTransactionException { - var value = nextLongOrNull(); - requireNonNull(value, "nextLong"); - return value; - } - - /** - * get current column value as long and move next column. - * - * @param defaultValue value to return if column value is null - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - */ - public long nextLong(long defaultValue) throws IOException, InterruptedException, TsurugiTransactionException { - var value = nextLongOrNull(); - if (value == null) { - return defaultValue; - } - return value; - } - - /** - * get current column value as long and move next column. - * - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - */ - public @Nonnull Optional nextLongOpt() throws IOException, InterruptedException, TsurugiTransactionException { - var value = nextLongOrNull(); - return Optional.ofNullable(value); - } - - /** - * get current column value as long and move next column. - * - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - */ - public @Nullable Long nextLongOrNull() throws IOException, InterruptedException, TsurugiTransactionException { - var lowValue = nextLowValue(); - return convertUtil.toLong(lowValue); - } - - // float - - /** - * get current column value as float and move next column. - * - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - * @throws NullPointerException if value is null - */ - public float nextFloat() throws IOException, InterruptedException, TsurugiTransactionException { - var value = nextFloatOrNull(); - requireNonNull(value, "nextFloat"); - return value; - } - - /** - * get current column value as float and move next column. - * - * @param defaultValue value to return if column value is null - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - */ - public float nextFloat(int defaultValue) throws IOException, InterruptedException, TsurugiTransactionException { - var value = nextFloatOrNull(); - if (value == null) { - return defaultValue; - } - return value; - } - - /** - * get current column value as float and move next column. - * - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - */ - public @Nonnull Optional nextFloatOpt() throws IOException, InterruptedException, TsurugiTransactionException { - var value = nextFloatOrNull(); - return Optional.ofNullable(value); - } - - /** - * get current column value as float and move next column. - * - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - */ - public @Nullable Float nextFloatOrNull() throws IOException, InterruptedException, TsurugiTransactionException { - var lowValue = nextLowValue(); - return convertUtil.toFloat(lowValue); - } - - // double - - /** - * get current column value as double and move next column. - * - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - * @throws NullPointerException if value is null - */ - public double nextDouble() throws IOException, InterruptedException, TsurugiTransactionException { - var value = nextDoubleOrNull(); - requireNonNull(value, "nextDouble"); - return value; - } - - /** - * get current column value as double and move next column. - * - * @param defaultValue value to return if column value is null - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - */ - public double nextDouble(int defaultValue) throws IOException, InterruptedException, TsurugiTransactionException { - var value = nextDoubleOrNull(); - if (value == null) { - return defaultValue; - } - return value; - } - - /** - * get current column value as double and move next column. - * - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - */ - public @Nonnull Optional nextDoubleOpt() throws IOException, InterruptedException, TsurugiTransactionException { - var value = nextDoubleOrNull(); - return Optional.ofNullable(value); - } - - /** - * get current column value as double and move next column. - * - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - */ - public @Nullable Double nextDoubleOrNull() throws IOException, InterruptedException, TsurugiTransactionException { - var lowValue = nextLowValue(); - return convertUtil.toDouble(lowValue); - } - - // decimal - - /** - * get current column value as decimal and move next column. - * - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - * @throws NullPointerException if value is null - */ - public @Nonnull BigDecimal nextDecimal() throws IOException, InterruptedException, TsurugiTransactionException { - var value = nextDecimalOrNull(); - requireNonNull(value, "nextDecimal"); - return value; - } - - /** - * get current column value as decimal and move next column. - * - * @param defaultValue value to return if column value is null - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - */ - public BigDecimal nextDecimal(BigDecimal defaultValue) throws IOException, InterruptedException, TsurugiTransactionException { - var value = nextDecimalOrNull(); - if (value == null) { - return defaultValue; - } - return value; - } - - /** - * get current column value as decimal and move next column. - * - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - */ - public @Nonnull Optional nextDecimalOpt() throws IOException, InterruptedException, TsurugiTransactionException { - var value = nextDecimalOrNull(); - return Optional.ofNullable(value); - } - - /** - * get current column value as decimal and move next column. - * - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - */ - public @Nullable BigDecimal nextDecimalOrNull() throws IOException, InterruptedException, TsurugiTransactionException { - var lowValue = nextLowValue(); - return convertUtil.toDecimal(lowValue); - } - - // string - - /** - * get current column value as String and move next column. - * - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - * @throws NullPointerException if value is null - */ - public @Nonnull String nextString() throws IOException, InterruptedException, TsurugiTransactionException { - var value = nextStringOrNull(); - requireNonNull(value, "nextString"); - return value; - } - - /** - * get current column value as String and move next column. - * - * @param defaultValue value to return if column value is null - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - */ - public String nextString(String defaultValue) throws IOException, InterruptedException, TsurugiTransactionException { - var value = nextStringOrNull(); - if (value == null) { - return defaultValue; - } - return value; - } - - /** - * get current column value as String and move next column. - * - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - */ - public @Nonnull Optional nextStringOpt() throws IOException, InterruptedException, TsurugiTransactionException { - var value = nextStringOrNull(); - return Optional.ofNullable(value); - } - - /** - * get current column value as String and move next column. - * - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - */ - public @Nullable String nextStringOrNull() throws IOException, InterruptedException, TsurugiTransactionException { - var lowValue = nextLowValue(); - return convertUtil.toString(lowValue); - } - - // byte[] - - /** - * get current column value as byte[] and move next column. - * - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - * @throws NullPointerException if value is null - */ - public @Nonnull byte[] nextBytes() throws IOException, InterruptedException, TsurugiTransactionException { - var value = nextBytesOrNull(); - requireNonNull(value, "nextBytes"); - return value; - } - - /** - * get current column value as byte[] and move next column. - * - * @param defaultValue value to return if column value is null - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - */ - public byte[] nextBytes(byte[] defaultValue) throws IOException, InterruptedException, TsurugiTransactionException { - var value = nextBytesOrNull(); - if (value == null) { - return defaultValue; - } - return value; - } - - /** - * get current column value as byte[] and move next column. - * - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - */ - public @Nonnull Optional nextBytesOpt() throws IOException, InterruptedException, TsurugiTransactionException { - var value = nextBytesOrNull(); - return Optional.ofNullable(value); - } - - /** - * get current column value as byte[] and move next column. - * - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - */ - public @Nullable byte[] nextBytesOrNull() throws IOException, InterruptedException, TsurugiTransactionException { - var lowValue = nextLowValue(); - return convertUtil.toBytes(lowValue); - } - - // boolean[] - - /** - * get current column value as boolean[] and move next column. - * - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - * @throws NullPointerException if value is null - */ - public @Nonnull boolean[] nextBits() throws IOException, InterruptedException, TsurugiTransactionException { - var value = nextBitsOrNull(); - requireNonNull(value, "nextBits"); - return value; - } - - /** - * get current column value as boolean[] and move next column. - * - * @param defaultValue value to return if column value is null - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - */ - public boolean[] nextBits(boolean[] defaultValue) throws IOException, InterruptedException, TsurugiTransactionException { - var value = nextBitsOrNull(); - if (value == null) { - return defaultValue; - } - return value; - } - - /** - * get current column value as boolean[] and move next column. - * - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - */ - public @Nonnull Optional nextBitsOpt() throws IOException, InterruptedException, TsurugiTransactionException { - var value = nextBitsOrNull(); - return Optional.ofNullable(value); - } - - /** - * get current column value as boolean[] and move next column. - * - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - */ - public @Nullable boolean[] nextBitsOrNull() throws IOException, InterruptedException, TsurugiTransactionException { - var lowValue = nextLowValue(); - return convertUtil.toBits(lowValue); - } - - // date - - /** - * get current column value as date and move next column. - * - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - * @throws NullPointerException if value is null - */ - public @Nonnull LocalDate nextDate() throws IOException, InterruptedException, TsurugiTransactionException { - var value = nextDateOrNull(); - requireNonNull(value, "nextDate"); - return value; - } - - /** - * get current column value as date and move next column. - * - * @param defaultValue value to return if column value is null - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - */ - public LocalDate nextDate(LocalDate defaultValue) throws IOException, InterruptedException, TsurugiTransactionException { - var value = nextDateOrNull(); - if (value == null) { - return defaultValue; - } - return value; - } - - /** - * get current column value as date and move next column. - * - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - */ - public @Nonnull Optional nextDateOpt() throws IOException, InterruptedException, TsurugiTransactionException { - var value = nextDateOrNull(); - return Optional.ofNullable(value); - } - - /** - * get current column value as date and move next column. - * - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - */ - public @Nullable LocalDate nextDateOrNull() throws IOException, InterruptedException, TsurugiTransactionException { - var lowValue = nextLowValue(); - return convertUtil.toDate(lowValue); - } - - // time - - /** - * get current column value as time and move next column. - * - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - * @throws NullPointerException if value is null - */ - public @Nonnull LocalTime nextTime() throws IOException, InterruptedException, TsurugiTransactionException { - var value = nextTimeOrNull(); - requireNonNull(value, "nextTime"); - return value; - } - - /** - * get current column value as time and move next column. - * - * @param defaultValue value to return if column value is null - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - */ - public LocalTime nextTime(LocalTime defaultValue) throws IOException, InterruptedException, TsurugiTransactionException { - var value = nextTimeOrNull(); - if (value == null) { - return defaultValue; - } - return value; - } - - /** - * get current column value as time and move next column. - * - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - */ - public @Nonnull Optional nextTimeOpt() throws IOException, InterruptedException, TsurugiTransactionException { - var value = nextTimeOrNull(); - return Optional.ofNullable(value); - } - - /** - * get current column value as time and move next column. - * - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - */ - public @Nullable LocalTime nextTimeOrNull() throws IOException, InterruptedException, TsurugiTransactionException { - var lowValue = nextLowValue(); - return convertUtil.toTime(lowValue); - } - - // dateTime - - /** - * get current column value as dateTime and move next column. - * - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - * @throws NullPointerException if value is null - */ - public @Nonnull LocalDateTime nextDateTime() throws IOException, InterruptedException, TsurugiTransactionException { - var value = nextDateTimeOrNull(); - requireNonNull(value, "nextDateTime"); - return value; - } - - /** - * get current column value as dateTime and move next column. - * - * @param defaultValue value to return if column value is null - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - */ - public LocalDateTime nextDateTime(LocalDateTime defaultValue) throws IOException, InterruptedException, TsurugiTransactionException { - var value = nextDateTimeOrNull(); - if (value == null) { - return defaultValue; - } - return value; - } - - /** - * get current column value as dateTime and move next column. - * - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - */ - public @Nonnull Optional nextDateTimeOpt() throws IOException, InterruptedException, TsurugiTransactionException { - var value = nextDateTimeOrNull(); - return Optional.ofNullable(value); - } - - /** - * get current column value as dateTime and move next column. - * - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - */ - public @Nullable LocalDateTime nextDateTimeOrNull() throws IOException, InterruptedException, TsurugiTransactionException { - var lowValue = nextLowValue(); - return convertUtil.toDateTime(lowValue); - } - - // offset time - - /** - * get current column value as offset time and move next column. - * - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - * @throws NullPointerException if value is null - */ - public @Nonnull OffsetTime nextOffsetTime() throws IOException, InterruptedException, TsurugiTransactionException { - var value = nextOffsetTimeOrNull(); - requireNonNull(value, "nextOffsetTime"); - return value; - } - - /** - * get current column value as offset time and move next column. - * - * @param defaultValue value to return if column value is null - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - */ - public OffsetTime nextOffsetTime(OffsetTime defaultValue) throws IOException, InterruptedException, TsurugiTransactionException { - var value = nextOffsetTimeOrNull(); - if (value == null) { - return defaultValue; - } - return value; - } - - /** - * get current column value as offset time and move next column. - * - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - */ - public @Nonnull Optional nextOffsetTimeOpt() throws IOException, InterruptedException, TsurugiTransactionException { - var value = nextOffsetTimeOrNull(); - return Optional.ofNullable(value); - } - - /** - * get current column value as offset time and move next column. - * - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - */ - public @Nullable OffsetTime nextOffsetTimeOrNull() throws IOException, InterruptedException, TsurugiTransactionException { - var lowValue = nextLowValue(); - return convertUtil.toOffsetTime(lowValue); - } - - // offset dateTime - - /** - * get current column value as offset dateTime and move next column. - * - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - * @throws NullPointerException if value is null - */ - public @Nonnull OffsetDateTime nextOffsetDateTime() throws IOException, InterruptedException, TsurugiTransactionException { - var value = nextOffsetDateTimeOrNull(); - requireNonNull(value, "nextOffsetDateTime"); - return value; - } - - /** - * get current column value as offset dateTime and move next column. - * - * @param defaultValue value to return if column value is null - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - */ - public OffsetDateTime nextOffsetDateTime(OffsetDateTime defaultValue) throws IOException, InterruptedException, TsurugiTransactionException { - var value = nextOffsetDateTimeOrNull(); - if (value == null) { - return defaultValue; - } - return value; - } - - /** - * get current column value as offset dateTime and move next column. - * - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - */ - public @Nonnull Optional nextOffsetDateTimeOpt() throws IOException, InterruptedException, TsurugiTransactionException { - var value = nextOffsetDateTimeOrNull(); - return Optional.ofNullable(value); - } - - /** - * get current column value as offset dateTime and move next column. - * - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - */ - public @Nullable OffsetDateTime nextOffsetDateTimeOrNull() throws IOException, InterruptedException, TsurugiTransactionException { - var lowValue = nextLowValue(); - return convertUtil.toOffsetDateTime(lowValue); - } - - // zoned dateTime - - /** - * get current column value as ZonedDateTime and move next column. - * - * @param zone time-zone - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - * @throws NullPointerException if value is null - */ - public @Nonnull ZonedDateTime nextZonedDateTime(@Nonnull ZoneId zone) throws IOException, InterruptedException, TsurugiTransactionException { - var value = nextZonedDateTimeOrNull(zone); - requireNonNull(value, "nextZonedDateTime"); - return value; - } - - /** - * get current column value as ZonedDateTime and move next column. - * - * @param zone time-zone - * @param defaultValue value to return if column value is null - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - */ - public ZonedDateTime nextZonedDateTime(@Nonnull ZoneId zone, ZonedDateTime defaultValue) throws IOException, InterruptedException, TsurugiTransactionException { - var value = nextZonedDateTimeOrNull(zone); - if (value == null) { - return defaultValue; - } - return value; - } - - /** - * get current column value as ZonedDateTime and move next column. - * - * @param zone time-zone - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - */ - public @Nonnull Optional nextZonedDateTimeOpt(@Nonnull ZoneId zone) throws IOException, InterruptedException, TsurugiTransactionException { - var value = nextZonedDateTimeOrNull(zone); - return Optional.ofNullable(value); - } - - /** - * get current column value as ZonedDateTime and move next column. - * - * @param zone time-zone - * @return column value - * @throws IOException if an I/O error occurs while retrieving the column data - * @throws InterruptedException if interrupted while retrieving the column data - * @throws TsurugiTransactionException if server error occurs while retrieving the column data - */ - public @Nullable ZonedDateTime nextZonedDateTimeOrNull(@Nonnull ZoneId zone) throws IOException, InterruptedException, TsurugiTransactionException { - var lowValue = nextLowValue(); - return convertUtil.toZonedDateTime(lowValue, zone); + @Override + public @Nullable Object nextValueOrNull() throws IOException, InterruptedException, TsurugiTransactionException { + nextColumn(); + return fetchCurrentColumnValue(); } @Override diff --git a/modules/iceaxe-core/src/main/java/com/tsurugidb/iceaxe/sql/result/mapping/TgEntityResultMapping.java b/modules/iceaxe-core/src/main/java/com/tsurugidb/iceaxe/sql/result/mapping/TgEntityResultMapping.java index 13d370c7..de45a3e1 100755 --- a/modules/iceaxe-core/src/main/java/com/tsurugidb/iceaxe/sql/result/mapping/TgEntityResultMapping.java +++ b/modules/iceaxe-core/src/main/java/com/tsurugidb/iceaxe/sql/result/mapping/TgEntityResultMapping.java @@ -46,7 +46,26 @@ public static TgEntityResultMapping of(Supplier entitySupplier) { private Supplier entitySupplier; private final List> columnConverterList = new ArrayList<>(); - private Map> columnConverterMap; + + private static /* record */ class NameConverter { + private final String name; + private final TsurugiTransactionBiConsumer converter; + + public NameConverter(String name, TsurugiTransactionBiConsumer converter) { + this.name = name; + this.converter = converter; + } + + public String name() { + return this.name; + } + + public TsurugiTransactionBiConsumer converter() { + return this.converter; + } + } + + private List> nameConverterList = null; /** * Tsurugi Result Mapping. @@ -1409,16 +1428,18 @@ protected void set(String name, TsurugiTransactionFunction converter) { - if (this.columnConverterMap == null) { - this.columnConverterMap = new HashMap<>(); + if (this.nameConverterList == null) { + this.nameConverterList = new ArrayList<>(); } - columnConverterMap.put(name, converter); + + var entry = new NameConverter<>(name, converter); + nameConverterList.add(entry); } // @ThreadSafe @Override protected R convert(TsurugiResultRecord record) throws IOException, InterruptedException, TsurugiTransactionException { - mergeColumnConverterMap(record); + mergeNameConverterList(record); R entity = entitySupplier.get(); for (var converter : columnConverterList) { @@ -1432,25 +1453,29 @@ protected R convert(TsurugiResultRecord record) throws IOException, InterruptedE } /** - * merge record to columnConverterMap. + * merge nameConverterList. * * @param record record * @throws IOException if an I/O error occurs while retrieving metadata * @throws InterruptedException if interrupted while retrieving metadata * @throws TsurugiTransactionException if server error occurs while retrieving metadata */ - protected synchronized void mergeColumnConverterMap(TsurugiResultRecord record) throws IOException, InterruptedException, TsurugiTransactionException { - if (this.columnConverterMap != null) { - var nameList = record.getNameList(); - int i = 0; - for (var name : nameList) { - var converter = columnConverterMap.get(name); - if (converter != null) { - set(i, converter); - } - i++; + protected synchronized void mergeNameConverterList(TsurugiResultRecord record) throws IOException, InterruptedException, TsurugiTransactionException { + if (this.nameConverterList != null) { + var nameList = record.getResultNameList(); + + var countMap = new HashMap(nameList.size()); + for (var entry : nameConverterList) { + String name = entry.name(); + int[] counter = countMap.computeIfAbsent(name, k -> new int[] { 0 }); + int subIndex = counter[0]++; + int index = nameList.getIndex(name, subIndex); + + var converter = entry.converter(); + set(index, converter); } - this.columnConverterMap = null; + + this.nameConverterList = null; } } } diff --git a/modules/iceaxe-core/src/test/java/com/tsurugidb/iceaxe/sql/result/IceaxeResultNameListTest.java b/modules/iceaxe-core/src/test/java/com/tsurugidb/iceaxe/sql/result/IceaxeResultNameListTest.java new file mode 100755 index 00000000..6624874f --- /dev/null +++ b/modules/iceaxe-core/src/test/java/com/tsurugidb/iceaxe/sql/result/IceaxeResultNameListTest.java @@ -0,0 +1,178 @@ +package com.tsurugidb.iceaxe.sql.result; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; +import java.util.concurrent.atomic.AtomicBoolean; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; + +import com.tsurugidb.iceaxe.sql.result.IceaxeResultNameList.IceaxeAmbiguousNamePolicy; +import com.tsurugidb.sql.proto.SqlCommon.AtomType; +import com.tsurugidb.sql.proto.SqlCommon.Column; + +class IceaxeResultNameListTest { + + @Test + void of() { + var lowColumnList = List.of(column("foo", AtomType.INT4), column("bar", AtomType.INT8), column("zzz", AtomType.CHARACTER)); + var actual = IceaxeResultNameList.of(lowColumnList); + + assertEquals(lowColumnList.size(), actual.size()); + assertEquals(List.of("foo", "bar", "zzz"), actual.getNameList()); + assertEquals("foo", actual.getName(0)); + assertEquals("bar", actual.getName(1)); + assertEquals("zzz", actual.getName(2)); + assertEquals(0, actual.getIndex("foo", IceaxeAmbiguousNamePolicy.ERROR)); + assertEquals(1, actual.getIndex("bar", IceaxeAmbiguousNamePolicy.ERROR)); + assertEquals(2, actual.getIndex("zzz", IceaxeAmbiguousNamePolicy.ERROR)); + } + + @ParameterizedTest + @ValueSource(ints = { 0, 1, 2, 3, 4, 5, 6, 7 }) + void toNameList(int pattern) { + var name = new String[3]; + name[0] = ((pattern & 0b001) == 0) ? "" : "foo"; + name[1] = ((pattern & 0b010) == 0) ? "" : "bar"; + name[2] = ((pattern & 0b100) == 0) ? "" : "zzz"; + var lowColumnList = List.of(column(name[0], AtomType.INT4), column(name[1], AtomType.INT8), column(name[2], AtomType.CHARACTER)); + var nameList = IceaxeResultNameList.toNameList(lowColumnList); + + assertEquals(name.length, nameList.size()); + for (int i = 0; i < name.length; i++) { + assertEquals(name[i].isEmpty() ? "@#" + i : name[i], nameList.get(i)); + } + } + + @ParameterizedTest + @ValueSource(strings = { "ERROR", "FIRST", "LAST" }) + void getIndexPolicy(String policy0) { + var policy = IceaxeAmbiguousNamePolicy.valueOf(policy0); + + var lowColumnList = List.of( // + column("foo", AtomType.INT4), column("bar", AtomType.INT8), column("zzz", AtomType.CHARACTER), // + column("foo", AtomType.INT4), column("bar", AtomType.INT8), column("foo", AtomType.CHARACTER) // + ); + var target = IceaxeResultNameList.of(lowColumnList); + + assertEquals(List.of("foo", "bar", "zzz", "foo", "bar", "foo"), target.getNameList()); + assertThrows(IllegalArgumentException.class, () -> { + target.getIndex("not-found", policy); + }); + switch (policy) { + case ERROR: + assertThrows(IllegalArgumentException.class, () -> { + target.getIndex("foo", policy); + }); + assertThrows(IllegalArgumentException.class, () -> { + target.getIndex("bar", policy); + }); + break; + case FIRST: + assertEquals(0, target.getIndex("foo", policy)); + assertEquals(1, target.getIndex("bar", policy)); + break; + case LAST: + assertEquals(5, target.getIndex("foo", policy)); + assertEquals(4, target.getIndex("bar", policy)); + break; + default: + throw new AssertionError(policy); + } + assertEquals(2, target.getIndex("zzz", policy)); + } + + @Test + void getIndexSub() { + var lowColumnList = List.of( // + column("foo", AtomType.INT4), column("bar", AtomType.INT8), column("zzz", AtomType.CHARACTER), // + column("foo", AtomType.INT4), column("bar", AtomType.INT8), column("foo", AtomType.CHARACTER) // + ); + var target = IceaxeResultNameList.of(lowColumnList); + + assertEquals(List.of("foo", "bar", "zzz", "foo", "bar", "foo"), target.getNameList()); + assertThrows(IllegalArgumentException.class, () -> { + target.getIndex("not-found", 0); + }); + + assertEquals(0, target.getIndex("foo", 0)); + assertEquals(3, target.getIndex("foo", 1)); + assertEquals(5, target.getIndex("foo", 2)); + assertThrows(IllegalArgumentException.class, () -> { + target.getIndex("foo", 3); + }); + assertThrows(IllegalArgumentException.class, () -> { + target.getIndex("foo", -1); + }); + + assertEquals(1, target.getIndex("bar", 0)); + assertEquals(4, target.getIndex("bar", 1)); + assertThrows(IllegalArgumentException.class, () -> { + target.getIndex("bar", 2); + }); + assertThrows(IllegalArgumentException.class, () -> { + target.getIndex("bar", -1); + }); + + assertEquals(2, target.getIndex("zzz", 0)); + assertThrows(IllegalArgumentException.class, () -> { + target.getIndex("zzz", 1); + }); + assertThrows(IllegalArgumentException.class, () -> { + target.getIndex("zzz", -1); + }); + } + + @Test + void multiThread() throws Exception { + int columnSize = 100; + int threadSize = 16; + + var lowColumnList = new ArrayList(columnSize); + for (int i = 0; i < columnSize - 1; i++) { + lowColumnList.add(column("c" + i, AtomType.INT4)); + } + lowColumnList.add(column("c1", AtomType.INT8)); + + var service = Executors.newCachedThreadPool(); + try { + for (int attempt = 0; attempt < 10; attempt++) { + var target = IceaxeResultNameList.of(lowColumnList); + + var startWait = new AtomicBoolean(true); + + var futureList = new ArrayList>(threadSize); + for (int t = 0; t < threadSize; t++) { + var future = service.submit(() -> { + while (startWait.get()) { + } + + for (int i = 0; i < columnSize - 1; i++) { + assertEquals(i, target.getIndex("c" + i, IceaxeAmbiguousNamePolicy.FIRST)); + } + assertEquals(columnSize - 1, target.getIndex("c1", IceaxeAmbiguousNamePolicy.LAST)); + }); + futureList.add(future); + } + + startWait.set(false); + + for (var future : futureList) { + future.get(); + } + } + } finally { + service.shutdownNow(); + } + } + + private static Column column(String name, AtomType type) { + return Column.newBuilder().setName(name).setAtomType(type).build(); + } +} diff --git a/modules/iceaxe-examples/src/main/java/com/tsurugidb/iceaxe/example/Example31Select.java b/modules/iceaxe-examples/src/main/java/com/tsurugidb/iceaxe/example/Example31Select.java index fbc7b211..db54f624 100755 --- a/modules/iceaxe-examples/src/main/java/com/tsurugidb/iceaxe/example/Example31Select.java +++ b/modules/iceaxe-examples/src/main/java/com/tsurugidb/iceaxe/example/Example31Select.java @@ -111,15 +111,12 @@ void selectAsEntityLoop(TsurugiSession session, TsurugiTransactionManager tm) th } private TgResultMapping resultMappingForTestEntity() { - switch (4) { + switch (0) { default: - return TgResultMapping.of(record -> { - var entity = new TestEntity(); - entity.setFoo(record.getIntOrNull("FOO")); - entity.setBar(record.getLongOrNull("BAR")); - entity.setZzz(record.getStringOrNull("ZZZ")); - return entity; - }); + return TgResultMapping.of(TestEntity::new) // + .addInt("FOO", TestEntity::setFoo) // + .addLong("BAR", TestEntity::setBar) // + .addString("ZZZ", TestEntity::setZzz); case 1: return TgResultMapping.of(TestEntity::of); case 2: // selectのカラムの順序依存 @@ -132,11 +129,30 @@ private TgResultMapping resultMappingForTestEntity() { .addInt(0, TestEntity::setFoo) // .addLong(1, TestEntity::setBar) // .addString(2, TestEntity::setZzz); - case 4: - return TgResultMapping.of(TestEntity::new) // - .addInt("FOO", TestEntity::setFoo) // - .addLong("BAR", TestEntity::setBar) // - .addString("ZZZ", TestEntity::setZzz); + case 10: + return TgResultMapping.of(record -> { + var entity = new TestEntity(); + entity.setFoo(record.getIntOrNull("FOO")); + entity.setBar(record.getLongOrNull("BAR")); + entity.setZzz(record.getStringOrNull("ZZZ")); + return entity; + }); + case 12: // selectのカラムの順序依存 + return TgResultMapping.of(record -> { + var entity = new TestEntity(); + entity.setFoo(record.nextIntOrNull()); + entity.setBar(record.nextLongOrNull()); + entity.setZzz(record.nextStringOrNull()); + return entity; + }); + case 13: // selectのカラムの順序依存 + return TgResultMapping.of(record -> { + var entity = new TestEntity(); + entity.setFoo(record.getIntOrNull(0)); + entity.setBar(record.getLongOrNull(1)); + entity.setZzz(record.getStringOrNull(2)); + return entity; + }); } }