diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2b7234b5..1c660636 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,18 +1,19 @@ name: Java CI with Maven on: push: - branches: [ main ] + branches: '**' pull_request: branches: [ main ] jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - name: Set up JDK 11 - uses: actions/setup-java@v1 + - uses: actions/checkout@v3 + - name: Set up JDK 17 + uses: actions/setup-java@v3 with: - java-version: 11 + java-version: '17' + distribution: 'temurin' - name: Install run: ./mvnw install -DskipTests - name: Test diff --git a/.mvn/wrapper/maven-wrapper.jar b/.mvn/wrapper/maven-wrapper.jar index c6feb8bb..cb28b0e3 100644 Binary files a/.mvn/wrapper/maven-wrapper.jar and b/.mvn/wrapper/maven-wrapper.jar differ diff --git a/.mvn/wrapper/maven-wrapper.properties b/.mvn/wrapper/maven-wrapper.properties index 56bb0164..3c6fda8c 100644 --- a/.mvn/wrapper/maven-wrapper.properties +++ b/.mvn/wrapper/maven-wrapper.properties @@ -1 +1,18 @@ -distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.0/apache-maven-3.5.0-bin.zip \ No newline at end of file +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.2/apache-maven-3.9.2-bin.zip +wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar diff --git a/README.md b/README.md index ee4fd209..2fa8bfa0 100644 --- a/README.md +++ b/README.md @@ -23,37 +23,21 @@ for each instance of your application. # Using databases -This Narayana starter supports two ways to enlist a relational database to a JTA transaction: Narayana Transactional -Driver and DBCP2. - -By default Narayana Transactional driver is used which provides a basic XAResource enlistment and recovery. +By default Narayana Transactional driver is used to enlist a relational database to a JTA transaction which provides a basic XAResource enlistment and recovery. ## Add pooling -If you need a more sophisticated connection management, you can enable DBCP2 support which provides connection pooling -and many other features. To enable DBCP2 add the following property to you application configuration: -``` -narayana.dbcp.enabled=true -``` -All DBCP2 configuration properties described in its -[documentation](https://commons.apache.org/proper/commons-dbcp/configuration.html) are mapped with a prefix -`narayana.dbcp`. So for example if you'd like to set an initial pool size to 10, you could do that by adding this entry -to your application configuration: -``` -narayana.dbcp.initialSize=10 -``` - -## Add last resource commit optimization - -If you are forced to use a non-xa DataSource to connect to your database you can auto wrap a JDBC Driver instance in a -special XADataSource instance with last resource commit optimization enabled by adding this entry to your application -configuration: +If you need a more sophisticated connection management, we advice you to use [agroal-spring-boot-starter](https://agroal.github.io) +which provides connection pooling and many other features. To enable Agroal add the following dependency to your application configuration: ``` -narayana.dbcp.enabled=true -narayana.lrco.enabled=true + + io.agroal + agroal-spring-boot-starter + 2.x.x + ``` -> Due to Narayana internal design restrictions, last resource commit optimization is supported for pooled DataSources only. +All Agroal configuration properties described in its [documentation](https://agroal.github.io/docs.html) # Using messaging brokers diff --git a/mvnw b/mvnw index 5bf251c0..8d937f4c 100755 --- a/mvnw +++ b/mvnw @@ -19,7 +19,7 @@ # ---------------------------------------------------------------------------- # ---------------------------------------------------------------------------- -# Maven2 Start Up Batch script +# Apache Maven Wrapper startup batch script, version 3.2.0 # # Required ENV vars: # ------------------ @@ -27,7 +27,6 @@ # # Optional ENV vars # ----------------- -# M2_HOME - location of maven2's installed home dir # MAVEN_OPTS - parameters passed to the Java VM when running Maven # e.g. to debug Maven itself, use # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 @@ -36,6 +35,10 @@ if [ -z "$MAVEN_SKIP_RC" ] ; then + if [ -f /usr/local/etc/mavenrc ] ; then + . /usr/local/etc/mavenrc + fi + if [ -f /etc/mavenrc ] ; then . /etc/mavenrc fi @@ -50,7 +53,7 @@ fi cygwin=false; darwin=false; mingw=false -case "`uname`" in +case "$(uname)" in CYGWIN*) cygwin=true ;; MINGW*) mingw=true;; Darwin*) darwin=true @@ -58,9 +61,9 @@ case "`uname`" in # See https://developer.apple.com/library/mac/qa/qa1170/_index.html if [ -z "$JAVA_HOME" ]; then if [ -x "/usr/libexec/java_home" ]; then - export JAVA_HOME="`/usr/libexec/java_home`" + JAVA_HOME="$(/usr/libexec/java_home)"; export JAVA_HOME else - export JAVA_HOME="/Library/Java/Home" + JAVA_HOME="/Library/Java/Home"; export JAVA_HOME fi fi ;; @@ -68,69 +71,38 @@ esac if [ -z "$JAVA_HOME" ] ; then if [ -r /etc/gentoo-release ] ; then - JAVA_HOME=`java-config --jre-home` + JAVA_HOME=$(java-config --jre-home) fi fi -if [ -z "$M2_HOME" ] ; then - ## resolve links - $0 may be a link to maven's home - PRG="$0" - - # need this for relative symlinks - while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG="`dirname "$PRG"`/$link" - fi - done - - saveddir=`pwd` - - M2_HOME=`dirname "$PRG"`/.. - - # make it fully qualified - M2_HOME=`cd "$M2_HOME" && pwd` - - cd "$saveddir" - # echo Using m2 at $M2_HOME -fi - # For Cygwin, ensure paths are in UNIX format before anything is touched if $cygwin ; then - [ -n "$M2_HOME" ] && - M2_HOME=`cygpath --unix "$M2_HOME"` [ -n "$JAVA_HOME" ] && - JAVA_HOME=`cygpath --unix "$JAVA_HOME"` + JAVA_HOME=$(cygpath --unix "$JAVA_HOME") [ -n "$CLASSPATH" ] && - CLASSPATH=`cygpath --path --unix "$CLASSPATH"` + CLASSPATH=$(cygpath --path --unix "$CLASSPATH") fi -# For Migwn, ensure paths are in UNIX format before anything is touched +# For Mingw, ensure paths are in UNIX format before anything is touched if $mingw ; then - [ -n "$M2_HOME" ] && - M2_HOME="`(cd "$M2_HOME"; pwd)`" - [ -n "$JAVA_HOME" ] && - JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" - # TODO classpath? + [ -n "$JAVA_HOME" ] && [ -d "$JAVA_HOME" ] && + JAVA_HOME="$(cd "$JAVA_HOME" || (echo "cannot cd into $JAVA_HOME."; exit 1); pwd)" fi if [ -z "$JAVA_HOME" ]; then - javaExecutable="`which javac`" - if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then + javaExecutable="$(which javac)" + if [ -n "$javaExecutable" ] && ! [ "$(expr "\"$javaExecutable\"" : '\([^ ]*\)')" = "no" ]; then # readlink(1) is not available as standard on Solaris 10. - readLink=`which readlink` - if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then + readLink=$(which readlink) + if [ ! "$(expr "$readLink" : '\([^ ]*\)')" = "no" ]; then if $darwin ; then - javaHome="`dirname \"$javaExecutable\"`" - javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" + javaHome="$(dirname "\"$javaExecutable\"")" + javaExecutable="$(cd "\"$javaHome\"" && pwd -P)/javac" else - javaExecutable="`readlink -f \"$javaExecutable\"`" + javaExecutable="$(readlink -f "\"$javaExecutable\"")" fi - javaHome="`dirname \"$javaExecutable\"`" - javaHome=`expr "$javaHome" : '\(.*\)/bin'` + javaHome="$(dirname "\"$javaExecutable\"")" + javaHome=$(expr "$javaHome" : '\(.*\)/bin') JAVA_HOME="$javaHome" export JAVA_HOME fi @@ -146,7 +118,7 @@ if [ -z "$JAVACMD" ] ; then JAVACMD="$JAVA_HOME/bin/java" fi else - JAVACMD="`which java`" + JAVACMD="$(\unset -f command 2>/dev/null; \command -v java)" fi fi @@ -160,12 +132,9 @@ if [ -z "$JAVA_HOME" ] ; then echo "Warning: JAVA_HOME environment variable is not set." fi -CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher - # traverses directory structure from process work directory to filesystem root # first directory with .mvn subdirectory is considered project base directory find_maven_basedir() { - if [ -z "$1" ] then echo "Path not specified to find_maven_basedir" @@ -181,45 +150,159 @@ find_maven_basedir() { fi # workaround for JBEAP-8937 (on Solaris 10/Sparc) if [ -d "${wdir}" ]; then - wdir=`cd "$wdir/.."; pwd` + wdir=$(cd "$wdir/.." || exit 1; pwd) fi # end of workaround done - echo "${basedir}" + printf '%s' "$(cd "$basedir" || exit 1; pwd)" } # concatenates all lines of a file concat_lines() { if [ -f "$1" ]; then - echo "$(tr -s '\n' ' ' < "$1")" + # Remove \r in case we run on Windows within Git Bash + # and check out the repository with auto CRLF management + # enabled. Otherwise, we may read lines that are delimited with + # \r\n and produce $'-Xarg\r' rather than -Xarg due to word + # splitting rules. + tr -s '\r\n' ' ' < "$1" fi } -BASE_DIR=`find_maven_basedir "$(pwd)"` +log() { + if [ "$MVNW_VERBOSE" = true ]; then + printf '%s\n' "$1" + fi +} + +BASE_DIR=$(find_maven_basedir "$(dirname "$0")") if [ -z "$BASE_DIR" ]; then exit 1; fi -export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} -echo $MAVEN_PROJECTBASEDIR +MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"}; export MAVEN_PROJECTBASEDIR +log "$MAVEN_PROJECTBASEDIR" + +########################################################################################## +# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +# This allows using the maven wrapper in projects that prohibit checking in binary data. +########################################################################################## +wrapperJarPath="$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" +if [ -r "$wrapperJarPath" ]; then + log "Found $wrapperJarPath" +else + log "Couldn't find $wrapperJarPath, downloading it ..." + + if [ -n "$MVNW_REPOURL" ]; then + wrapperUrl="$MVNW_REPOURL/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar" + else + wrapperUrl="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar" + fi + while IFS="=" read -r key value; do + # Remove '\r' from value to allow usage on windows as IFS does not consider '\r' as a separator ( considers space, tab, new line ('\n'), and custom '=' ) + safeValue=$(echo "$value" | tr -d '\r') + case "$key" in (wrapperUrl) wrapperUrl="$safeValue"; break ;; + esac + done < "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.properties" + log "Downloading from: $wrapperUrl" + + if $cygwin; then + wrapperJarPath=$(cygpath --path --windows "$wrapperJarPath") + fi + + if command -v wget > /dev/null; then + log "Found wget ... using wget" + [ "$MVNW_VERBOSE" = true ] && QUIET="" || QUIET="--quiet" + if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then + wget $QUIET "$wrapperUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath" + else + wget $QUIET --http-user="$MVNW_USERNAME" --http-password="$MVNW_PASSWORD" "$wrapperUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath" + fi + elif command -v curl > /dev/null; then + log "Found curl ... using curl" + [ "$MVNW_VERBOSE" = true ] && QUIET="" || QUIET="--silent" + if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then + curl $QUIET -o "$wrapperJarPath" "$wrapperUrl" -f -L || rm -f "$wrapperJarPath" + else + curl $QUIET --user "$MVNW_USERNAME:$MVNW_PASSWORD" -o "$wrapperJarPath" "$wrapperUrl" -f -L || rm -f "$wrapperJarPath" + fi + else + log "Falling back to using Java to download" + javaSource="$MAVEN_PROJECTBASEDIR/.mvn/wrapper/MavenWrapperDownloader.java" + javaClass="$MAVEN_PROJECTBASEDIR/.mvn/wrapper/MavenWrapperDownloader.class" + # For Cygwin, switch paths to Windows format before running javac + if $cygwin; then + javaSource=$(cygpath --path --windows "$javaSource") + javaClass=$(cygpath --path --windows "$javaClass") + fi + if [ -e "$javaSource" ]; then + if [ ! -e "$javaClass" ]; then + log " - Compiling MavenWrapperDownloader.java ..." + ("$JAVA_HOME/bin/javac" "$javaSource") + fi + if [ -e "$javaClass" ]; then + log " - Running MavenWrapperDownloader.java ..." + ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$wrapperUrl" "$wrapperJarPath") || rm -f "$wrapperJarPath" + fi + fi + fi +fi +########################################################################################## +# End of extension +########################################################################################## + +# If specified, validate the SHA-256 sum of the Maven wrapper jar file +wrapperSha256Sum="" +while IFS="=" read -r key value; do + case "$key" in (wrapperSha256Sum) wrapperSha256Sum=$value; break ;; + esac +done < "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.properties" +if [ -n "$wrapperSha256Sum" ]; then + wrapperSha256Result=false + if command -v sha256sum > /dev/null; then + if echo "$wrapperSha256Sum $wrapperJarPath" | sha256sum -c > /dev/null 2>&1; then + wrapperSha256Result=true + fi + elif command -v shasum > /dev/null; then + if echo "$wrapperSha256Sum $wrapperJarPath" | shasum -a 256 -c > /dev/null 2>&1; then + wrapperSha256Result=true + fi + else + echo "Checksum validation was requested but neither 'sha256sum' or 'shasum' are available." + echo "Please install either command, or disable validation by removing 'wrapperSha256Sum' from your maven-wrapper.properties." + exit 1 + fi + if [ $wrapperSha256Result = false ]; then + echo "Error: Failed to validate Maven wrapper SHA-256, your Maven wrapper might be compromised." >&2 + echo "Investigate or delete $wrapperJarPath to attempt a clean download." >&2 + echo "If you updated your Maven version, you need to update the specified wrapperSha256Sum property." >&2 + exit 1 + fi +fi + MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" # For Cygwin, switch paths to Windows format before running java if $cygwin; then - [ -n "$M2_HOME" ] && - M2_HOME=`cygpath --path --windows "$M2_HOME"` [ -n "$JAVA_HOME" ] && - JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` + JAVA_HOME=$(cygpath --path --windows "$JAVA_HOME") [ -n "$CLASSPATH" ] && - CLASSPATH=`cygpath --path --windows "$CLASSPATH"` + CLASSPATH=$(cygpath --path --windows "$CLASSPATH") [ -n "$MAVEN_PROJECTBASEDIR" ] && - MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` + MAVEN_PROJECTBASEDIR=$(cygpath --path --windows "$MAVEN_PROJECTBASEDIR") fi +# Provide a "standardized" way to retrieve the CLI args that will +# work with both Windows and non-Windows executions. +MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $*" +export MAVEN_CMD_LINE_ARGS + WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain +# shellcheck disable=SC2086 # safe args exec "$JAVACMD" \ $MAVEN_OPTS \ + $MAVEN_DEBUG_OPTS \ -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ - "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ + "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" diff --git a/mvnw.cmd b/mvnw.cmd index 019bd74d..c4586b56 100755 --- a/mvnw.cmd +++ b/mvnw.cmd @@ -18,15 +18,14 @@ @REM ---------------------------------------------------------------------------- @REM ---------------------------------------------------------------------------- -@REM Maven2 Start Up Batch script +@REM Apache Maven Wrapper startup batch script, version 3.2.0 @REM @REM Required ENV vars: @REM JAVA_HOME - location of a JDK home dir @REM @REM Optional ENV vars -@REM M2_HOME - location of maven2's installed home dir @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands -@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending +@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven @REM e.g. to debug Maven itself, use @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 @@ -35,7 +34,9 @@ @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' @echo off -@REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' +@REM set title of command window +title %0 +@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% @REM set %HOME% to equivalent of $HOME @@ -44,8 +45,8 @@ if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") @REM Execute a user defined script before this one if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre @REM check for pre script, once with legacy .bat ending and once with .cmd ending -if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" -if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" +if exist "%USERPROFILE%\mavenrc_pre.bat" call "%USERPROFILE%\mavenrc_pre.bat" %* +if exist "%USERPROFILE%\mavenrc_pre.cmd" call "%USERPROFILE%\mavenrc_pre.cmd" %* :skipRcPre @setlocal @@ -115,11 +116,72 @@ for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do s :endReadAdditionalConfig SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" - set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain -%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* +set WRAPPER_URL="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar" + +FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( + IF "%%A"=="wrapperUrl" SET WRAPPER_URL=%%B +) + +@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +@REM This allows using the maven wrapper in projects that prohibit checking in binary data. +if exist %WRAPPER_JAR% ( + if "%MVNW_VERBOSE%" == "true" ( + echo Found %WRAPPER_JAR% + ) +) else ( + if not "%MVNW_REPOURL%" == "" ( + SET WRAPPER_URL="%MVNW_REPOURL%/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar" + ) + if "%MVNW_VERBOSE%" == "true" ( + echo Couldn't find %WRAPPER_JAR%, downloading it ... + echo Downloading from: %WRAPPER_URL% + ) + + powershell -Command "&{"^ + "$webclient = new-object System.Net.WebClient;"^ + "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ + "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ + "}"^ + "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%WRAPPER_URL%', '%WRAPPER_JAR%')"^ + "}" + if "%MVNW_VERBOSE%" == "true" ( + echo Finished downloading %WRAPPER_JAR% + ) +) +@REM End of extension + +@REM If specified, validate the SHA-256 sum of the Maven wrapper jar file +SET WRAPPER_SHA_256_SUM="" +FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( + IF "%%A"=="wrapperSha256Sum" SET WRAPPER_SHA_256_SUM=%%B +) +IF NOT %WRAPPER_SHA_256_SUM%=="" ( + powershell -Command "&{"^ + "$hash = (Get-FileHash \"%WRAPPER_JAR%\" -Algorithm SHA256).Hash.ToLower();"^ + "If('%WRAPPER_SHA_256_SUM%' -ne $hash){"^ + " Write-Output 'Error: Failed to validate Maven wrapper SHA-256, your Maven wrapper might be compromised.';"^ + " Write-Output 'Investigate or delete %WRAPPER_JAR% to attempt a clean download.';"^ + " Write-Output 'If you updated your Maven version, you need to update the specified wrapperSha256Sum property.';"^ + " exit 1;"^ + "}"^ + "}" + if ERRORLEVEL 1 goto error +) + +@REM Provide a "standardized" way to retrieve the CLI args that will +@REM work with both Windows and non-Windows executions. +set MAVEN_CMD_LINE_ARGS=%* + +%MAVEN_JAVA_EXE% ^ + %JVM_CONFIG_MAVEN_PROPS% ^ + %MAVEN_OPTS% ^ + %MAVEN_DEBUG_OPTS% ^ + -classpath %WRAPPER_JAR% ^ + "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" ^ + %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* if ERRORLEVEL 1 goto error goto end @@ -129,15 +191,15 @@ set ERROR_CODE=1 :end @endlocal & set ERROR_CODE=%ERROR_CODE% -if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost +if not "%MAVEN_SKIP_RC%"=="" goto skipRcPost @REM check for post script, once with legacy .bat ending and once with .cmd ending -if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" -if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" +if exist "%USERPROFILE%\mavenrc_post.bat" call "%USERPROFILE%\mavenrc_post.bat" +if exist "%USERPROFILE%\mavenrc_post.cmd" call "%USERPROFILE%\mavenrc_post.cmd" :skipRcPost @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' -if "%MAVEN_BATCH_PAUSE%" == "on" pause +if "%MAVEN_BATCH_PAUSE%"=="on" pause -if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% +if "%MAVEN_TERMINATE_CMD%"=="on" exit %ERROR_CODE% -exit /B %ERROR_CODE% +cmd /C exit /B %ERROR_CODE% diff --git a/narayana-spring-boot-core/pom.xml b/narayana-spring-boot-core/pom.xml index 9f208f82..45f37589 100644 --- a/narayana-spring-boot-core/pom.xml +++ b/narayana-spring-boot-core/pom.xml @@ -19,7 +19,7 @@ me.snowdrop narayana-spring-boot-parent - 2.6.7-SNAPSHOT + 3.0.0-SNAPSHOT narayana-spring-boot-core @@ -36,21 +36,13 @@ org.jboss.narayana.jts narayana-jts-integration - - org.jboss - jboss-transaction-spi - org.jboss.logging jboss-logging - org.apache.commons - commons-dbcp2 - - - javax.jms - javax.jms-api + jakarta.jms + jakarta.jms-api true diff --git a/narayana-spring-boot-core/src/main/java/me/snowdrop/boot/narayana/core/jdbc/PooledXADataSourceWrapper.java b/narayana-spring-boot-core/src/main/java/me/snowdrop/boot/narayana/core/jdbc/PooledXADataSourceWrapper.java deleted file mode 100644 index 5d0e419c..00000000 --- a/narayana-spring-boot-core/src/main/java/me/snowdrop/boot/narayana/core/jdbc/PooledXADataSourceWrapper.java +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright 2020 Red Hat, Inc, and individual contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package me.snowdrop.boot.narayana.core.jdbc; - -import java.lang.reflect.Field; -import java.lang.reflect.Modifier; -import java.util.Map; -import java.util.Properties; - -import javax.sql.DataSource; -import javax.sql.XADataSource; -import javax.transaction.TransactionManager; - -import com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule; -import me.snowdrop.boot.narayana.core.properties.RecoveryCredentialsProperties; -import org.apache.commons.dbcp2.BasicDataSource; -import org.apache.commons.dbcp2.BasicDataSourceFactory; -import org.apache.commons.dbcp2.managed.BasicManagedDataSource; - -/** - * {@link AbstractXADataSourceWrapper} implementation that uses {@link BasicManagedDataSource} to wrap an - * {@link XADataSource}. - *

