From 89f7d82b4a726cd5cb60b04a5a76e5d631b9f5ac Mon Sep 17 00:00:00 2001 From: Jeremy Landis Date: Tue, 2 Aug 2022 22:41:34 -0400 Subject: [PATCH 01/11] [jakarta] Move over all imports to jakarta from javax --- src/main/java/org/mybatis/cdi/CDIUtils.java | 16 +++++------ .../cdi/JtaTransactionInterceptor.java | 20 ++++++------- .../cdi/LocalTransactionInterceptor.java | 20 ++++++------- src/main/java/org/mybatis/cdi/Mapper.java | 2 +- .../java/org/mybatis/cdi/MyBatisBean.java | 12 ++++---- .../org/mybatis/cdi/MybatisExtension.java | 28 +++++++++---------- .../mybatis/cdi/SerializableMapperProxy.java | 4 +-- .../mybatis/cdi/SessionFactoryProvider.java | 2 +- .../cdi/SqlSessionManagerRegistry.java | 12 ++++---- .../java/org/mybatis/cdi/Transactional.java | 6 ++-- src/site/xdoc/getting-started.xml.vm | 4 +-- src/site/zh/xdoc/getting-started.xml.vm | 4 +-- src/test/java/org/mybatis/cdi/FooService.java | 8 +++--- .../java/org/mybatis/cdi/FooServiceJTA.java | 4 +-- .../org/mybatis/cdi/FooServiceJTATest.java | 6 ++-- .../java/org/mybatis/cdi/FooServiceTest.java | 4 +-- src/test/java/org/mybatis/cdi/JtaManager.java | 2 +- .../org/mybatis/cdi/ManagerProducers.java | 10 +++---- .../org/mybatis/cdi/ManagerProducersJta.java | 6 ++-- .../org/mybatis/cdi/MySpecialManager.java | 2 +- .../org/mybatis/cdi/MybatisExtensionTest.java | 18 ++++++------ .../java/org/mybatis/cdi/OtherQualifier.java | 2 +- .../mybatis/cdi/SerializableFooService.java | 4 +-- .../mybatis/cdi/UserTransactionProvider.java | 6 ++-- 24 files changed, 101 insertions(+), 101 deletions(-) diff --git a/src/main/java/org/mybatis/cdi/CDIUtils.java b/src/main/java/org/mybatis/cdi/CDIUtils.java index 499ee34b..defe7e48 100644 --- a/src/main/java/org/mybatis/cdi/CDIUtils.java +++ b/src/main/java/org/mybatis/cdi/CDIUtils.java @@ -19,16 +19,16 @@ import java.util.Iterator; import java.util.Set; -import javax.enterprise.context.spi.CreationalContext; -import javax.enterprise.inject.Any; -import javax.enterprise.inject.Default; -import javax.enterprise.inject.spi.Bean; -import javax.enterprise.inject.spi.BeanManager; -import javax.enterprise.inject.spi.CDI; -import javax.enterprise.util.AnnotationLiteral; - import org.apache.ibatis.session.SqlSessionFactory; +import jakarta.enterprise.context.spi.CreationalContext; +import jakarta.enterprise.inject.Any; +import jakarta.enterprise.inject.Default; +import jakarta.enterprise.inject.spi.Bean; +import jakarta.enterprise.inject.spi.BeanManager; +import jakarta.enterprise.inject.spi.CDI; +import jakarta.enterprise.util.AnnotationLiteral; + /** * @author Frank D. Martinez [mnesarco] */ diff --git a/src/main/java/org/mybatis/cdi/JtaTransactionInterceptor.java b/src/main/java/org/mybatis/cdi/JtaTransactionInterceptor.java index 2641ecdc..4ae8461b 100644 --- a/src/main/java/org/mybatis/cdi/JtaTransactionInterceptor.java +++ b/src/main/java/org/mybatis/cdi/JtaTransactionInterceptor.java @@ -15,16 +15,16 @@ */ package org.mybatis.cdi; -import javax.enterprise.inject.Instance; -import javax.inject.Inject; -import javax.interceptor.Interceptor; -import javax.transaction.HeuristicMixedException; -import javax.transaction.HeuristicRollbackException; -import javax.transaction.NotSupportedException; -import javax.transaction.RollbackException; -import javax.transaction.Status; -import javax.transaction.SystemException; -import javax.transaction.UserTransaction; +import jakarta.enterprise.inject.Instance; +import jakarta.inject.Inject; +import jakarta.interceptor.Interceptor; +import jakarta.transaction.HeuristicMixedException; +import jakarta.transaction.HeuristicRollbackException; +import jakarta.transaction.NotSupportedException; +import jakarta.transaction.RollbackException; +import jakarta.transaction.Status; +import jakarta.transaction.SystemException; +import jakarta.transaction.UserTransaction; /** * Interceptor for JTA transactions. MyBatis should be configured to use the {@code MANAGED} transaction manager. diff --git a/src/main/java/org/mybatis/cdi/LocalTransactionInterceptor.java b/src/main/java/org/mybatis/cdi/LocalTransactionInterceptor.java index 0e9f4d96..24f5f128 100644 --- a/src/main/java/org/mybatis/cdi/LocalTransactionInterceptor.java +++ b/src/main/java/org/mybatis/cdi/LocalTransactionInterceptor.java @@ -19,18 +19,18 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.UndeclaredThrowableException; -import javax.inject.Inject; -import javax.interceptor.AroundInvoke; -import javax.interceptor.Interceptor; -import javax.interceptor.InvocationContext; -import javax.transaction.HeuristicMixedException; -import javax.transaction.HeuristicRollbackException; -import javax.transaction.NotSupportedException; -import javax.transaction.RollbackException; -import javax.transaction.SystemException; - import org.apache.ibatis.session.SqlSessionManager; +import jakarta.inject.Inject; +import jakarta.interceptor.AroundInvoke; +import jakarta.interceptor.Interceptor; +import jakarta.interceptor.InvocationContext; +import jakarta.transaction.HeuristicMixedException; +import jakarta.transaction.HeuristicRollbackException; +import jakarta.transaction.NotSupportedException; +import jakarta.transaction.RollbackException; +import jakarta.transaction.SystemException; + /** * Best-effort interceptor for local transactions. It locates all the instances of {@code SqlSssionManager} and starts * transactions on all them. It cannot guarantee atomiticy if there is more than one {@code SqlSssionManager}. Use XA diff --git a/src/main/java/org/mybatis/cdi/Mapper.java b/src/main/java/org/mybatis/cdi/Mapper.java index b613caa6..213c08b9 100644 --- a/src/main/java/org/mybatis/cdi/Mapper.java +++ b/src/main/java/org/mybatis/cdi/Mapper.java @@ -22,7 +22,7 @@ import java.lang.annotation.Retention; import java.lang.annotation.Target; -import javax.enterprise.inject.Stereotype; +import jakarta.enterprise.inject.Stereotype; /** * Marker interface for MyBatis mappers. diff --git a/src/main/java/org/mybatis/cdi/MyBatisBean.java b/src/main/java/org/mybatis/cdi/MyBatisBean.java index 3884a568..90943407 100644 --- a/src/main/java/org/mybatis/cdi/MyBatisBean.java +++ b/src/main/java/org/mybatis/cdi/MyBatisBean.java @@ -23,17 +23,17 @@ import java.util.HashSet; import java.util.Set; -import javax.enterprise.context.Dependent; -import javax.enterprise.context.spi.CreationalContext; -import javax.enterprise.inject.spi.Bean; -import javax.enterprise.inject.spi.InjectionPoint; -import javax.enterprise.inject.spi.PassivationCapable; - import org.apache.ibatis.executor.ErrorContext; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionManager; +import jakarta.enterprise.context.Dependent; +import jakarta.enterprise.context.spi.CreationalContext; +import jakarta.enterprise.inject.spi.Bean; +import jakarta.enterprise.inject.spi.InjectionPoint; +import jakarta.enterprise.inject.spi.PassivationCapable; + /** * Internal CDI metadata for a mapper bean. * diff --git a/src/main/java/org/mybatis/cdi/MybatisExtension.java b/src/main/java/org/mybatis/cdi/MybatisExtension.java index 36033bf2..4e30613e 100644 --- a/src/main/java/org/mybatis/cdi/MybatisExtension.java +++ b/src/main/java/org/mybatis/cdi/MybatisExtension.java @@ -23,25 +23,25 @@ import java.util.List; import java.util.Set; -import javax.enterprise.event.Observes; -import javax.enterprise.inject.spi.AfterBeanDiscovery; -import javax.enterprise.inject.spi.AnnotatedMember; -import javax.enterprise.inject.spi.AnnotatedType; -import javax.enterprise.inject.spi.Extension; -import javax.enterprise.inject.spi.InjectionPoint; -import javax.enterprise.inject.spi.InjectionTarget; -import javax.enterprise.inject.spi.ProcessAnnotatedType; -import javax.enterprise.inject.spi.ProcessInjectionTarget; -import javax.enterprise.inject.spi.ProcessProducer; -import javax.enterprise.inject.spi.WithAnnotations; -import javax.inject.Named; -import javax.inject.Qualifier; - import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import jakarta.enterprise.event.Observes; +import jakarta.enterprise.inject.spi.AfterBeanDiscovery; +import jakarta.enterprise.inject.spi.AnnotatedMember; +import jakarta.enterprise.inject.spi.AnnotatedType; +import jakarta.enterprise.inject.spi.Extension; +import jakarta.enterprise.inject.spi.InjectionPoint; +import jakarta.enterprise.inject.spi.InjectionTarget; +import jakarta.enterprise.inject.spi.ProcessAnnotatedType; +import jakarta.enterprise.inject.spi.ProcessInjectionTarget; +import jakarta.enterprise.inject.spi.ProcessProducer; +import jakarta.enterprise.inject.spi.WithAnnotations; +import jakarta.inject.Named; +import jakarta.inject.Qualifier; + /** * MyBatis CDI extension. * diff --git a/src/main/java/org/mybatis/cdi/SerializableMapperProxy.java b/src/main/java/org/mybatis/cdi/SerializableMapperProxy.java index 8a45a70f..cedae03b 100644 --- a/src/main/java/org/mybatis/cdi/SerializableMapperProxy.java +++ b/src/main/java/org/mybatis/cdi/SerializableMapperProxy.java @@ -23,10 +23,10 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; -import javax.enterprise.context.spi.CreationalContext; - import org.apache.ibatis.session.SqlSessionFactory; +import jakarta.enterprise.context.spi.CreationalContext; + /** * @author Frank D. Martinez [mnesarco] */ diff --git a/src/main/java/org/mybatis/cdi/SessionFactoryProvider.java b/src/main/java/org/mybatis/cdi/SessionFactoryProvider.java index 6f83565b..4cb99ba7 100644 --- a/src/main/java/org/mybatis/cdi/SessionFactoryProvider.java +++ b/src/main/java/org/mybatis/cdi/SessionFactoryProvider.java @@ -22,7 +22,7 @@ import java.lang.annotation.Retention; import java.lang.annotation.Target; -import javax.enterprise.inject.Stereotype; +import jakarta.enterprise.inject.Stereotype; /** * Qualifies an SqlSessionFactory provider method as usable by mybatis-cdi. diff --git a/src/main/java/org/mybatis/cdi/SqlSessionManagerRegistry.java b/src/main/java/org/mybatis/cdi/SqlSessionManagerRegistry.java index 8783b557..14114b83 100644 --- a/src/main/java/org/mybatis/cdi/SqlSessionManagerRegistry.java +++ b/src/main/java/org/mybatis/cdi/SqlSessionManagerRegistry.java @@ -20,15 +20,15 @@ import java.util.HashMap; import java.util.Map; -import javax.annotation.PostConstruct; -import javax.enterprise.context.ApplicationScoped; -import javax.enterprise.inject.Any; -import javax.enterprise.inject.Instance; -import javax.inject.Inject; - import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionManager; +import jakarta.annotation.PostConstruct; +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.enterprise.inject.Any; +import jakarta.enterprise.inject.Instance; +import jakarta.inject.Inject; + /** * @author Frank D. Martinez [mnesarco] */ diff --git a/src/main/java/org/mybatis/cdi/Transactional.java b/src/main/java/org/mybatis/cdi/Transactional.java index 4dc7460a..fa640a38 100644 --- a/src/main/java/org/mybatis/cdi/Transactional.java +++ b/src/main/java/org/mybatis/cdi/Transactional.java @@ -20,11 +20,11 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; -import javax.enterprise.util.Nonbinding; -import javax.interceptor.InterceptorBinding; - import org.apache.ibatis.session.ExecutorType; +import jakarta.enterprise.util.Nonbinding; +import jakarta.interceptor.InterceptorBinding; + /** * Adds transaction demarcation to the annotated method. * diff --git a/src/site/xdoc/getting-started.xml.vm b/src/site/xdoc/getting-started.xml.vm index bf10f69b..1190566e 100644 --- a/src/site/xdoc/getting-started.xml.vm +++ b/src/site/xdoc/getting-started.xml.vm @@ -63,7 +63,7 @@

Date: Tue, 2 Aug 2022 22:42:35 -0400 Subject: [PATCH 02/11] [cdi4] Drop removed isNullable that was deprecated in 1.1 --- src/main/java/org/mybatis/cdi/MyBatisBean.java | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/main/java/org/mybatis/cdi/MyBatisBean.java b/src/main/java/org/mybatis/cdi/MyBatisBean.java index 90943407..67604ccd 100644 --- a/src/main/java/org/mybatis/cdi/MyBatisBean.java +++ b/src/main/java/org/mybatis/cdi/MyBatisBean.java @@ -113,11 +113,6 @@ public boolean isAlternative() { return false; } - @Override - public boolean isNullable() { - return false; - } - @Override public Set getInjectionPoints() { return Collections.emptySet(); From 2268921a1813c24694e0268c7289feb8663922e7 Mon Sep 17 00:00:00 2001 From: Jeremy Landis Date: Tue, 2 Aug 2022 22:42:59 -0400 Subject: [PATCH 03/11] [cdi4] Cast user transaction from javax to jakarta --- src/test/java/org/mybatis/cdi/UserTransactionProvider.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/org/mybatis/cdi/UserTransactionProvider.java b/src/test/java/org/mybatis/cdi/UserTransactionProvider.java index aa28db5d..40e43f42 100644 --- a/src/test/java/org/mybatis/cdi/UserTransactionProvider.java +++ b/src/test/java/org/mybatis/cdi/UserTransactionProvider.java @@ -26,7 +26,7 @@ public class UserTransactionProvider { @Produces @ApplicationScoped public UserTransaction initTX() { - return new UserTransactionManager(); + return (UserTransaction) new UserTransactionManager(); } } From 452ec3c4cde98fb8a2092710f27540a23f87f0e7 Mon Sep 17 00:00:00 2001 From: Jeremy Landis Date: Tue, 2 Aug 2022 22:43:50 -0400 Subject: [PATCH 04/11] [cdi4] Upgrade pom to weld 5 only drop support for 1.1, 1.2, and 2.0 --- pom.xml | 165 +++++++++++++++++++++----------------------------------- 1 file changed, 60 insertions(+), 105 deletions(-) diff --git a/pom.xml b/pom.xml index 0fbf86e8..78e2da22 100644 --- a/pom.xml +++ b/pom.xml @@ -28,7 +28,7 @@ mybatis-cdi - 1.1.4-SNAPSHOT + 1.2.0-SNAPSHOT mybatis-cdi https://www.mybatis.org/cdi @@ -58,7 +58,9 @@ - 1.0.3 + 11 + 11 + 1.1.3 org.mybatis.cdi.* org.mybatis.cdi org.mybatis.*;resolution:=optional,* @@ -69,32 +71,83 @@ + org.mybatis mybatis 3.5.11 provided + + jakarta.annotation jakarta.annotation-api - 1.3.5 + 2.1.1 provided jakarta.transaction jakarta.transaction-api - 1.3.3 + 2.0.1 + provided + + + jakarta.enterprise + jakarta.enterprise.cdi-api + 4.0.1 + provided + + + + + org.jboss.classfilewriter + jboss-classfilewriter + 1.2.5.Final provided + + org.jboss.weld.se + weld-se-core + 5.0.1.Final + test + - + org.junit.jupiter junit-jupiter-engine 5.9.1 test + + org.mockito + mockito-core + 4.9.0 + test + + + org.mockito + mockito-junit-jupiter + 4.9.0 + test + + + org.jboss.weld + weld-junit5 + 4.0.0.Final + test + + + + + javax.transaction + javax.transaction-api + 1.3 + provided + + + com.atomikos transactions-jdbc @@ -119,26 +172,8 @@ 10.15.2.0 test - - org.mockito - mockito-core - 4.9.0 - test - - - org.mockito - mockito-junit-jupiter - 4.9.0 - test - - + + org.slf4j slf4j-api @@ -151,13 +186,6 @@ 2.0.5 test - - - org.jboss.classfilewriter - jboss-classfilewriter - 1.2.5.Final - provided - @@ -211,57 +239,6 @@ - - cdi-2.0 - - - jakarta.enterprise - jakarta.enterprise.cdi-api - 2.0.2 - provided - - - org.jboss.weld.se - weld-se-core - 3.1.9.Final - test - - - - - cdi-1.2 - - - javax.enterprise - cdi-api - 1.2 - provided - - - org.jboss.weld.se - weld-se - 2.4.8.Final - test - - - - - cdi-1.1 - - - javax.enterprise - cdi-api - 1.1 - provided - - - org.jboss.weld.se - weld-se - 2.1.2.Final - test - - - jdk17on @@ -271,28 +248,6 @@ -Djdk.attach.allowAttachSelf --add-opens java.base/java.lang=ALL-UNNAMED - - eclipse - - - m2e.version - - - - - jakarta.enterprise - jakarta.enterprise.cdi-api - 2.0.2 - provided - - - org.jboss.weld.se - weld-se-core - 3.1.9.Final - test - - - From 3ac915d84b8b4a5eab40392c2f71908f79d79eaa Mon Sep 17 00:00:00 2001 From: Jeremy Landis Date: Tue, 2 Aug 2022 22:49:38 -0400 Subject: [PATCH 05/11] [weld] Update to weld junit 5 dropping custom extension support --- .../org/mybatis/cdi/FooServiceJTATest.java | 15 +++---- .../java/org/mybatis/cdi/FooServiceTest.java | 15 +++---- .../org/mybatis/cdi/WeldJunit5Extension.java | 44 ------------------- 3 files changed, 14 insertions(+), 60 deletions(-) delete mode 100644 src/test/java/org/mybatis/cdi/WeldJunit5Extension.java diff --git a/src/test/java/org/mybatis/cdi/FooServiceJTATest.java b/src/test/java/org/mybatis/cdi/FooServiceJTATest.java index 023e1a4f..0157f77a 100644 --- a/src/test/java/org/mybatis/cdi/FooServiceJTATest.java +++ b/src/test/java/org/mybatis/cdi/FooServiceJTATest.java @@ -15,25 +15,24 @@ */ package org.mybatis.cdi; +import org.jboss.weld.environment.se.Weld; +import org.jboss.weld.junit5.EnableWeld; +import org.jboss.weld.junit5.WeldInitiator; +import org.jboss.weld.junit5.WeldSetup; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestInstance; import org.junit.jupiter.api.TestInstance.Lifecycle; -import org.junit.jupiter.api.extension.ExtendWith; import jakarta.inject.Inject; import jakarta.transaction.UserTransaction; @TestInstance(Lifecycle.PER_CLASS) -// TODO Add the following once we drop cdi 1.1 support -// @EnableWeld -// TODO Remove the following once we drop cdi 1.1 support -@ExtendWith(WeldJunit5Extension.class) +@EnableWeld class FooServiceJTATest { - // TODO Add the following once we drop cdi 1.1 support - // @WeldSetup - // public WeldInitiator weld = WeldInitiator.of(new Weld()); + @WeldSetup + public WeldInitiator weld = WeldInitiator.of(new Weld()); @Inject private FooServiceJTA fooServiceJTA; diff --git a/src/test/java/org/mybatis/cdi/FooServiceTest.java b/src/test/java/org/mybatis/cdi/FooServiceTest.java index e1eb169c..b6aeee71 100644 --- a/src/test/java/org/mybatis/cdi/FooServiceTest.java +++ b/src/test/java/org/mybatis/cdi/FooServiceTest.java @@ -20,24 +20,23 @@ import java.io.ObjectInputStream; import java.io.ObjectOutputStream; +import org.jboss.weld.environment.se.Weld; +import org.jboss.weld.junit5.EnableWeld; +import org.jboss.weld.junit5.WeldInitiator; +import org.jboss.weld.junit5.WeldSetup; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestInstance; import org.junit.jupiter.api.TestInstance.Lifecycle; -import org.junit.jupiter.api.extension.ExtendWith; import jakarta.inject.Inject; @TestInstance(Lifecycle.PER_CLASS) -// TODO Add the following once we drop cdi 1.1 support -// @EnableWeld -// TODO Remove the following once we drop cdi 1.1 support -@ExtendWith(WeldJunit5Extension.class) +@EnableWeld class FooServiceTest { - // TODO Add the following once we drop cdi 1.1 support - // @WeldSetup - // public WeldInitiator weld = WeldInitiator.of(new Weld()); + @WeldSetup + public WeldInitiator weld = WeldInitiator.of(new Weld()); @Inject private FooService fooService; diff --git a/src/test/java/org/mybatis/cdi/WeldJunit5Extension.java b/src/test/java/org/mybatis/cdi/WeldJunit5Extension.java deleted file mode 100644 index 6906ca14..00000000 --- a/src/test/java/org/mybatis/cdi/WeldJunit5Extension.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright 2013-2022 the original author or authors. - * - * 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 - * - * https://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 org.mybatis.cdi; - -import org.jboss.weld.environment.se.Weld; -import org.jboss.weld.environment.se.WeldContainer; -import org.junit.jupiter.api.extension.ExtensionContext; -import org.junit.jupiter.api.extension.TestInstanceFactory; -import org.junit.jupiter.api.extension.TestInstanceFactoryContext; -import org.junit.jupiter.api.extension.TestInstantiationException; - -//TODO Remove this class once we drop cdi 1.1 support -public class WeldJunit5Extension implements TestInstanceFactory { - - private Weld weld; - private WeldContainer container; - - // This constructor is invoked by JUnit Jupiter via reflection or ServiceLoader. - public WeldJunit5Extension() { - this.weld = new Weld(); - this.container = this.weld.initialize(); - } - - @SuppressWarnings("deprecation") - @Override - public Object createTestInstance(TestInstanceFactoryContext factoryContext, ExtensionContext extensionContext) - throws TestInstantiationException { - return this.container.instance().select(factoryContext.getTestClass()).get(); - } - -} From 76b78c159962baaa712c133a3ddae02cea748fbe Mon Sep 17 00:00:00 2001 From: Jeremy Landis Date: Sat, 3 Sep 2022 18:09:40 -0400 Subject: [PATCH 06/11] [jakarta] Update beans xml to 4.0 --- src/main/resources/META-INF/beans.xml | 6 +++--- src/test/resources/META-INF/beans.xml | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/resources/META-INF/beans.xml b/src/main/resources/META-INF/beans.xml index c8c7bb08..039388ea 100644 --- a/src/main/resources/META-INF/beans.xml +++ b/src/main/resources/META-INF/beans.xml @@ -16,7 +16,7 @@ limitations under the License. --> - + diff --git a/src/test/resources/META-INF/beans.xml b/src/test/resources/META-INF/beans.xml index c8c7bb08..039388ea 100644 --- a/src/test/resources/META-INF/beans.xml +++ b/src/test/resources/META-INF/beans.xml @@ -16,7 +16,7 @@ limitations under the License. --> - + From ffe525607fbc831795e963c9243c9e82b93054ff Mon Sep 17 00:00:00 2001 From: Jeremy Landis Date: Sat, 3 Sep 2022 18:09:58 -0400 Subject: [PATCH 07/11] [jakarta] Rename extension from javax to jakarta --- ...ject.spi.Extension => jakarta.enterprise.inject.spi.Extension} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/main/resources/META-INF/services/{javax.enterprise.inject.spi.Extension => jakarta.enterprise.inject.spi.Extension} (100%) diff --git a/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension b/src/main/resources/META-INF/services/jakarta.enterprise.inject.spi.Extension similarity index 100% rename from src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension rename to src/main/resources/META-INF/services/jakarta.enterprise.inject.spi.Extension From 33733a5aca8cd61c769a7873a73113798b30c250 Mon Sep 17 00:00:00 2001 From: Alexander Wienzek Date: Fri, 3 Feb 2023 11:17:40 +0100 Subject: [PATCH 08/11] Migrate from atomikos to narayana Removed Atomikos dependencies and code from pom.xml Added narayana-jta-jakarta:5.13.1.Final dependency to pom.xml Removed not needed properties from mybatis-config_jta.xml Added NarayanaDataSourceWrapper which is needed to wrap a XADataSource Added a primary key to CreateDB_JTA.sql to avoid tests sometimes failing Changed JtaDatasourceFactory to use Narayana --- pom.xml | 20 +--- .../org/mybatis/cdi/JtaDatasourceFactory.java | 31 +++---- .../cdi/NarayanaDataSourceWrapper.java | 93 +++++++++++++++++++ .../mybatis/cdi/UserTransactionProvider.java | 7 +- .../org/mybatis/cdi/CreateDB_JTA.sql | 5 +- .../org/mybatis/cdi/mybatis-config_jta.xml | 6 +- 6 files changed, 117 insertions(+), 45 deletions(-) create mode 100644 src/test/java/org/mybatis/cdi/NarayanaDataSourceWrapper.java diff --git a/pom.xml b/pom.xml index 78e2da22..99f57095 100644 --- a/pom.xml +++ b/pom.xml @@ -1,7 +1,7 @@ - - javax.transaction - javax.transaction-api - 1.3 - provided - - - com.atomikos - transactions-jdbc - 5.0.9 + org.jboss.narayana.jta + narayana-jta-jakarta + 5.13.1.Final test @@ -199,10 +191,6 @@ derby.stream.error.file ${project.build.directory}/derby.log - - com.atomikos.icatch.log_base_dir - ${project.build.directory} - diff --git a/src/test/java/org/mybatis/cdi/JtaDatasourceFactory.java b/src/test/java/org/mybatis/cdi/JtaDatasourceFactory.java index c19df67e..64fd6e33 100644 --- a/src/test/java/org/mybatis/cdi/JtaDatasourceFactory.java +++ b/src/test/java/org/mybatis/cdi/JtaDatasourceFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2022 the original author or authors. + * Copyright 2013-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,36 +15,31 @@ */ package org.mybatis.cdi; -import com.atomikos.jdbc.AtomikosDataSourceBean; - import java.util.Properties; import javax.sql.DataSource; +import org.apache.derby.jdbc.EmbeddedXADataSource; import org.apache.ibatis.datasource.DataSourceFactory; public class JtaDatasourceFactory implements DataSourceFactory { - - AtomikosDataSourceBean ds; + private final DataSource dataSource; + private final EmbeddedXADataSource embeddedXADataSource; public JtaDatasourceFactory() { - this.ds = new AtomikosDataSourceBean(); + embeddedXADataSource = new EmbeddedXADataSource(); + dataSource = new NarayanaDataSourceWrapper(embeddedXADataSource); } @Override - public void setProperties(Properties props) { - this.ds.setUniqueResourceName(props.getProperty("resourceName")); - props.remove("resourceName"); - this.ds.setXaDataSourceClassName(props.getProperty("driver")); - props.remove("driver"); - this.ds.setMaxPoolSize(Integer.parseInt(props.getProperty("maxPoolSize"))); - props.remove("maxPoolSize"); - this.ds.setXaProperties(props); + public DataSource getDataSource() { + return dataSource; } @Override - public DataSource getDataSource() { - return this.ds; + public void setProperties(final Properties properties) { + embeddedXADataSource.setCreateDatabase(properties.getProperty("createDatabase")); + embeddedXADataSource.setDatabaseName(properties.getProperty("databaseName")); + embeddedXADataSource.setDataSourceName(properties.getProperty("resourceName")); } - -} +} \ No newline at end of file diff --git a/src/test/java/org/mybatis/cdi/NarayanaDataSourceWrapper.java b/src/test/java/org/mybatis/cdi/NarayanaDataSourceWrapper.java new file mode 100644 index 00000000..2bd55bde --- /dev/null +++ b/src/test/java/org/mybatis/cdi/NarayanaDataSourceWrapper.java @@ -0,0 +1,93 @@ +/* + * Copyright 2013-2023 the original author or authors. + * + * 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 + * + * https://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 org.mybatis.cdi; + +import com.arjuna.ats.internal.jdbc.ConnectionManager; +import com.arjuna.ats.jdbc.TransactionalDriver; + +import java.io.PrintWriter; +import java.sql.Connection; +import java.sql.SQLException; +import java.sql.SQLFeatureNotSupportedException; +import java.util.Properties; +import java.util.logging.Logger; + +import javax.annotation.Nonnull; +import javax.sql.DataSource; +import javax.sql.XADataSource; + +public class NarayanaDataSourceWrapper implements DataSource { + private final XADataSource xaDataSource; + + public NarayanaDataSourceWrapper(@Nonnull final XADataSource xaDataSource) { + this.xaDataSource = xaDataSource; + } + + @Override + public Connection getConnection() throws SQLException { + final var properties = new Properties(); + properties.put(TransactionalDriver.XADataSource, xaDataSource); + return ConnectionManager.create(null, properties); + } + + @Override + public Connection getConnection(final String username, final String password) throws SQLException { + final var properties = new Properties(); + properties.put(TransactionalDriver.XADataSource, xaDataSource); + properties.put(TransactionalDriver.userName, username); + properties.put(TransactionalDriver.password, password); + return ConnectionManager.create(null, properties); + } + + @Override + public int getLoginTimeout() throws SQLException { + return xaDataSource.getLoginTimeout(); + } + + @Override + public PrintWriter getLogWriter() throws SQLException { + return xaDataSource.getLogWriter(); + } + + @Override + public Logger getParentLogger() throws SQLFeatureNotSupportedException { + return xaDataSource.getParentLogger(); + } + + @Override + public boolean isWrapperFor(final Class iface) throws SQLException { + return iface.isAssignableFrom(getClass()); + } + + @Override + public void setLoginTimeout(final int seconds) throws SQLException { + xaDataSource.setLoginTimeout(seconds); + } + + @Override + public void setLogWriter(final PrintWriter out) throws SQLException { + xaDataSource.setLogWriter(out); + } + + @SuppressWarnings("unchecked") + @Override + public T unwrap(final Class iface) throws SQLException { + if (isWrapperFor(iface)) { + return (T) this; + } + throw new SQLException(getClass() + " is not a wrapper for " + iface); + } +} diff --git a/src/test/java/org/mybatis/cdi/UserTransactionProvider.java b/src/test/java/org/mybatis/cdi/UserTransactionProvider.java index 40e43f42..9c36b715 100644 --- a/src/test/java/org/mybatis/cdi/UserTransactionProvider.java +++ b/src/test/java/org/mybatis/cdi/UserTransactionProvider.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2022 the original author or authors. + * Copyright 2013-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,8 +15,6 @@ */ package org.mybatis.cdi; -import com.atomikos.icatch.jta.UserTransactionManager; - import jakarta.enterprise.context.ApplicationScoped; import jakarta.enterprise.inject.Produces; import jakarta.transaction.UserTransaction; @@ -26,7 +24,6 @@ public class UserTransactionProvider { @Produces @ApplicationScoped public UserTransaction initTX() { - return (UserTransaction) new UserTransactionManager(); + return com.arjuna.ats.jta.UserTransaction.userTransaction(); } - } diff --git a/src/test/resources/org/mybatis/cdi/CreateDB_JTA.sql b/src/test/resources/org/mybatis/cdi/CreateDB_JTA.sql index 7cbb0a9d..fc2ff2b7 100644 --- a/src/test/resources/org/mybatis/cdi/CreateDB_JTA.sql +++ b/src/test/resources/org/mybatis/cdi/CreateDB_JTA.sql @@ -1,5 +1,5 @@ -- --- Copyright 2013-2022 the original author or authors. +-- Copyright 2013-2023 the original author or authors. -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. @@ -16,7 +16,8 @@ CREATE TABLE USERS ( id integer not null, - name varchar(80) not null + name varchar(80) not null, + PRIMARY KEY(id) ); insert into users (id, name) values(1, '1-User1'); diff --git a/src/test/resources/org/mybatis/cdi/mybatis-config_jta.xml b/src/test/resources/org/mybatis/cdi/mybatis-config_jta.xml index 0ae0bb02..a7645a8d 100644 --- a/src/test/resources/org/mybatis/cdi/mybatis-config_jta.xml +++ b/src/test/resources/org/mybatis/cdi/mybatis-config_jta.xml @@ -1,7 +1,7 @@