Files
spring-boot-demo/multi-datasource/scripts/capture-facts.sh
T
Claude e59ff029a1 Add multi-datasource module: two databases with per-database DataSource, Flyway, EntityManagerFactory and transaction manager on Boot 4.1
Working setup plus one small application per way of getting it wrong (no @Primary, @Primary only, url vs jdbc-url, wrong repository package, Flyway auto-configuration), plain vs named @Transactional, and ChainedTransactionManager with a failing commit. Transcripts are written by the tests.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Uu7q8vPeREyT4218EJPzz1
2026-09-24 09:38:27 +00:00

46 lines
2.5 KiB
Bash
Executable File

#!/usr/bin/env bash
# Facts that a test cannot observe, read straight out of the jars on the classpath.
# 10-chained-transaction-manager-jar.txt is ChainedTransactionManager still shipped, and is it deprecated?
# 11-enable-jpa-repositories-not-repeatable.txt what javac says about two @EnableJpaRepositories on one class
# 12-builder-packages.txt how EntityManagerFactoryBuilder.Builder.packages(Class...) turns classes into packages
set -euo pipefail
cd "$(dirname "$0")/.."
mkdir -p output target
mvn -B -q dependency:build-classpath -Dmdep.outputFile=target/classpath.txt >/dev/null
CP="$(cat target/classpath.txt)"
commons="$(tr ':' '\n' < target/classpath.txt | grep 'spring-data-commons' | head -1)"
{
echo "# Is org.springframework.data.transaction.ChainedTransactionManager still shipped, and is it deprecated?"
echo
echo "jar: $(basename "$commons")"
echo "class: $(unzip -l "$commons" | awk '{print $4}' | grep 'transaction/ChainedTransactionManager.class')"
echo
echo "--- javap -v: class-level annotations ---"
javap -v -cp "$commons" org.springframework.data.transaction.ChainedTransactionManager \
| awk '/^RuntimeVisibleAnnotations:/{p=1} p{print} /^BootstrapMethods:/{p=0}' | sed '/^BootstrapMethods:/,$d'
echo "--- javap -v: Deprecated attribute ---"
javap -v -cp "$commons" org.springframework.data.transaction.ChainedTransactionManager | grep -E '^Deprecated:'
} > output/10-chained-transaction-manager-jar.txt
{
echo "# javac on a class carrying two @EnableJpaRepositories (scripts/facts/RepeatedEnable.java)"
echo
javac -proc:none -d target/facts -cp "$CP" scripts/facts/RepeatedEnable.java 2>&1 | grep -v "^Picked up" | sed "s|scripts/facts/||" || true
} > output/11-enable-jpa-repositories-not-repeatable.txt
boot_jpa="$(tr ':' '\n' < target/classpath.txt | grep 'spring-boot-jpa-' | head -1)"
{
echo "# What does EntityManagerFactoryBuilder.Builder.packages(Class...) do with the classes it is given?"
echo
echo "jar: $(basename "$boot_jpa")"
echo
echo "--- javap -c: the calls made inside packages(java.lang.Class<?>...) ---"
javap -c -p -cp "$boot_jpa" 'org.springframework.boot.jpa.EntityManagerFactoryBuilder$Builder' 2>&1 \
| grep -v '^Picked up' \
| awk '/packages\(java.lang.Class<\?>\.\.\.\);/{p=1} p&&/^$/{p=0} p' \
| grep -E 'invoke' | sed 's/^ *[0-9]*: *//'
} > output/12-builder-packages.txt
cat output/10-chained-transaction-manager-jar.txt output/11-enable-jpa-repositories-not-repeatable.txt output/12-builder-packages.txt