Files
hibernate-demo/date-time/scripts/run-all.sh
T
asmhatreandClaude Sonnet 5.5 ef2d2aa8ea Add date-time module: Instant vs LocalDateTime vs OffsetDateTime vs ZonedDateTime round-tripped across JVM time zones on H2 and PostgreSQL
Hibernate 7.4.14.Final (plus an 8.0.0.Beta4 preview run), H2 2.5.252, PostgreSQL 17.11 in Docker.
Same-JVM and cross-zone round trips, @TimeZoneStorage modes, DST gap/overlap, precision
(precision vs secondPrecision), hibernate.jdbc.time_zone, java_time_use_direct_jdbc default flip.
Supersedes the date/time experiments of docs/13 (7.4.5); chapter 13 is unchanged.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_017ic4b7rnC7jppGGdHGESvy
2026-10-29 00:56:54 +00:00

81 lines
3.3 KiB
Bash
Executable File

#!/usr/bin/env bash
# Regenerates every file under output/. Needs JDK 25, Maven 3.9 (online, first run), and Docker
# (PostgreSQL 17 runs in a throwaway container on a random localhost port).
#
# Matrix: database (H2 file db, PostgreSQL 17) x JVM default zone (Asia/Kolkata, America/New_York)
# same-JVM round trips, plus cross-zone round trips (write in one zone, read in the other),
# then java_time_use_direct_jdbc=true on Hibernate 7, then the same on Hibernate 8.0.0.Beta4.
# Pass H7_ONLY=1 to skip the Hibernate 8 beta runs, H8_ONLY=1 to run only those (keeps existing output/).
set -euo pipefail
cd "$(dirname "$0")/.."
K=Asia/Kolkata
NY=America/New_York
NAME="dt-pg-$$"
cleanup() { docker rm -f "$NAME" >/dev/null 2>&1 || true; }
trap cleanup EXIT
docker run -d --rm --name "$NAME" -e POSTGRES_PASSWORD=postgres -p 127.0.0.1::5432 postgres:17-alpine >/dev/null
PORT="$(docker port "$NAME" 5432/tcp | head -1 | sed 's/.*://')"
for _ in $(seq 1 60); do
docker exec "$NAME" pg_isready -U postgres >/dev/null 2>&1 && break
sleep 1
done
sleep 2
PGURL="jdbc:postgresql://127.0.0.1:${PORT}/postgres"
echo "postgres: $(docker exec "$NAME" psql -U postgres -Atc 'select version()')" >&2
mkdir -p output
[ -n "${H8_ONLY:-}" ] || { rm -rf output; mkdir -p output; }
if [ -z "${H8_ONLY:-}" ]; then
{
echo "# environment for this run of scripts/run-all.sh"
java -version 2>&1 | grep -v '^Picked up'
echo "postgres server: $(docker exec "$NAME" psql -U postgres -Atc 'select version()')"
echo "postgres image: $(docker image inspect --format '{{index .RepoDigests 0}}' postgres:17-alpine)"
echo "postgres server TimeZone setting: $(docker exec "$NAME" psql -U postgres -Atc 'show timezone')"
echo "jdbc drivers: org.postgresql:postgresql:42.7.14, com.h2database:h2:2.5.252, org.hsqldb:hsqldb:2.7.4"
} > output/00-environment.txt
fi
run() { # db, phase, jvm zone, extra maven -D flags...
local db="$1" phase="$2" zone="$3"; shift 3
echo "== db=$db phase=$phase zone=$zone $*" >&2
mvn -B -q surefire:test -Ddt.db="$db" -Ddt.phase="$phase" -Ddt.pg.url="$PGURL" \
-Ddt.jvmargs="-Duser.timezone=$zone -Ddt.writerZone=${WRITER:-none}" "$@"
}
if [ -z "${H8_ONLY:-}" ]; then
mvn -B -q clean test-compile
for db in h2 postgres; do
run "$db" both "$K"
run "$db" both "$NY"
# cross-zone: the writer JVM and the reader JVM have different default zones
WRITER="$K" run "$db" write "$K" -Dtest=RoundTripTest,ZonedTest
WRITER="$K" run "$db" read "$NY" -Dtest=RoundTripTest,ZonedTest
WRITER="$NY" run "$db" write "$NY" -Dtest=RoundTripTest,ZonedTest
WRITER="$NY" run "$db" read "$K" -Dtest=RoundTripTest,ZonedTest
# Hibernate 7's default is java_time_use_direct_jdbc=false; flip it
run "$db" both "$NY" -Ddt.directJdbc=true
done
# HSQLDB is only here to re-check the old "H2 rounds, HSQLDB truncates" claim
run hsqldb both "$K" -Dtest=EdgeCasesTest#precision
fi
if [ -z "${H7_ONLY:-}" ]; then
H8="-Dhibernate.version=8.0.0.Beta4 -Dpersistence.version=4.0.0-M7 -Dh.label=h8"
# shellcheck disable=SC2086
mvn -B -q clean test-compile $H8
for db in h2 postgres; do
# shellcheck disable=SC2086
{ run "$db" both "$K" $H8
run "$db" both "$NY" $H8
run "$db" both "$NY" $H8 -Ddt.directJdbc=false; }
done
fi
[ -n "${H7_ONLY:-}" ] || ./scripts/javap-facts.sh >/dev/null
ls -1 output | wc -l