- * {@link BasicManagedDataSource} provides a pooling support which is not available in the Narayana transactional - * driver. - * - * @author Gytis Trikleris - */ -public class PooledXADataSourceWrapper extends AbstractXADataSourceWrapper { - - private final Map properties; - private final TransactionManager transactionManager; - - /** - * Create a new {@link PooledXADataSourceWrapper} instance. - * - * @param transactionManager underlying transaction manager - * @param xaRecoveryModule recovery module to register data source with. - * @param properties DBCP properties - */ - public PooledXADataSourceWrapper(TransactionManager transactionManager, XARecoveryModule xaRecoveryModule, - Map properties) { - this(transactionManager, xaRecoveryModule, properties, RecoveryCredentialsProperties.DEFAULT); - } - - /** - * Create a new {@link PooledXADataSourceWrapper} instance. - * - * @param transactionManager underlying transaction manager - * @param xaRecoveryModule recovery module to register data source with. - * @param properties DBCP properties - * @param recoveryCredentials credentials for recovery helper - */ - public PooledXADataSourceWrapper(TransactionManager transactionManager, XARecoveryModule xaRecoveryModule, - Map properties, RecoveryCredentialsProperties recoveryCredentials) { - super(xaRecoveryModule, recoveryCredentials); - this.properties = properties; - this.transactionManager = transactionManager; - } - - /** - * Wrap the provided data source and initialize the connection pool if its initial size is higher than 0. - * - * @param xaDataSource data source that needs to be wrapped - * @return wrapped data source - * @throws Exception if data source copy or connection pool initialization has failed. - */ - @Override - protected DataSource wrapDataSourceInternal(XADataSource xaDataSource) throws Exception { - BasicManagedDataSource basicManagedDataSource = new BasicManagedDataSource(); - // Managed data source does't have a factory. Therefore we need to create an unmanaged data source and then copy - // it's configuration to the managed one. - BasicDataSource basicDataSource = getBasicDataSource(); - copyFields(basicDataSource, basicManagedDataSource); - basicManagedDataSource.setTransactionManager(this.transactionManager); - basicManagedDataSource.setXaDataSourceInstance(xaDataSource); - - // Initialize the connections pool - int initialSize = Integer.valueOf(this.properties.getOrDefault("initialSize", "0")); - if (initialSize > 0) { - basicManagedDataSource.setInitialSize(initialSize); - basicManagedDataSource.getLogWriter(); // A trick to trigger pool initialization - } - - return basicManagedDataSource; - } - - private BasicDataSource getBasicDataSource() throws Exception { - Properties dbcpProperties = new Properties(); - dbcpProperties.putAll(this.properties); - // BasicDataSource is only used to load correct properties. Thus no connections should be created. - dbcpProperties.put("initialSize", "0"); - - return BasicDataSourceFactory.createDataSource(dbcpProperties); - } - - private void copyFields(Object source, Object destination) throws IllegalAccessException { - for (Field field: source.getClass().getDeclaredFields()) { - field.setAccessible(true); - if (field.get(source) == null || Modifier.isFinal(field.getModifiers())) { - continue; - } - field.set(destination, field.get(source)); - } - } - -} diff --git a/narayana-spring-boot-core/src/main/java/me/snowdrop/boot/narayana/core/jdbc/lrco/LrcoXAConnection.java b/narayana-spring-boot-core/src/main/java/me/snowdrop/boot/narayana/core/jdbc/lrco/LrcoXAConnection.java deleted file mode 100644 index e0c8e024..00000000 --- a/narayana-spring-boot-core/src/main/java/me/snowdrop/boot/narayana/core/jdbc/lrco/LrcoXAConnection.java +++ /dev/null @@ -1,399 +0,0 @@ -/* - * Copyright 2020 Red Hat, Inc, and individual contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package me.snowdrop.boot.narayana.core.jdbc.lrco; - -import java.sql.Array; -import java.sql.Blob; -import java.sql.CallableStatement; -import java.sql.Clob; -import java.sql.Connection; -import java.sql.DatabaseMetaData; -import java.sql.NClob; -import java.sql.PreparedStatement; -import java.sql.SQLClientInfoException; -import java.sql.SQLException; -import java.sql.SQLWarning; -import java.sql.SQLXML; -import java.sql.Savepoint; -import java.sql.Statement; -import java.sql.Struct; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Properties; -import java.util.concurrent.Executor; - -import javax.sql.ConnectionEvent; -import javax.sql.ConnectionEventListener; -import javax.sql.StatementEventListener; -import javax.sql.XAConnection; -import javax.transaction.xa.XAResource; - -public class LrcoXAConnection implements XAConnection { - - private final Connection physicalConnection; - private volatile Connection handleConnection; - private final List eventListeners; - - public LrcoXAConnection(Connection connection) throws SQLException { - this.physicalConnection = connection; - this.eventListeners = new ArrayList<>(); - } - - @Override - public XAResource getXAResource() throws SQLException { - return new LrcoXAResource(this.physicalConnection); - } - - @Override - public Connection getConnection() throws SQLException { - Connection lastHandleConnection = this.handleConnection; - if (lastHandleConnection != null) { - lastHandleConnection.close(); - } - this.handleConnection = new PooledJdbcConnection(); - return this.handleConnection; - } - - @Override - public void close() throws SQLException { - Connection lastHandleConnection = this.handleConnection; - if (lastHandleConnection != null) { - lastHandleConnection.close(); - } - this.physicalConnection.close(); - } - - private void closeHandle() { - ConnectionEvent event = new ConnectionEvent(this); - for (int i = 0; i < this.eventListeners.size(); i++) { - ConnectionEventListener listener = this.eventListeners.get(i); - listener.connectionClosed(event); - } - this.handleConnection = null; - } - - @Override - public void addConnectionEventListener(ConnectionEventListener listener) { - if (!this.eventListeners.contains(listener)) { - this.eventListeners.add(listener); - } - } - - @Override - public void removeConnectionEventListener(ConnectionEventListener listener) { - this.eventListeners.remove(listener); - } - - @Override - public void addStatementEventListener(StatementEventListener listener) { - } - - @Override - public void removeStatementEventListener(StatementEventListener listener) { - } - - private final class PooledJdbcConnection implements Connection { - - private boolean closed; - - private PooledJdbcConnection() { - this.closed = false; - } - - @Override - public void close() throws SQLException { - if (!this.closed) { - try { - if (!LrcoXAConnection.this.physicalConnection.getAutoCommit()) { - LrcoXAConnection.this.physicalConnection.rollback(); - } - LrcoXAConnection.this.physicalConnection.setAutoCommit(true); - } catch (SQLException e) { - // ignore - } - closeHandle(); - this.closed = true; - } - } - - @Override - public Statement createStatement() throws SQLException { - return LrcoXAConnection.this.physicalConnection.createStatement(); - } - - @Override - public PreparedStatement prepareStatement(String string) throws SQLException { - return LrcoXAConnection.this.physicalConnection.prepareStatement(string); - } - - @Override - public CallableStatement prepareCall(String string) throws SQLException { - return LrcoXAConnection.this.physicalConnection.prepareCall(string); - } - - @Override - public String nativeSQL(String string) throws SQLException { - return LrcoXAConnection.this.physicalConnection.nativeSQL(string); - } - - @Override - public void setAutoCommit(boolean autoCommit) throws SQLException { - LrcoXAConnection.this.physicalConnection.setAutoCommit(autoCommit); - } - - @Override - public boolean getAutoCommit() throws SQLException { - return LrcoXAConnection.this.physicalConnection.getAutoCommit(); - } - - @Override - public void commit() throws SQLException { - LrcoXAConnection.this.physicalConnection.commit(); - } - - @Override - public void rollback() throws SQLException { - LrcoXAConnection.this.physicalConnection.rollback(); - } - - @Override - public boolean isClosed() throws SQLException { - return LrcoXAConnection.this.physicalConnection.isClosed(); - } - - @Override - public DatabaseMetaData getMetaData() throws SQLException { - return LrcoXAConnection.this.physicalConnection.getMetaData(); - } - - @Override - public void setReadOnly(boolean readOnly) throws SQLException { - LrcoXAConnection.this.physicalConnection.setReadOnly(readOnly); - } - - @Override - public boolean isReadOnly() throws SQLException { - return LrcoXAConnection.this.physicalConnection.isReadOnly(); - } - - @Override - public void setCatalog(String string) throws SQLException { - LrcoXAConnection.this.physicalConnection.setCatalog(string); - } - - @Override - public String getCatalog() throws SQLException { - return LrcoXAConnection.this.physicalConnection.getCatalog(); - } - - @Override - public void setTransactionIsolation(int level) throws SQLException { - LrcoXAConnection.this.physicalConnection.setTransactionIsolation(level); - } - - @Override - public int getTransactionIsolation() throws SQLException { - return LrcoXAConnection.this.physicalConnection.getTransactionIsolation(); - } - - @Override - public SQLWarning getWarnings() throws SQLException { - return LrcoXAConnection.this.physicalConnection.getWarnings(); - } - - @Override - public void clearWarnings() throws SQLException { - LrcoXAConnection.this.physicalConnection.clearWarnings(); - } - - @Override - public Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLException { - return LrcoXAConnection.this.physicalConnection.createStatement(resultSetType, resultSetConcurrency); - } - - @Override - public PreparedStatement prepareStatement(String string, int i, int i1) throws SQLException { - return LrcoXAConnection.this.physicalConnection.prepareStatement(string, i, i1); - } - - @Override - public CallableStatement prepareCall(String string, int i, int i1) throws SQLException { - return LrcoXAConnection.this.physicalConnection.prepareCall(string, i, i1); - } - - @Override - public Map> getTypeMap() throws SQLException { - return LrcoXAConnection.this.physicalConnection.getTypeMap(); - } - - @Override - public void setTypeMap(Map> map) throws SQLException { - LrcoXAConnection.this.physicalConnection.setTypeMap(map); - } - - @Override - public void setHoldability(int holdability) throws SQLException { - LrcoXAConnection.this.physicalConnection.setHoldability(holdability); - } - - @Override - public int getHoldability() throws SQLException { - return LrcoXAConnection.this.physicalConnection.getHoldability(); - } - - @Override - public Savepoint setSavepoint() throws SQLException { - return LrcoXAConnection.this.physicalConnection.setSavepoint(); - } - - @Override - public Savepoint setSavepoint(String string) throws SQLException { - return LrcoXAConnection.this.physicalConnection.setSavepoint(string); - } - - @Override - public void rollback(Savepoint savepoint) throws SQLException { - LrcoXAConnection.this.physicalConnection.rollback(savepoint); - } - - @Override - public void releaseSavepoint(Savepoint savepoint) throws SQLException { - LrcoXAConnection.this.physicalConnection.releaseSavepoint(savepoint); - } - - @Override - public Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException { - return LrcoXAConnection.this.physicalConnection.createStatement(resultSetType, resultSetConcurrency, resultSetHoldability); - } - - @Override - public PreparedStatement prepareStatement(String string, int i, int i1, int i2) throws SQLException { - return LrcoXAConnection.this.physicalConnection.prepareStatement(string, i, i1, i2); - } - - @Override - public CallableStatement prepareCall(String string, int i, int i1, int i2) throws SQLException { - return LrcoXAConnection.this.physicalConnection.prepareCall(string, i, i1, i2); - } - - @Override - public PreparedStatement prepareStatement(String string, int i) throws SQLException { - return LrcoXAConnection.this.physicalConnection.prepareStatement(string, i); - } - - @Override - public PreparedStatement prepareStatement(String string, int[] ints) throws SQLException { - return LrcoXAConnection.this.physicalConnection.prepareStatement(string, ints); - } - - @Override - public PreparedStatement prepareStatement(String string, String[] strings) throws SQLException { - return LrcoXAConnection.this.physicalConnection.prepareStatement(string, strings); - } - - @Override - public Clob createClob() throws SQLException { - return LrcoXAConnection.this.physicalConnection.createClob(); - } - - @Override - public Blob createBlob() throws SQLException { - return LrcoXAConnection.this.physicalConnection.createBlob(); - } - - @Override - public NClob createNClob() throws SQLException { - return LrcoXAConnection.this.physicalConnection.createNClob(); - } - - @Override - public SQLXML createSQLXML() throws SQLException { - return LrcoXAConnection.this.physicalConnection.createSQLXML(); - } - - @Override - public boolean isValid(int timeout) throws SQLException { - return LrcoXAConnection.this.physicalConnection.isValid(timeout); - } - - @Override - public void setClientInfo(String string, String string1) throws SQLClientInfoException { - LrcoXAConnection.this.physicalConnection.setClientInfo(string, string1); - } - - @Override - public void setClientInfo(Properties prprts) throws SQLClientInfoException { - LrcoXAConnection.this.physicalConnection.setClientInfo(prprts); - } - - @Override - public String getClientInfo(String string) throws SQLException { - return LrcoXAConnection.this.physicalConnection.getClientInfo(string); - } - - @Override - public Properties getClientInfo() throws SQLException { - return LrcoXAConnection.this.physicalConnection.getClientInfo(); - } - - @Override - public Array createArrayOf(String string, Object[] os) throws SQLException { - return LrcoXAConnection.this.physicalConnection.createArrayOf(string, os); - } - - @Override - public Struct createStruct(String string, Object[] os) throws SQLException { - return LrcoXAConnection.this.physicalConnection.createStruct(string, os); - } - - @Override - public void setSchema(String string) throws SQLException { - LrcoXAConnection.this.physicalConnection.setSchema(string); - } - - @Override - public String getSchema() throws SQLException { - return LrcoXAConnection.this.physicalConnection.getSchema(); - } - - @Override - public void abort(Executor exctr) throws SQLException { - LrcoXAConnection.this.physicalConnection.abort(exctr); - } - - @Override - public void setNetworkTimeout(Executor exctr, int i) throws SQLException { - LrcoXAConnection.this.physicalConnection.setNetworkTimeout(exctr, i); - } - - @Override - public int getNetworkTimeout() throws SQLException { - return LrcoXAConnection.this.physicalConnection.getNetworkTimeout(); - } - - @Override - public T unwrap(Class type) throws SQLException { - return LrcoXAConnection.this.physicalConnection.unwrap(type); - } - - @Override - public boolean isWrapperFor(Class type) throws SQLException { - return LrcoXAConnection.this.physicalConnection.isWrapperFor(type); - } - } -} diff --git a/narayana-spring-boot-core/src/main/java/me/snowdrop/boot/narayana/core/jdbc/lrco/LrcoXADataSource.java b/narayana-spring-boot-core/src/main/java/me/snowdrop/boot/narayana/core/jdbc/lrco/LrcoXADataSource.java deleted file mode 100644 index 3bbf9314..00000000 --- a/narayana-spring-boot-core/src/main/java/me/snowdrop/boot/narayana/core/jdbc/lrco/LrcoXADataSource.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright 2020 Red Hat, Inc, and individual contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package me.snowdrop.boot.narayana.core.jdbc.lrco; - -import java.io.PrintWriter; -import java.sql.Driver; -import java.sql.SQLException; -import java.sql.SQLFeatureNotSupportedException; -import java.util.Properties; -import java.util.logging.Logger; - -import javax.sql.XAConnection; -import javax.sql.XADataSource; - -public class LrcoXADataSource implements XADataSource { - - private final Driver driver; - private final String url; - private final Properties info; - - public LrcoXADataSource(Driver driver, String url, String username, String password) { - this.driver = driver; - this.url = url; - this.info = new Properties(); - if (username != null) { - this.info.setProperty("user", username); - } - if (password != null) { - this.info.setProperty("password", password); - } - } - - @Override - public XAConnection getXAConnection() throws SQLException { - return new LrcoXAConnection(this.driver.connect(this.url, this.info)); - } - - @Override - public XAConnection getXAConnection(String user, String password) throws SQLException { - Properties info = new Properties(this.info); - info.put("user", user); - info.put("password", password); - return new LrcoXAConnection(this.driver.connect(this.url, info)); - } - - @Override - public PrintWriter getLogWriter() throws SQLException { - throw new UnsupportedOperationException("getLogWriter"); - } - - @Override - public void setLogWriter(PrintWriter out) throws SQLException { - throw new UnsupportedOperationException("setLogWriter"); - } - - @Override - public int getLoginTimeout() throws SQLException { - return 0; - } - - @Override - public void setLoginTimeout(int seconds) throws SQLException { - throw new UnsupportedOperationException("setLoginTimeout"); - } - - @Override - public Logger getParentLogger() throws SQLFeatureNotSupportedException { - return this.driver.getParentLogger(); - } -} diff --git a/narayana-spring-boot-core/src/main/java/me/snowdrop/boot/narayana/core/jdbc/lrco/LrcoXAResource.java b/narayana-spring-boot-core/src/main/java/me/snowdrop/boot/narayana/core/jdbc/lrco/LrcoXAResource.java deleted file mode 100644 index c81af853..00000000 --- a/narayana-spring-boot-core/src/main/java/me/snowdrop/boot/narayana/core/jdbc/lrco/LrcoXAResource.java +++ /dev/null @@ -1,153 +0,0 @@ -/* - * Copyright 2020 Red Hat, Inc, and individual contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package me.snowdrop.boot.narayana.core.jdbc.lrco; - -import java.sql.Connection; -import java.sql.SQLException; -import java.util.Objects; - -import javax.transaction.xa.XAException; -import javax.transaction.xa.XAResource; -import javax.transaction.xa.Xid; - -import com.arjuna.ats.jta.resources.LastResourceCommitOptimisation; - -public class LrcoXAResource implements LastResourceCommitOptimisation { - - private final Connection connection; - private Xid currentXid; - - public LrcoXAResource(Connection connection) { - this.connection = connection; - } - - private static XAException convertException(SQLException ex) { - XAException xa = new XAException(ex.getMessage()); - xa.initCause(ex); - return xa; - } - - @Override - public synchronized void start(Xid xid, int flags) throws XAException { - switch (flags) { - case XAResource.TMNOFLAGS: - if (this.currentXid != null) { - throw new XAException("Already enlisted in another transaction with xid " + xid); - } - try { - this.connection.setAutoCommit(false); - } catch (SQLException ex) { - throw (XAException) new XAException("Count not turn off auto commit for a XA transaction") - .initCause(ex); - } - this.currentXid = xid; - break; - case XAResource.TMRESUME: - if (!xid.equals(this.currentXid)) { - throw new XAException("Attempting to resume in different transaction: expected " + this.currentXid - + ", but was " + xid); - } - break; - default: - throw new XAException("unknown state: " + flags); - } - } - - @Override - public synchronized void end(Xid xid, int flags) throws XAException { - // Should not be called - throw new XAException(XAException.XAER_PROTO); - } - - @Override - public synchronized int prepare(Xid xid) throws XAException { - // Should not be called - throw new XAException(XAException.XAER_PROTO); - } - - @Override - public synchronized void commit(Xid xid, boolean onePhase) throws XAException { - Objects.requireNonNull(xid, "xid is null"); - if (!this.currentXid.equals(xid)) { - throw new XAException("Invalid Xid: expected " + this.currentXid + ", but was " + xid); - } - try { - if (this.connection.isClosed()) { - throw new XAException("Connection is closed"); - } - if (!this.connection.isReadOnly()) { - this.connection.commit(); - } - } catch (SQLException ex) { - throw convertException(ex); - } finally { - try { - this.connection.setAutoCommit(true); - } catch (final SQLException ex) { - // ignore - } - this.currentXid = null; - } - } - - @Override - public synchronized void rollback(Xid xid) throws XAException { - Objects.requireNonNull(xid, "xid is null"); - if (!this.currentXid.equals(xid)) { - throw new XAException("Invalid Xid: expected " + this.currentXid + ", but was " + xid); - } - try { - this.connection.rollback(); - } catch (SQLException ex) { - throw convertException(ex); - } finally { - try { - this.connection.setAutoCommit(true); - } catch (final SQLException ex) { - // ignore - } - this.currentXid = null; - } - } - - @Override - public Xid[] recover(int flag) throws XAException { - return new Xid[0]; - } - - @Override - public void forget(Xid xid) throws XAException { - // Should not be called - throw new XAException(XAException.XAER_PROTO); - } - - @Override - public boolean isSameRM(XAResource xares) throws XAException { - return this == xares; - } - - @Override - public int getTransactionTimeout() throws XAException { - // Should not be called - throw new XAException(XAException.XAER_PROTO); - } - - @Override - public boolean setTransactionTimeout(int seconds) throws XAException { - return false; - } -} diff --git a/narayana-spring-boot-core/src/main/java/me/snowdrop/boot/narayana/core/jms/AbstractXAConnectionFactoryWrapper.java b/narayana-spring-boot-core/src/main/java/me/snowdrop/boot/narayana/core/jms/AbstractXAConnectionFactoryWrapper.java index 6716fb47..2199a7d6 100644 --- a/narayana-spring-boot-core/src/main/java/me/snowdrop/boot/narayana/core/jms/AbstractXAConnectionFactoryWrapper.java +++ b/narayana-spring-boot-core/src/main/java/me/snowdrop/boot/narayana/core/jms/AbstractXAConnectionFactoryWrapper.java @@ -16,8 +16,8 @@ package me.snowdrop.boot.narayana.core.jms; -import javax.jms.ConnectionFactory; -import javax.jms.XAConnectionFactory; +import jakarta.jms.ConnectionFactory; +import jakarta.jms.XAConnectionFactory; import com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule; import com.arjuna.ats.jta.recovery.XAResourceRecoveryHelper; diff --git a/narayana-spring-boot-core/src/main/java/me/snowdrop/boot/narayana/core/jms/GenericXAConnectionFactoryWrapper.java b/narayana-spring-boot-core/src/main/java/me/snowdrop/boot/narayana/core/jms/GenericXAConnectionFactoryWrapper.java index 8580d14f..5701d5b4 100644 --- a/narayana-spring-boot-core/src/main/java/me/snowdrop/boot/narayana/core/jms/GenericXAConnectionFactoryWrapper.java +++ b/narayana-spring-boot-core/src/main/java/me/snowdrop/boot/narayana/core/jms/GenericXAConnectionFactoryWrapper.java @@ -16,9 +16,9 @@ package me.snowdrop.boot.narayana.core.jms; -import javax.jms.ConnectionFactory; -import javax.jms.XAConnectionFactory; -import javax.transaction.TransactionManager; +import jakarta.jms.ConnectionFactory; +import jakarta.jms.XAConnectionFactory; +import jakarta.transaction.TransactionManager; import com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule; import me.snowdrop.boot.narayana.core.properties.RecoveryCredentialsProperties; diff --git a/narayana-spring-boot-core/src/main/java/me/snowdrop/boot/narayana/core/jms/PooledXAConnectionFactoryWrapper.java b/narayana-spring-boot-core/src/main/java/me/snowdrop/boot/narayana/core/jms/PooledXAConnectionFactoryWrapper.java index e19e49c8..a5be3832 100644 --- a/narayana-spring-boot-core/src/main/java/me/snowdrop/boot/narayana/core/jms/PooledXAConnectionFactoryWrapper.java +++ b/narayana-spring-boot-core/src/main/java/me/snowdrop/boot/narayana/core/jms/PooledXAConnectionFactoryWrapper.java @@ -16,9 +16,9 @@ package me.snowdrop.boot.narayana.core.jms; -import javax.jms.ConnectionFactory; -import javax.jms.XAConnectionFactory; -import javax.transaction.TransactionManager; +import jakarta.jms.ConnectionFactory; +import jakarta.jms.XAConnectionFactory; +import jakarta.transaction.TransactionManager; import com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule; import me.snowdrop.boot.narayana.core.properties.MessagingHubConnectionFactoryProperties; diff --git a/narayana-spring-boot-core/src/main/java/me/snowdrop/boot/narayana/core/properties/NarayanaProperties.java b/narayana-spring-boot-core/src/main/java/me/snowdrop/boot/narayana/core/properties/NarayanaProperties.java index 0dd01629..0e3320b3 100644 --- a/narayana-spring-boot-core/src/main/java/me/snowdrop/boot/narayana/core/properties/NarayanaProperties.java +++ b/narayana-spring-boot-core/src/main/java/me/snowdrop/boot/narayana/core/properties/NarayanaProperties.java @@ -19,9 +19,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; -import java.util.HashMap; import java.util.List; -import java.util.Map; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.NestedConfigurationProperty; @@ -103,12 +101,6 @@ public class NarayanaProperties { private List expiryScanners = new ArrayList<>(Collections.singletonList( "com.arjuna.ats.internal.arjuna.recovery.ExpiredTransactionStatusManagerScanner")); - /** - * Map of DBCP specific properties used if pooled data source wrapper is enabled. - * See https://commons.apache.org/proper/commons-dbcp/configuration.html for the list of supported properties. - */ - private Map dbcp = new HashMap<>(); - /** * MessagingHub specific properties used if pooled connection factory wrapper is enabled. * See https://github.com/messaginghub/pooled-jms/blob/master/pooled-jms-docs/Configuration.md for the list of supported properties. @@ -201,26 +193,6 @@ public void setRecoveryDbCredentials(RecoveryCredentialsProperties recoveryDbCre this.recoveryDbCredentials = recoveryDbCredentials; } - @Deprecated - public String getRecoveryDbUser() { - return this.recoveryDbCredentials.getUser(); - } - - @Deprecated - public void setRecoveryDbUser(String recoveryDbUser) { - this.recoveryDbCredentials.setUser(recoveryDbUser); - } - - @Deprecated - public String getRecoveryDbPass() { - return this.recoveryDbCredentials.getPassword(); - } - - @Deprecated - public void setRecoveryDbPass(String recoveryDbPass) { - this.recoveryDbCredentials.setPassword(recoveryDbPass); - } - public RecoveryCredentialsProperties getRecoveryJmsCredentials() { return this.recoveryJmsCredentials; } @@ -229,34 +201,6 @@ public void setRecoveryJmsCredentials(RecoveryCredentialsProperties recoveryJmsC this.recoveryJmsCredentials = recoveryJmsCredentials; } - @Deprecated - public String getRecoveryJmsUser() { - return this.recoveryJmsCredentials.getUser(); - } - - @Deprecated - public void setRecoveryJmsUser(String recoveryJmsUser) { - this.recoveryJmsCredentials.setUser(recoveryJmsUser); - } - - @Deprecated - public String getRecoveryJmsPass() { - return this.recoveryJmsCredentials.getUser(); - } - - @Deprecated - public void setRecoveryJmsPass(String recoveryJmsPass) { - this.recoveryJmsCredentials.setPassword(recoveryJmsPass); - } - - public Map getDbcp() { - return this.dbcp; - } - - public void setDbcp(Map dbcp) { - this.dbcp = dbcp; - } - public MessagingHubConnectionFactoryProperties getMessaginghub() { return this.messaginghub; } diff --git a/narayana-spring-boot-core/src/test/java/me/snowdrop/boot/narayana/core/jdbc/NarayanaDataSourceTests.java b/narayana-spring-boot-core/src/test/java/me/snowdrop/boot/narayana/core/jdbc/NarayanaDataSourceTests.java index a339297e..1f96bcdd 100644 --- a/narayana-spring-boot-core/src/test/java/me/snowdrop/boot/narayana/core/jdbc/NarayanaDataSourceTests.java +++ b/narayana-spring-boot-core/src/test/java/me/snowdrop/boot/narayana/core/jdbc/NarayanaDataSourceTests.java @@ -17,6 +17,7 @@ package me.snowdrop.boot.narayana.core.jdbc; import java.sql.Connection; +import java.sql.DatabaseMetaData; import java.sql.SQLException; import java.util.Properties; @@ -80,8 +81,13 @@ void shouldUnwrapXaDataSource() throws SQLException { @Test void shouldGetConnectionAndCommit() throws SQLException { + DatabaseMetaData mockMetaData = mock(DatabaseMetaData.class); Connection mockConnection = mock(Connection.class); XAConnection mockXaConnection = mock(XAConnection.class); + given(mockMetaData.getDriverName()).willReturn("mock"); + given(mockMetaData.getDriverMajorVersion()).willReturn(1); + given(mockMetaData.getDriverMinorVersion()).willReturn(0); + given(mockConnection.getMetaData()).willReturn(mockMetaData); given(mockXaConnection.getConnection()).willReturn(mockConnection); given(this.mockXaDataSource.getXAConnection()).willReturn(mockXaConnection); @@ -103,8 +109,13 @@ void shouldGetConnectionAndCommit() throws SQLException { void shouldGetConnectionAndCommitWithCredentials() throws SQLException { String username = "testUsername"; String password = "testPassword"; + DatabaseMetaData mockMetaData = mock(DatabaseMetaData.class); Connection mockConnection = mock(Connection.class); XAConnection mockXaConnection = mock(XAConnection.class); + given(mockMetaData.getDriverName()).willReturn("mock"); + given(mockMetaData.getDriverMajorVersion()).willReturn(1); + given(mockMetaData.getDriverMinorVersion()).willReturn(0); + given(mockConnection.getMetaData()).willReturn(mockMetaData); given(mockXaConnection.getConnection()).willReturn(mockConnection); given(this.mockXaDataSource.getXAConnection(username, password)).willReturn(mockXaConnection); diff --git a/narayana-spring-boot-core/src/test/java/me/snowdrop/boot/narayana/core/jdbc/PooledXADataSourceWrapperTests.java b/narayana-spring-boot-core/src/test/java/me/snowdrop/boot/narayana/core/jdbc/PooledXADataSourceWrapperTests.java deleted file mode 100644 index 274bbd67..00000000 --- a/narayana-spring-boot-core/src/test/java/me/snowdrop/boot/narayana/core/jdbc/PooledXADataSourceWrapperTests.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright 2020 Red Hat, Inc, and individual contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package me.snowdrop.boot.narayana.core.jdbc; - -import java.util.Collections; -import java.util.Map; - -import javax.sql.DataSource; -import javax.sql.XADataSource; -import javax.transaction.TransactionManager; - -import com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule; -import me.snowdrop.boot.narayana.core.properties.RecoveryCredentialsProperties; -import org.apache.commons.dbcp2.managed.BasicManagedDataSource; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.BDDMockito.given; -import static org.mockito.Mockito.verify; - -/** - * @author Gytis Trikleris - */ -@ExtendWith(MockitoExtension.class) -class PooledXADataSourceWrapperTests { - - @Mock - private XADataSource mockXaDataSource; - - @Mock - private XARecoveryModule mockXaRecoveryModule; - - private Map dbcpProperties; - - @Mock - private RecoveryCredentialsProperties mockRecoveryCredentialsProperties; - - @Mock - private TransactionManager mockTransactionManager; - - private PooledXADataSourceWrapper wrapper; - - @BeforeEach - void before() { - this.dbcpProperties = Collections.singletonMap("username", "test-user"); - this.wrapper = new PooledXADataSourceWrapper(this.mockTransactionManager, this.mockXaRecoveryModule, - this.dbcpProperties, this.mockRecoveryCredentialsProperties); - } - - @Test - void wrap() throws Exception { - given(this.mockRecoveryCredentialsProperties.isValid()).willReturn(false); - - DataSource dataSource = this.wrapper.wrapDataSource(this.mockXaDataSource); - assertThat(dataSource).isInstanceOf(BasicManagedDataSource.class); - - BasicManagedDataSource basicManagedDataSource = (BasicManagedDataSource) dataSource; - assertThat(basicManagedDataSource.getTransactionManager()).isEqualTo(this.mockTransactionManager); - assertThat(basicManagedDataSource.getXaDataSourceInstance()).isEqualTo(this.mockXaDataSource); - assertThat(basicManagedDataSource.getUsername()).isEqualTo("test-user"); - - verify(this.mockXaRecoveryModule).addXAResourceRecoveryHelper(any(DataSourceXAResourceRecoveryHelper.class)); - verify(this.mockRecoveryCredentialsProperties).isValid(); - } - - @Test - void wrapWithCredentials() throws Exception { - given(this.mockRecoveryCredentialsProperties.isValid()).willReturn(true); - given(this.mockRecoveryCredentialsProperties.getUser()).willReturn("userName"); - given(this.mockRecoveryCredentialsProperties.getPassword()).willReturn("password"); - - DataSource dataSource = this.wrapper.wrapDataSource(this.mockXaDataSource); - assertThat(dataSource).isInstanceOf(BasicManagedDataSource.class); - - BasicManagedDataSource basicManagedDataSource = (BasicManagedDataSource) dataSource; - assertThat(basicManagedDataSource.getTransactionManager()).isEqualTo(this.mockTransactionManager); - assertThat(basicManagedDataSource.getXaDataSourceInstance()).isEqualTo(this.mockXaDataSource); - - verify(this.mockXaRecoveryModule).addXAResourceRecoveryHelper(any(DataSourceXAResourceRecoveryHelper.class)); - verify(this.mockRecoveryCredentialsProperties).getUser(); - verify(this.mockRecoveryCredentialsProperties).getPassword(); - } -} diff --git a/narayana-spring-boot-core/src/test/java/me/snowdrop/boot/narayana/core/jms/GenericXAConnectionFactoryWrapperTests.java b/narayana-spring-boot-core/src/test/java/me/snowdrop/boot/narayana/core/jms/GenericXAConnectionFactoryWrapperTests.java index 2a6af51d..66c6b394 100644 --- a/narayana-spring-boot-core/src/test/java/me/snowdrop/boot/narayana/core/jms/GenericXAConnectionFactoryWrapperTests.java +++ b/narayana-spring-boot-core/src/test/java/me/snowdrop/boot/narayana/core/jms/GenericXAConnectionFactoryWrapperTests.java @@ -16,9 +16,9 @@ package me.snowdrop.boot.narayana.core.jms; -import javax.jms.ConnectionFactory; -import javax.jms.XAConnectionFactory; -import javax.transaction.TransactionManager; +import jakarta.jms.ConnectionFactory; +import jakarta.jms.XAConnectionFactory; +import jakarta.transaction.TransactionManager; import com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule; import me.snowdrop.boot.narayana.core.properties.RecoveryCredentialsProperties; diff --git a/narayana-spring-boot-core/src/test/java/me/snowdrop/boot/narayana/core/jms/PooledXAConnectionFactoryWrapperTest.java b/narayana-spring-boot-core/src/test/java/me/snowdrop/boot/narayana/core/jms/PooledXAConnectionFactoryWrapperTest.java index 8ac2bf71..aa48f14f 100644 --- a/narayana-spring-boot-core/src/test/java/me/snowdrop/boot/narayana/core/jms/PooledXAConnectionFactoryWrapperTest.java +++ b/narayana-spring-boot-core/src/test/java/me/snowdrop/boot/narayana/core/jms/PooledXAConnectionFactoryWrapperTest.java @@ -16,9 +16,9 @@ package me.snowdrop.boot.narayana.core.jms; -import javax.jms.ConnectionFactory; -import javax.jms.XAConnectionFactory; -import javax.transaction.TransactionManager; +import jakarta.jms.ConnectionFactory; +import jakarta.jms.XAConnectionFactory; +import jakarta.transaction.TransactionManager; import com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule; import me.snowdrop.boot.narayana.core.properties.MessagingHubConnectionFactoryProperties; diff --git a/narayana-spring-boot-samples/narayana-spring-boot-sample-2ds/pom.xml b/narayana-spring-boot-samples/narayana-spring-boot-sample-2ds/pom.xml index 15040671..6465654b 100644 --- a/narayana-spring-boot-samples/narayana-spring-boot-sample-2ds/pom.xml +++ b/narayana-spring-boot-samples/narayana-spring-boot-sample-2ds/pom.xml @@ -4,7 +4,7 @@ me.snowdrop narayana-spring-boot-samples - 2.6.7-SNAPSHOT + 3.0.0-SNAPSHOT narayana-spring-boot-sample-2ds diff --git a/narayana-spring-boot-samples/narayana-spring-boot-sample-2ds/src/main/java/me/snowdrop/narayana/sample/DataSourceConfiguration.java b/narayana-spring-boot-samples/narayana-spring-boot-sample-2ds/src/main/java/me/snowdrop/narayana/sample/DataSourceConfiguration.java index b5844550..cfb7c847 100644 --- a/narayana-spring-boot-samples/narayana-spring-boot-sample-2ds/src/main/java/me/snowdrop/narayana/sample/DataSourceConfiguration.java +++ b/narayana-spring-boot-samples/narayana-spring-boot-sample-2ds/src/main/java/me/snowdrop/narayana/sample/DataSourceConfiguration.java @@ -19,13 +19,11 @@ import java.sql.Connection; import java.sql.SQLException; import java.sql.Statement; -import java.util.HashMap; import javax.sql.DataSource; -import javax.transaction.TransactionManager; import com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule; -import me.snowdrop.boot.narayana.core.jdbc.PooledXADataSourceWrapper; +import me.snowdrop.boot.narayana.core.jdbc.GenericXADataSourceWrapper; import org.h2.jdbcx.JdbcDataSource; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -34,22 +32,22 @@ public class DataSourceConfiguration { @Bean(name = "ds1") - public DataSource firstDataSource(TransactionManager transactionManager, XARecoveryModule xaRecoveryModule) throws Exception { + public DataSource firstDataSource(XARecoveryModule xaRecoveryModule) throws Exception { JdbcDataSource h2XaDataSource = new JdbcDataSource(); h2XaDataSource.setURL("jdbc:h2:mem:ds1;DB_CLOSE_DELAY=-1"); createDummyTable(h2XaDataSource); - PooledXADataSourceWrapper wrapper = new PooledXADataSourceWrapper(transactionManager, xaRecoveryModule, new HashMap<>()); + GenericXADataSourceWrapper wrapper = new GenericXADataSourceWrapper(xaRecoveryModule); return wrapper.wrapDataSource(h2XaDataSource); } @Bean(name = "ds2") - public DataSource secondDataSource(TransactionManager transactionManager, XARecoveryModule xaRecoveryModule) throws Exception { + public DataSource secondDataSource(XARecoveryModule xaRecoveryModule) throws Exception { JdbcDataSource h2XaDataSource = new JdbcDataSource(); h2XaDataSource.setURL("jdbc:h2:mem:ds2;DB_CLOSE_DELAY=-1"); createDummyTable(h2XaDataSource); - PooledXADataSourceWrapper wrapper = new PooledXADataSourceWrapper(transactionManager, xaRecoveryModule, new HashMap<>()); + GenericXADataSourceWrapper wrapper = new GenericXADataSourceWrapper(xaRecoveryModule); return wrapper.wrapDataSource(h2XaDataSource); } diff --git a/narayana-spring-boot-samples/narayana-spring-boot-sample-2ds/src/main/java/me/snowdrop/narayana/sample/ScheduledExecutor.java b/narayana-spring-boot-samples/narayana-spring-boot-sample-2ds/src/main/java/me/snowdrop/narayana/sample/ScheduledExecutor.java index efda03db..897c0b32 100644 --- a/narayana-spring-boot-samples/narayana-spring-boot-sample-2ds/src/main/java/me/snowdrop/narayana/sample/ScheduledExecutor.java +++ b/narayana-spring-boot-samples/narayana-spring-boot-sample-2ds/src/main/java/me/snowdrop/narayana/sample/ScheduledExecutor.java @@ -19,7 +19,8 @@ import java.util.Random; import javax.sql.DataSource; -import javax.transaction.Transactional; + +import jakarta.transaction.Transactional; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.jdbc.core.JdbcTemplate; diff --git a/narayana-spring-boot-samples/narayana-spring-boot-sample-2pc/pom.xml b/narayana-spring-boot-samples/narayana-spring-boot-sample-2pc/pom.xml index 2d25bd0a..8c05ff0e 100644 --- a/narayana-spring-boot-samples/narayana-spring-boot-sample-2pc/pom.xml +++ b/narayana-spring-boot-samples/narayana-spring-boot-sample-2pc/pom.xml @@ -4,7 +4,7 @@ me.snowdrop narayana-spring-boot-samples - 2.6.7-SNAPSHOT + 3.0.0-SNAPSHOT narayana-spring-boot-sample-2pc @@ -32,7 +32,7 @@ org.apache.activemq - artemis-jms-server + artemis-jakarta-server org.springframework.boot diff --git a/narayana-spring-boot-samples/narayana-spring-boot-sample-2pc/src/main/java/me/snowdrop/narayana/sample/ScheduledExecutor.java b/narayana-spring-boot-samples/narayana-spring-boot-sample-2pc/src/main/java/me/snowdrop/narayana/sample/ScheduledExecutor.java index 688bcdf2..474c375c 100644 --- a/narayana-spring-boot-samples/narayana-spring-boot-sample-2pc/src/main/java/me/snowdrop/narayana/sample/ScheduledExecutor.java +++ b/narayana-spring-boot-samples/narayana-spring-boot-sample-2pc/src/main/java/me/snowdrop/narayana/sample/ScheduledExecutor.java @@ -18,7 +18,7 @@ import java.util.List; -import javax.transaction.Transactional; +import jakarta.transaction.Transactional; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; diff --git a/narayana-spring-boot-samples/narayana-spring-boot-sample-2pc/src/main/java/me/snowdrop/narayana/sample/UserService.java b/narayana-spring-boot-samples/narayana-spring-boot-sample-2pc/src/main/java/me/snowdrop/narayana/sample/UserService.java index ec948a81..ab41ee10 100644 --- a/narayana-spring-boot-samples/narayana-spring-boot-sample-2pc/src/main/java/me/snowdrop/narayana/sample/UserService.java +++ b/narayana-spring-boot-samples/narayana-spring-boot-sample-2pc/src/main/java/me/snowdrop/narayana/sample/UserService.java @@ -18,7 +18,7 @@ import java.util.List; -import javax.transaction.Transactional; +import jakarta.transaction.Transactional; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jms.core.JmsTemplate; diff --git a/narayana-spring-boot-samples/pom.xml b/narayana-spring-boot-samples/pom.xml index b79f58f8..1f9ab8c6 100644 --- a/narayana-spring-boot-samples/pom.xml +++ b/narayana-spring-boot-samples/pom.xml @@ -4,7 +4,7 @@ me.snowdrop narayana-spring-boot-parent - 2.6.7-SNAPSHOT + 3.0.0-SNAPSHOT narayana-spring-boot-samples diff --git a/narayana-spring-boot-starter-it/pom.xml b/narayana-spring-boot-starter-it/pom.xml index 9eca04c6..ccaffa54 100644 --- a/narayana-spring-boot-starter-it/pom.xml +++ b/narayana-spring-boot-starter-it/pom.xml @@ -19,7 +19,7 @@ me.snowdrop narayana-spring-boot-parent - 2.6.7-SNAPSHOT + 3.0.0-SNAPSHOT narayana-spring-boot-starter-it @@ -49,9 +49,15 @@ spring-boot-starter-test test + + io.agroal + agroal-spring-boot-starter + ${agroal.version} + test + org.apache.activemq - artemis-jms-server + artemis-jakarta-server test diff --git a/narayana-spring-boot-starter-it/src/test/java/me/snowdrop/boot/narayana/app/EntriesService.java b/narayana-spring-boot-starter-it/src/test/java/me/snowdrop/boot/narayana/app/EntriesService.java index f6e2f109..82feceb3 100644 --- a/narayana-spring-boot-starter-it/src/test/java/me/snowdrop/boot/narayana/app/EntriesService.java +++ b/narayana-spring-boot-starter-it/src/test/java/me/snowdrop/boot/narayana/app/EntriesService.java @@ -18,7 +18,7 @@ import java.util.List; -import javax.transaction.Transactional; +import jakarta.transaction.Transactional; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/narayana-spring-boot-starter-it/src/test/java/me/snowdrop/boot/narayana/app/Entry.java b/narayana-spring-boot-starter-it/src/test/java/me/snowdrop/boot/narayana/app/Entry.java index 6abf3fec..e3a09206 100644 --- a/narayana-spring-boot-starter-it/src/test/java/me/snowdrop/boot/narayana/app/Entry.java +++ b/narayana-spring-boot-starter-it/src/test/java/me/snowdrop/boot/narayana/app/Entry.java @@ -18,9 +18,9 @@ import java.util.Objects; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.Id; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.Id; /** * @author Gytis Trikleris diff --git a/narayana-spring-boot-starter-it/src/test/java/me/snowdrop/boot/narayana/app/MessagesService.java b/narayana-spring-boot-starter-it/src/test/java/me/snowdrop/boot/narayana/app/MessagesService.java index cc31089a..7765d2ab 100644 --- a/narayana-spring-boot-starter-it/src/test/java/me/snowdrop/boot/narayana/app/MessagesService.java +++ b/narayana-spring-boot-starter-it/src/test/java/me/snowdrop/boot/narayana/app/MessagesService.java @@ -19,7 +19,7 @@ import java.util.LinkedList; import java.util.List; -import javax.transaction.Transactional; +import jakarta.transaction.Transactional; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/narayana-spring-boot-starter-it/src/test/java/me/snowdrop/boot/narayana/generic/GenericRecoveryIT.java b/narayana-spring-boot-starter-it/src/test/java/me/snowdrop/boot/narayana/generic/GenericRecoveryIT.java index fe125a5e..97a1b70a 100644 --- a/narayana-spring-boot-starter-it/src/test/java/me/snowdrop/boot/narayana/generic/GenericRecoveryIT.java +++ b/narayana-spring-boot-starter-it/src/test/java/me/snowdrop/boot/narayana/generic/GenericRecoveryIT.java @@ -20,11 +20,13 @@ import java.util.LinkedList; import java.util.List; -import javax.transaction.TransactionManager; import javax.transaction.xa.XAResource; import javax.transaction.xa.Xid; +import jakarta.transaction.TransactionManager; + import com.arjuna.ats.jta.recovery.XAResourceRecoveryHelper; +import io.agroal.springframework.boot.AgroalDataSourceConfiguration; import me.snowdrop.boot.narayana.app.EntriesService; import me.snowdrop.boot.narayana.app.Entry; import me.snowdrop.boot.narayana.app.MessagesService; @@ -38,6 +40,7 @@ import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.test.context.SpringBootTest; import static org.assertj.core.api.Assertions.assertThat; @@ -53,6 +56,7 @@ @WithByteman @BMUnitConfig @SpringBootTest(classes = TestApplication.class) +@EnableAutoConfiguration(exclude = AgroalDataSourceConfiguration.class) public class GenericRecoveryIT { @Mock @@ -72,7 +76,7 @@ public class GenericRecoveryIT { @BeforeEach void before() { - MockitoAnnotations.initMocks(this); + MockitoAnnotations.openMocks(this); this.messagesService.clearReceivedMessages(); this.entriesService.clearEntries(); BytemanHelper.reset(); @@ -107,6 +111,7 @@ void testCrashBeforeCommit() throws Exception { await("Wait for the recovery to happen") .atMost(Duration.ofSeconds(30)) + .pollInterval(Duration.ofSeconds(1)) .untilAsserted(() -> { assertMessagesAfterRecovery(this.messagesService.getReceivedMessages()); assertEntriesAfterRecovery(this.entriesService.getEntries()); diff --git a/narayana-spring-boot-starter-it/src/test/java/me/snowdrop/boot/narayana/generic/GenericTransactionalIT.java b/narayana-spring-boot-starter-it/src/test/java/me/snowdrop/boot/narayana/generic/GenericTransactionalIT.java index 25527d4e..f1cc87b8 100644 --- a/narayana-spring-boot-starter-it/src/test/java/me/snowdrop/boot/narayana/generic/GenericTransactionalIT.java +++ b/narayana-spring-boot-starter-it/src/test/java/me/snowdrop/boot/narayana/generic/GenericTransactionalIT.java @@ -18,9 +18,10 @@ import java.time.Duration; -import javax.transaction.Transaction; -import javax.transaction.TransactionManager; +import jakarta.transaction.Transaction; +import jakarta.transaction.TransactionManager; +import io.agroal.springframework.boot.AgroalDataSourceConfiguration; import me.snowdrop.boot.narayana.app.EntriesService; import me.snowdrop.boot.narayana.app.Entry; import me.snowdrop.boot.narayana.app.MessagesService; @@ -29,6 +30,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.test.context.SpringBootTest; import static org.assertj.core.api.Assertions.assertThat; @@ -38,6 +40,7 @@ * @author Gytis Trikleris */ @SpringBootTest(classes = TestApplication.class) +@EnableAutoConfiguration(exclude = AgroalDataSourceConfiguration.class) public class GenericTransactionalIT { @Autowired diff --git a/narayana-spring-boot-starter-it/src/test/java/me/snowdrop/boot/narayana/lrco/LrcoPooledRecoveryIT.java b/narayana-spring-boot-starter-it/src/test/java/me/snowdrop/boot/narayana/lrco/LrcoPooledRecoveryIT.java deleted file mode 100644 index 58e53e24..00000000 --- a/narayana-spring-boot-starter-it/src/test/java/me/snowdrop/boot/narayana/lrco/LrcoPooledRecoveryIT.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright 2020 Red Hat, Inc, and individual contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package me.snowdrop.boot.narayana.lrco; - -import java.util.List; - -import me.snowdrop.boot.narayana.app.Entry; -import me.snowdrop.boot.narayana.app.TestApplication; -import me.snowdrop.boot.narayana.generic.GenericRecoveryIT; -import org.springframework.boot.test.context.SpringBootTest; - -import static org.assertj.core.api.Assertions.assertThat; - -@SpringBootTest(classes = TestApplication.class, properties = {"narayana.dbcp.enabled=true", "narayana.messaginghub.enabled=true", "narayana.lrco.enabled=true"}) -public class LrcoPooledRecoveryIT extends GenericRecoveryIT { - - @Override - protected void assertEntriesAfterCrash(List entries) { - // LRCO resource is committed last, while others get prepared only. - assertThat(entries) - .as("Test entry should exist because resource was committed before crash") - .hasSize(1); - } -} diff --git a/narayana-spring-boot-starter-it/src/test/java/me/snowdrop/boot/narayana/lrco/LrcoPooledTransactionalIT.java b/narayana-spring-boot-starter-it/src/test/java/me/snowdrop/boot/narayana/lrco/LrcoPooledTransactionalIT.java deleted file mode 100644 index 8a9c0700..00000000 --- a/narayana-spring-boot-starter-it/src/test/java/me/snowdrop/boot/narayana/lrco/LrcoPooledTransactionalIT.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright 2020 Red Hat, Inc, and individual contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package me.snowdrop.boot.narayana.lrco; - -import me.snowdrop.boot.narayana.app.TestApplication; -import me.snowdrop.boot.narayana.generic.GenericTransactionalIT; -import org.springframework.boot.test.context.SpringBootTest; - -@SpringBootTest(classes = TestApplication.class, properties = {"narayana.dbcp.enabled=true", "narayana.messaginghub.enabled=true", "narayana.lrco.enabled=true"}) -public class LrcoPooledTransactionalIT extends GenericTransactionalIT { -} diff --git a/narayana-spring-boot-starter-it/src/test/java/me/snowdrop/boot/narayana/pooled/PooledRecoveryIT.java b/narayana-spring-boot-starter-it/src/test/java/me/snowdrop/boot/narayana/pooled/PooledRecoveryIT.java index 392984a3..cd58809a 100644 --- a/narayana-spring-boot-starter-it/src/test/java/me/snowdrop/boot/narayana/pooled/PooledRecoveryIT.java +++ b/narayana-spring-boot-starter-it/src/test/java/me/snowdrop/boot/narayana/pooled/PooledRecoveryIT.java @@ -18,11 +18,13 @@ import me.snowdrop.boot.narayana.app.TestApplication; import me.snowdrop.boot.narayana.generic.GenericRecoveryIT; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.test.context.SpringBootTest; /** * @author Gytis Trikleris */ -@SpringBootTest(classes = TestApplication.class, properties = {"narayana.dbcp.enabled=true", "narayana.messaginghub.enabled=true"}) +@SpringBootTest(classes = TestApplication.class, properties = "narayana.messaginghub.enabled=true") +@EnableAutoConfiguration public class PooledRecoveryIT extends GenericRecoveryIT { } diff --git a/narayana-spring-boot-starter-it/src/test/java/me/snowdrop/boot/narayana/pooled/PooledTransactionalIT.java b/narayana-spring-boot-starter-it/src/test/java/me/snowdrop/boot/narayana/pooled/PooledTransactionalIT.java index e0799e9c..2dbfb048 100644 --- a/narayana-spring-boot-starter-it/src/test/java/me/snowdrop/boot/narayana/pooled/PooledTransactionalIT.java +++ b/narayana-spring-boot-starter-it/src/test/java/me/snowdrop/boot/narayana/pooled/PooledTransactionalIT.java @@ -18,11 +18,13 @@ import me.snowdrop.boot.narayana.app.TestApplication; import me.snowdrop.boot.narayana.generic.GenericTransactionalIT; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.test.context.SpringBootTest; /** * @author Gytis Trikleris */ -@SpringBootTest(classes = TestApplication.class, properties = {"narayana.dbcp.enabled=true", "narayana.messaginghub.enabled=true"}) +@SpringBootTest(classes = TestApplication.class, properties = "narayana.messaginghub.enabled=true") +@EnableAutoConfiguration public class PooledTransactionalIT extends GenericTransactionalIT { } diff --git a/narayana-spring-boot-starter/pom.xml b/narayana-spring-boot-starter/pom.xml index 51c66243..3515b8b9 100644 --- a/narayana-spring-boot-starter/pom.xml +++ b/narayana-spring-boot-starter/pom.xml @@ -19,7 +19,7 @@ me.snowdrop narayana-spring-boot-parent - 2.6.7-SNAPSHOT + 3.0.0-SNAPSHOT narayana-spring-boot-starter @@ -43,8 +43,8 @@ true - javax.jms - javax.jms-api + jakarta.jms + jakarta.jms-api true diff --git a/narayana-spring-boot-starter/src/main/java/me/snowdrop/boot/narayana/autoconfigure/NarayanaBeanFactoryPostProcessor.java b/narayana-spring-boot-starter/src/main/java/me/snowdrop/boot/narayana/autoconfigure/NarayanaBeanFactoryPostProcessor.java index f12061d2..057c0492 100644 --- a/narayana-spring-boot-starter/src/main/java/me/snowdrop/boot/narayana/autoconfigure/NarayanaBeanFactoryPostProcessor.java +++ b/narayana-spring-boot-starter/src/main/java/me/snowdrop/boot/narayana/autoconfigure/NarayanaBeanFactoryPostProcessor.java @@ -16,7 +16,7 @@ package me.snowdrop.boot.narayana.autoconfigure; -import javax.transaction.TransactionManager; +import jakarta.transaction.TransactionManager; import com.arjuna.ats.jbossatx.jta.RecoveryManagerService; import org.springframework.beans.BeansException; @@ -41,8 +41,8 @@ public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) String[] recoveryManagerServices = beanFactory.getBeanNamesForType(RecoveryManagerService.class, true, false); addBeanDependencies(beanFactory, transactionManagers, "javax.sql.DataSource"); addBeanDependencies(beanFactory, recoveryManagerServices, "javax.sql.DataSource"); - addBeanDependencies(beanFactory, transactionManagers, "javax.jms.ConnectionFactory"); - addBeanDependencies(beanFactory, recoveryManagerServices, "javax.jms.ConnectionFactory"); + addBeanDependencies(beanFactory, transactionManagers, "jakarta.jms.ConnectionFactory"); + addBeanDependencies(beanFactory, recoveryManagerServices, "jakarta.jms.ConnectionFactory"); } private void addBeanDependencies(ConfigurableListableBeanFactory beanFactory, String[] beanNames, diff --git a/narayana-spring-boot-starter/src/main/java/me/snowdrop/boot/narayana/autoconfigure/NarayanaConfiguration.java b/narayana-spring-boot-starter/src/main/java/me/snowdrop/boot/narayana/autoconfigure/NarayanaConfiguration.java index 6bd58e95..09be5b7f 100644 --- a/narayana-spring-boot-starter/src/main/java/me/snowdrop/boot/narayana/autoconfigure/NarayanaConfiguration.java +++ b/narayana-spring-boot-starter/src/main/java/me/snowdrop/boot/narayana/autoconfigure/NarayanaConfiguration.java @@ -18,18 +18,17 @@ import java.io.File; -import javax.jms.Message; -import javax.transaction.Transaction; -import javax.transaction.TransactionManager; -import javax.transaction.TransactionSynchronizationRegistry; -import javax.transaction.UserTransaction; +import jakarta.jms.Message; +import jakarta.transaction.Transaction; +import jakarta.transaction.TransactionManager; +import jakarta.transaction.TransactionSynchronizationRegistry; +import jakarta.transaction.UserTransaction; import com.arjuna.ats.arjuna.recovery.RecoveryManager; import com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule; import com.arjuna.ats.jbossatx.jta.RecoveryManagerService; import com.arjuna.ats.jta.common.jtaPropertyManager; import me.snowdrop.boot.narayana.core.jdbc.GenericXADataSourceWrapper; -import me.snowdrop.boot.narayana.core.jdbc.PooledXADataSourceWrapper; import me.snowdrop.boot.narayana.core.jms.GenericXAConnectionFactoryWrapper; import me.snowdrop.boot.narayana.core.jms.PooledXAConnectionFactoryWrapper; import me.snowdrop.boot.narayana.core.properties.NarayanaProperties; @@ -42,7 +41,6 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.autoconfigure.transaction.TransactionManagerCustomizers; import org.springframework.boot.autoconfigure.transaction.jta.JtaAutoConfiguration; -import org.springframework.boot.autoconfigure.transaction.jta.JtaProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.jdbc.XADataSourceWrapper; import org.springframework.boot.jms.XAConnectionFactoryWrapper; @@ -60,10 +58,7 @@ * @author Gytis Trikleris */ @Configuration -@EnableConfigurationProperties({ - JtaProperties.class, - NarayanaProperties.class -}) +@EnableConfigurationProperties(NarayanaProperties.class) @ConditionalOnProperty(prefix = "spring.jta", value = "enabled", matchIfMissing = true) @ConditionalOnClass({ Transaction.class, @@ -75,13 +70,9 @@ @AutoConfigureBefore(JtaAutoConfiguration.class) public class NarayanaConfiguration { - private final JtaProperties jtaProperties; - private final TransactionManagerCustomizers transactionManagerCustomizers; - public NarayanaConfiguration(JtaProperties jtaProperties, - ObjectProvider transactionManagerCustomizers) { - this.jtaProperties = jtaProperties; + public NarayanaConfiguration(ObjectProvider transactionManagerCustomizers) { this.transactionManagerCustomizers = transactionManagerCustomizers.getIfAvailable(); } @@ -95,7 +86,6 @@ public static NarayanaBeanFactoryPostProcessor narayanaBeanFactoryPostProcessor( @ConditionalOnMissingBean public NarayanaPropertiesInitializer narayanaPropertiesInitializer(NarayanaProperties properties) { initLogDir(properties); - initTransactionManagerId(properties); return new NarayanaPropertiesInitializer(properties); } @@ -152,31 +142,14 @@ public XARecoveryModule xaRecoveryModule() { } private void initLogDir(NarayanaProperties properties) { - if (!StringUtils.isEmpty(properties.getLogDir())) { + if (StringUtils.hasText(properties.getLogDir())) { return; } - if (!StringUtils.isEmpty(this.jtaProperties.getLogDir())) { - properties.setLogDir(this.jtaProperties.getLogDir()); - } else { - properties.setLogDir(getLogDir().getAbsolutePath()); - } - } - - private void initTransactionManagerId(NarayanaProperties properties) { - if (!StringUtils.isEmpty(properties.getTransactionManagerId())) { - return; - } - - if (!StringUtils.isEmpty(this.jtaProperties.getTransactionManagerId())) { - properties.setTransactionManagerId(this.jtaProperties.getTransactionManagerId()); - } + properties.setLogDir(getLogDir().getAbsolutePath()); } private File getLogDir() { - if (StringUtils.hasLength(this.jtaProperties.getLogDir())) { - return new File(this.jtaProperties.getLogDir()); - } File home = new ApplicationHome().getDir(); return new File(home, "transaction-logs"); } @@ -184,7 +157,6 @@ private File getLogDir() { /** * Generic data source wrapper configuration. */ - @ConditionalOnProperty(name = "narayana.dbcp.enabled", havingValue = "false", matchIfMissing = true) static class GenericJdbcConfiguration { @Bean @@ -197,23 +169,6 @@ public XADataSourceWrapper xaDataSourceWrapper(NarayanaProperties narayanaProper } - /** - * Pooled data source wrapper configuration. - */ - @ConditionalOnProperty(name = "narayana.dbcp.enabled", havingValue = "true") - static class PooledJdbcConfiguration { - - @Bean - @ConditionalOnMissingBean(XADataSourceWrapper.class) - public XADataSourceWrapper xaDataSourceWrapper(NarayanaProperties narayanaProperties, - XARecoveryModule xaRecoveryModule, TransactionManager transactionManager) { - return new PooledXADataSourceWrapper(transactionManager, xaRecoveryModule, - narayanaProperties.getDbcp(), - narayanaProperties.getRecoveryDbCredentials()); - } - - } - /** * JMS connection factory wrapper configuration. */ diff --git a/narayana-spring-boot-starter/src/main/java/me/snowdrop/boot/narayana/autoconfigure/NarayanaLrcoXADataSourceAutoConfiguration.java b/narayana-spring-boot-starter/src/main/java/me/snowdrop/boot/narayana/autoconfigure/NarayanaLrcoXADataSourceAutoConfiguration.java deleted file mode 100644 index 94d0d9cf..00000000 --- a/narayana-spring-boot-starter/src/main/java/me/snowdrop/boot/narayana/autoconfigure/NarayanaLrcoXADataSourceAutoConfiguration.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright 2020 Red Hat, Inc, and individual contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package me.snowdrop.boot.narayana.autoconfigure; - -import java.sql.Driver; - -import javax.sql.XADataSource; - -import me.snowdrop.boot.narayana.core.jdbc.lrco.LrcoXADataSource; -import org.springframework.beans.BeanUtils; -import org.springframework.boot.autoconfigure.AutoConfigureAfter; -import org.springframework.boot.autoconfigure.AutoConfigureBefore; -import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; -import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties; -import org.springframework.boot.autoconfigure.jdbc.XADataSourceAutoConfiguration; -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.boot.jdbc.XADataSourceWrapper; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.util.ClassUtils; - -@Configuration(proxyBeanMethods = false) -@AutoConfigureBefore(XADataSourceAutoConfiguration.class) -@AutoConfigureAfter(NarayanaConfiguration.class) -@EnableConfigurationProperties(DataSourceProperties.class) -@ConditionalOnProperty(name = {"narayana.dbcp.enabled", "narayana.lrco.enabled"}) -@ConditionalOnBean(XADataSourceWrapper.class) -@ConditionalOnMissingBean(XADataSource.class) -public class NarayanaLrcoXADataSourceAutoConfiguration { - - @Bean - public XADataSource xaDataSource(DataSourceProperties properties) { - return createXaDataSource(properties); - } - - private LrcoXADataSource createXaDataSource(DataSourceProperties properties) { - Driver driver = createDriver(properties.determineDriverClassName(), properties.getClassLoader()); - String url = properties.determineUrl(); - String username = properties.determineUsername(); - String password = properties.determinePassword(); - return new LrcoXADataSource(driver, url, username, password); - } - - private Driver createDriver(String className, ClassLoader classLoader) { - Class clazz = ClassUtils.resolveClassName(className, classLoader); - Object instance = BeanUtils.instantiateClass(clazz); - return (Driver) instance; - } -} diff --git a/narayana-spring-boot-starter/src/main/resources/META-INF/spring.factories b/narayana-spring-boot-starter/src/main/resources/META-INF/spring.factories deleted file mode 100644 index abfc8363..00000000 --- a/narayana-spring-boot-starter/src/main/resources/META-INF/spring.factories +++ /dev/null @@ -1,3 +0,0 @@ -org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ -me.snowdrop.boot.narayana.autoconfigure.NarayanaConfiguration,\ -me.snowdrop.boot.narayana.autoconfigure.NarayanaLrcoXADataSourceAutoConfiguration \ No newline at end of file diff --git a/narayana-spring-boot-starter/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/narayana-spring-boot-starter/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports new file mode 100644 index 00000000..cb34b948 --- /dev/null +++ b/narayana-spring-boot-starter/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -0,0 +1 @@ +me.snowdrop.boot.narayana.autoconfigure.NarayanaConfiguration diff --git a/narayana-spring-boot-starter/src/test/java/me/snowdrop/boot/narayana/autoconfigure/NarayanaBeanFactoryPostProcessorTests.java b/narayana-spring-boot-starter/src/test/java/me/snowdrop/boot/narayana/autoconfigure/NarayanaBeanFactoryPostProcessorTests.java index 1963d1d0..413060fe 100644 --- a/narayana-spring-boot-starter/src/test/java/me/snowdrop/boot/narayana/autoconfigure/NarayanaBeanFactoryPostProcessorTests.java +++ b/narayana-spring-boot-starter/src/test/java/me/snowdrop/boot/narayana/autoconfigure/NarayanaBeanFactoryPostProcessorTests.java @@ -16,9 +16,10 @@ package me.snowdrop.boot.narayana.autoconfigure; -import javax.jms.ConnectionFactory; import javax.sql.DataSource; -import javax.transaction.TransactionManager; + +import jakarta.jms.ConnectionFactory; +import jakarta.transaction.TransactionManager; import com.arjuna.ats.jbossatx.jta.RecoveryManagerService; import org.junit.jupiter.api.Test; diff --git a/narayana-spring-boot-starter/src/test/java/me/snowdrop/boot/narayana/autoconfigure/NarayanaConfigurationIT.java b/narayana-spring-boot-starter/src/test/java/me/snowdrop/boot/narayana/autoconfigure/NarayanaConfigurationIT.java index daad6a79..60302a46 100644 --- a/narayana-spring-boot-starter/src/test/java/me/snowdrop/boot/narayana/autoconfigure/NarayanaConfigurationIT.java +++ b/narayana-spring-boot-starter/src/test/java/me/snowdrop/boot/narayana/autoconfigure/NarayanaConfigurationIT.java @@ -19,14 +19,13 @@ import java.io.File; import java.util.Properties; -import javax.transaction.TransactionManager; -import javax.transaction.TransactionSynchronizationRegistry; -import javax.transaction.UserTransaction; +import jakarta.transaction.TransactionManager; +import jakarta.transaction.TransactionSynchronizationRegistry; +import jakarta.transaction.UserTransaction; import com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule; import com.arjuna.ats.jbossatx.jta.RecoveryManagerService; import me.snowdrop.boot.narayana.core.jdbc.GenericXADataSourceWrapper; -import me.snowdrop.boot.narayana.core.jdbc.PooledXADataSourceWrapper; import me.snowdrop.boot.narayana.core.jms.GenericXAConnectionFactoryWrapper; import me.snowdrop.boot.narayana.core.jms.PooledXAConnectionFactoryWrapper; import me.snowdrop.boot.narayana.core.properties.NarayanaProperties; @@ -89,23 +88,6 @@ void recoveryDbCredentialsShouldBeLoaded() { assertThat(narayanaProperties.getRecoveryDbCredentials().getPassword()).isEqualTo("password"); } - @Test - void recoveryDbCredentialsShouldBeLoadedForDeprecatedMethods() { - Properties properties = new Properties(); - properties.put("narayana.recoveryDbUser", "userName"); - properties.put("narayana.recoveryDbPass", "password"); - PropertiesPropertySource propertySource = new PropertiesPropertySource("test", properties); - - this.context = new AnnotationConfigApplicationContext(); - this.context.register(NarayanaConfiguration.class); - this.context.getEnvironment().getPropertySources().addFirst(propertySource); - this.context.refresh(); - - NarayanaProperties narayanaProperties = this.context.getBean(NarayanaProperties.class); - assertThat(narayanaProperties.getRecoveryDbCredentials().getUser()).isEqualTo("userName"); - assertThat(narayanaProperties.getRecoveryDbCredentials().getPassword()).isEqualTo("password"); - } - @Test void recoveryJmsCredentialsShouldBeLoaded() { Properties properties = new Properties(); @@ -123,23 +105,6 @@ void recoveryJmsCredentialsShouldBeLoaded() { assertThat(narayanaProperties.getRecoveryJmsCredentials().getPassword()).isEqualTo("password"); } - @Test - void recoveryJmsCredentialsShouldBeLoadedForDeprecatedMethods() { - Properties properties = new Properties(); - properties.put("narayana.recoveryJmsUser", "userName"); - properties.put("narayana.recoveryJmsPass", "password"); - PropertiesPropertySource propertySource = new PropertiesPropertySource("test", properties); - - this.context = new AnnotationConfigApplicationContext(); - this.context.register(NarayanaConfiguration.class); - this.context.getEnvironment().getPropertySources().addFirst(propertySource); - this.context.refresh(); - - NarayanaProperties narayanaProperties = this.context.getBean(NarayanaProperties.class); - assertThat(narayanaProperties.getRecoveryJmsCredentials().getUser()).isEqualTo("userName"); - assertThat(narayanaProperties.getRecoveryJmsCredentials().getPassword()).isEqualTo("password"); - } - @Test void genericXaDataSourceWrapperShouldBeLoaded() { Properties properties = new Properties(); @@ -155,25 +120,9 @@ void genericXaDataSourceWrapperShouldBeLoaded() { assertThat(xaDataSourceWrapper).isInstanceOf(GenericXADataSourceWrapper.class); } - @Test - void pooledXaDataSourceWrapperShouldBeLoaded() { - Properties properties = new Properties(); - properties.put("narayana.dbcp.enabled", "true"); - PropertiesPropertySource propertySource = new PropertiesPropertySource("test", properties); - - this.context = new AnnotationConfigApplicationContext(); - this.context.register(NarayanaConfiguration.class); - this.context.getEnvironment().getPropertySources().addFirst(propertySource); - this.context.refresh(); - - XADataSourceWrapper xaDataSourceWrapper = this.context.getBean(XADataSourceWrapper.class); - assertThat(xaDataSourceWrapper).isInstanceOf(PooledXADataSourceWrapper.class); - } - @Test void genericXaConnectionFactoryWrapperShouldBeLoaded() { Properties properties = new Properties(); - properties.put("narayana.messaginghub.enabled", "false"); PropertiesPropertySource propertySource = new PropertiesPropertySource("test", properties); this.context = new AnnotationConfigApplicationContext(); diff --git a/narayana-spring-boot-starter/src/test/java/me/snowdrop/boot/narayana/autoconfigure/NarayanaConfigurationTest.java b/narayana-spring-boot-starter/src/test/java/me/snowdrop/boot/narayana/autoconfigure/NarayanaConfigurationTest.java index 010a5728..92d655c3 100644 --- a/narayana-spring-boot-starter/src/test/java/me/snowdrop/boot/narayana/autoconfigure/NarayanaConfigurationTest.java +++ b/narayana-spring-boot-starter/src/test/java/me/snowdrop/boot/narayana/autoconfigure/NarayanaConfigurationTest.java @@ -18,9 +18,9 @@ import java.io.File; -import javax.transaction.TransactionManager; -import javax.transaction.TransactionSynchronizationRegistry; -import javax.transaction.UserTransaction; +import jakarta.transaction.TransactionManager; +import jakarta.transaction.TransactionSynchronizationRegistry; +import jakarta.transaction.UserTransaction; import me.snowdrop.boot.narayana.core.properties.NarayanaProperties; import org.junit.jupiter.api.BeforeEach; @@ -30,7 +30,6 @@ import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.beans.factory.ObjectProvider; import org.springframework.boot.autoconfigure.transaction.TransactionManagerCustomizers; -import org.springframework.boot.autoconfigure.transaction.jta.JtaProperties; import org.springframework.boot.system.ApplicationHome; import org.springframework.transaction.jta.JtaTransactionManager; @@ -46,9 +45,6 @@ @ExtendWith(MockitoExtension.class) class NarayanaConfigurationTest { - @Mock - private JtaProperties mockJtaProperties; - @Mock private ObjectProvider mockTransactionManagerCustomizersProvider; @@ -71,8 +67,7 @@ class NarayanaConfigurationTest { @BeforeEach void before() { - this.configuration = new NarayanaConfiguration(this.mockJtaProperties, - this.mockTransactionManagerCustomizersProvider); + this.configuration = new NarayanaConfiguration(this.mockTransactionManagerCustomizersProvider); } @Test @@ -82,13 +77,6 @@ void narayanaPropertiesInitializerShouldUseNarayanaLogDir() { verify(this.mockNarayanaProperties, times(0)).setLogDir(anyString()); } - @Test - void narayanaPropertiesInitializerShouldUseSpringJtaLogDir() { - given(this.mockJtaProperties.getLogDir()).willReturn("spring-jta-log-dir"); - this.configuration.narayanaPropertiesInitializer(this.mockNarayanaProperties); - verify(this.mockNarayanaProperties).setLogDir("spring-jta-log-dir"); - } - @Test void narayanaPropertiesInitializerShouldUseDefaultLogDir() { this.configuration.narayanaPropertiesInitializer(this.mockNarayanaProperties); @@ -97,20 +85,6 @@ void narayanaPropertiesInitializerShouldUseDefaultLogDir() { verify(this.mockNarayanaProperties).setLogDir(expectedLogDir.getAbsolutePath()); } - @Test - void narayanaPropertiesInitializerShouldUseNarayanaTransactionManagerId() { - given(this.mockNarayanaProperties.getTransactionManagerId()).willReturn("narayana-manager-id"); - this.configuration.narayanaPropertiesInitializer(this.mockNarayanaProperties); - verify(this.mockNarayanaProperties, times(0)).setTransactionManagerId(anyString()); - } - - @Test - void narayanaPropertiesInitializerShouldUseSpringJtaTransactionManagerId() { - given(this.mockJtaProperties.getTransactionManagerId()).willReturn("spring-jta-manager-id"); - this.configuration.narayanaPropertiesInitializer(this.mockNarayanaProperties); - verify(this.mockNarayanaProperties).setTransactionManagerId("spring-jta-manager-id"); - } - @Test void jtaTransactionManagerShouldBeCreated() { JtaTransactionManager jtaTransactionManager = this.configuration.transactionManager( @@ -125,8 +99,7 @@ void jtaTransactionManagerShouldBeCreated() { void jtaTransactionManagerShouldBeCustomized() { given(this.mockTransactionManagerCustomizersProvider.getIfAvailable()).willReturn( this.mockTransactionManagerCustomizers); - this.configuration = new NarayanaConfiguration(this.mockJtaProperties, - this.mockTransactionManagerCustomizersProvider); + this.configuration = new NarayanaConfiguration(this.mockTransactionManagerCustomizersProvider); JtaTransactionManager jtaTransactionManager = this.configuration.transactionManager( this.mockUserTransaction, this.mockTransactionManager, this.mockTransactionSynchronizationRegistry); verify(this.mockTransactionManagerCustomizers).customize(jtaTransactionManager); diff --git a/narayana-spring-boot-starter/src/test/java/me/snowdrop/boot/narayana/autoconfigure/NarayanaLrcoXADataSourceAutoConfigurationIT.java b/narayana-spring-boot-starter/src/test/java/me/snowdrop/boot/narayana/autoconfigure/NarayanaLrcoXADataSourceAutoConfigurationIT.java deleted file mode 100644 index 03dbcad1..00000000 --- a/narayana-spring-boot-starter/src/test/java/me/snowdrop/boot/narayana/autoconfigure/NarayanaLrcoXADataSourceAutoConfigurationIT.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright 2020 Red Hat, Inc, and individual contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package me.snowdrop.boot.narayana.autoconfigure; - -import java.util.Properties; - -import javax.sql.XADataSource; - -import me.snowdrop.boot.narayana.core.jdbc.lrco.LrcoXADataSource; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Test; -import org.springframework.context.annotation.AnnotationConfigApplicationContext; -import org.springframework.core.env.PropertiesPropertySource; - -import static org.assertj.core.api.Assertions.assertThat; - -class NarayanaLrcoXADataSourceAutoConfigurationIT { - - private AnnotationConfigApplicationContext context; - - @AfterEach - void closeContext() { - if (this.context != null) { - this.context.close(); - } - } - - @Test - void lrcoXADataSourceShouldBeLoaded() { - Properties properties = new Properties(); - properties.put("narayana.dbcp.enabled", "true"); - properties.put("narayana.lrco.enabled", "true"); - PropertiesPropertySource propertySource = new PropertiesPropertySource("test", properties); - - this.context = new AnnotationConfigApplicationContext(); - this.context.getEnvironment().getPropertySources().addFirst(propertySource); - this.context.register( - NarayanaConfiguration.class, - NarayanaLrcoXADataSourceAutoConfiguration.class); - this.context.refresh(); - - XADataSource xaDataSource = this.context.getBean(XADataSource.class); - assertThat(xaDataSource).isInstanceOf(LrcoXADataSource.class); - } -} diff --git a/openshift/recovery-controller/pom.xml b/openshift/recovery-controller/pom.xml index e409c3ea..9c8a73e9 100644 --- a/openshift/recovery-controller/pom.xml +++ b/openshift/recovery-controller/pom.xml @@ -19,7 +19,7 @@ me.snowdrop narayana-spring-boot-parent - 2.6.7-SNAPSHOT + 3.0.0-SNAPSHOT ../../pom.xml diff --git a/openshift/recovery-controller/src/main/resources/META-INF/spring.factories b/openshift/recovery-controller/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports similarity index 53% rename from openshift/recovery-controller/src/main/resources/META-INF/spring.factories rename to openshift/recovery-controller/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports index 9135a6fb..7e35a693 100644 --- a/openshift/recovery-controller/src/main/resources/META-INF/spring.factories +++ b/openshift/recovery-controller/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -1,4 +1,3 @@ -org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ -me.snowdrop.boot.narayana.openshift.recovery.StatefulsetRecoveryControllerAutoConfiguration,\ -me.snowdrop.boot.narayana.openshift.recovery.NarayanaRecoveryTerminationControllerAutoConfiguration,\ -me.snowdrop.boot.narayana.openshift.recovery.camel.CamelServiceShutdownControllerAutoConfiguration \ No newline at end of file +me.snowdrop.boot.narayana.openshift.recovery.NarayanaRecoveryTerminationControllerAutoConfiguration +me.snowdrop.boot.narayana.openshift.recovery.StatefulsetRecoveryControllerAutoConfiguration +me.snowdrop.boot.narayana.openshift.recovery.camel.CamelServiceShutdownControllerAutoConfiguration diff --git a/pom.xml b/pom.xml index 6902d667..bc21fca0 100644 --- a/pom.xml +++ b/pom.xml @@ -18,7 +18,7 @@ 4.0.0 me.snowdrop narayana-spring-boot-parent - 2.6.7-SNAPSHOT + 3.0.0-SNAPSHOT pom Narayana Spring Boot :: parent @@ -46,28 +46,28 @@ ${basedir} false - 1.8 + 17 UTF-8 UTF-8 - 4.0.3 - 4.0.19 - 3.14.2 - 5.12.7.Final - 4.9.0 - 2.7.2 - 7.6.1.Final + 2.2-SNAPSHOT + 4.2.0 + 4.0.21 + 4.0.0-M3 + 6.0.1.Final + 6.6.2 + 3.1.0 - 3.1.1 - 3.8.1 - 2.8.2 - 3.0.0-M3 - 3.0.0-M5 - 3.2.0 - 3.2.0 - 2.5.3 - 3.0.0-M5 + 3.3.0 + 3.11.0 + 3.1.1 + 3.3.0 + 3.0.0 + 3.3.0 + 3.5.0 + 3.0.0 3.2.1 + 3.0.0 @@ -131,11 +131,6 @@ byteman-bmunit5 ${byteman.version} - - org.jboss - jboss-transaction-spi - ${jboss-transaction-spi.version} - @@ -216,7 +211,7 @@ src/checkstyle/checkstyle-suppressions.xml src/checkstyle/checkstyle-header.txt main.basedir=${main.basedir} - UTF-8 + UTF-8 true true true @@ -248,7 +243,7 @@ - [1.8,) + [17,) main.basedir @@ -383,7 +378,8 @@ narayana-spring-boot-core narayana-spring-boot-starter - narayana-spring-boot-starter-it + + openshift/recovery-controller diff --git a/src/checkstyle/checkstyle.xml b/src/checkstyle/checkstyle.xml index 4772d5f0..8bbb73da 100644 --- a/src/checkstyle/checkstyle.xml +++ b/src/checkstyle/checkstyle.xml @@ -78,7 +78,7 @@ - +