Skip to content

Instantly share code, notes, and snippets.

@japgolly
Created April 11, 2020 02:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save japgolly/582bd8c0dcb7d1ef6ac314db62c6c42e to your computer and use it in GitHub Desktop.
Save japgolly/582bd8c0dcb7d1ef6ac314db62c6c42e to your computer and use it in GitHub Desktop.
Postgres TIMESTAMP_WITH_TIMEZONE hack
#!/bin/bash
set -euo pipefail
cd "$(dirname "$0")/.."
org=org.postgresql
art=postgresql
pkg=org.postgresql.jdbc
name=TypeInfoCache
ext=java
pkgDir=${pkg//./\/}
tgt=base-db/src/main/java/$pkgDir
hack=$tgt/$name.$ext
orig=$hack.original
patch=$hack.patch
ver="$(
< project/Dep*.scala \
fgrep '"'"$org"'"' \
| sed 's/^[^0-9]*//; s/".*//'
)"
# echo "org: $org"
# echo "art: $art"
# echo "ver: $ver"
# echo "tgt: $tgt"
function update_orig {
sources=~/".coursier/cache/v1/https/repo1.maven.org/maven2/${org//./\/}/$art/$ver/$art-$ver-sources.jar"
[ ! -e "$sources" ] && echo "Source jar not found: $sources" && exit 1 || true
unzip -p "$sources" "$pkgDir/$name.$ext" > "$orig"
echo "Updated $orig"
}
function create_patch {
diff -u5 --ignore-all-space --text "$orig" "$hack" \
| sed -e '1,2s/\t.*//' \
> "$patch" \
|| [ $? -eq 1 ]
echo "Created $patch"
}
function apply_patch {
[ ! -e "$hack" ] || mv "$hack" /tmp
cp "$orig" "$hack"
patch -u --forward --ignore-whitespace "$hack" "$patch"
}
cmd_update_orig="update_orig"
cmd_create_patch="create_patch"
cmd_apply_patch="apply_patch"
options="$cmd_update_orig | $cmd_create_patch | $cmd_apply_patch"
[ $# -ne 1 ] && echo "Usage: $0 ($options)" && exit 1
case "$1" in
$cmd_update_orig)
update_orig
;;
$cmd_create_patch)
create_patch
;;
$cmd_apply_patch)
apply_patch
;;
*)
echo "Usage: $0 ($options)" && exit 1
;;
esac
--- base-db/src/main/java/org/postgresql/jdbc/TypeInfoCache.java.original
+++ base-db/src/main/java/org/postgresql/jdbc/TypeInfoCache.java
@@ -88,11 +88,11 @@
{"bit", Oid.BIT, Types.BIT, "java.lang.Boolean", Oid.BIT_ARRAY},
{"date", Oid.DATE, Types.DATE, "java.sql.Date", Oid.DATE_ARRAY},
{"time", Oid.TIME, Types.TIME, "java.sql.Time", Oid.TIME_ARRAY},
{"timetz", Oid.TIMETZ, Types.TIME, "java.sql.Time", Oid.TIMETZ_ARRAY},
{"timestamp", Oid.TIMESTAMP, Types.TIMESTAMP, "java.sql.Timestamp", Oid.TIMESTAMP_ARRAY},
- {"timestamptz", Oid.TIMESTAMPTZ, Types.TIMESTAMP, "java.sql.Timestamp",
+ {"timestamptz", Oid.TIMESTAMPTZ, Types.TIMESTAMP_WITH_TIMEZONE, "java.sql.Timestamp",
Oid.TIMESTAMPTZ_ARRAY},
//JCP! if mvn.project.property.postgresql.jdbc.spec >= "JDBC4.2"
{"refcursor", Oid.REF_CURSOR, Types.REF_CURSOR, "java.sql.ResultSet", Oid.REF_CURSOR_ARRAY},
//JCP! endif
{"json", Oid.JSON, Types.OTHER, "org.postgresql.util.PGobject", Oid.JSON_ARRAY},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment