#!/usr/bin/env bash # Starts the API with Hibernate SQL logging, performs one borrow, and prints only the SQL that # the borrow produced. Look for "version" in the UPDATE: that is optimistic locking at work. set -euo pipefail cd "$(dirname "$0")/.." mvn -B -q -DskipTests package LOG=/tmp/library-sql.log setsid nohup java -jar target/library-management-1.0.0.jar --server.port=8081 --logging.level.org.hibernate.SQL=DEBUG > "$LOG" 2>&1 < /dev/null & for _ in $(seq 1 60); do curl -s -o /dev/null localhost:8081/api/books && break; sleep 1; done J='Content-Type: application/json' curl -s -o /dev/null -H "$J" -d '{"isbn":"978-0134685991","title":"Effective Java","author":"Joshua Bloch","copies":2}' localhost:8081/api/books curl -s -o /dev/null -H "$J" -d '{"name":"Asha","email":"asha@example.com"}' localhost:8081/api/members START=$(wc -l < "$LOG") curl -s -o /dev/null -H "$J" -d '{"memberId":1,"bookId":1}' localhost:8081/api/loans sleep 1 tail -n +"$((START + 1))" "$LOG" | grep 'org.hibernate.SQL' | sed -E 's/^.*org.hibernate.SQL +: //' scripts/stop.sh