This is an automated email from the ASF dual-hosted git repository. aldettinger pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git
The following commit(s) were added to refs/heads/main by this push: new 0239abea3d Restore named DataSource autowiring for JDBC and SQL extensions 0239abea3d is described below commit 0239abea3dce408e1655c771567231a316e0ee50 Author: James Netherton <jamesnether...@gmail.com> AuthorDate: Fri Sep 16 08:59:01 2022 +0100 Restore named DataSource autowiring for JDBC and SQL extensions Fixes #4063 --- .../core/deployment/CamelRegistryProcessor.java | 17 ++- .../spi/CamelBeanQualifierResolverBuildItem.java | 46 +++++++ .../CamelRegistryBeanQualifierResolutionTest.java | 137 +++++++++++++++++++++ ...gistry.java => CamelBeanQualifierResolver.java} | 19 +-- .../apache/camel/quarkus/core/CamelRecorder.java | 17 ++- .../camel/quarkus/core/RuntimeBeanRepository.java | 24 ++++ .../apache/camel/quarkus/core/RuntimeRegistry.java | 6 +- .../jdbc/deployment/pom.xml | 12 +- .../jdbc/deployment/JdbcSupportProcessor.java | 56 +++++++++ extensions-support/jdbc/pom.xml | 39 ++++++ .../jdbc/runtime}/pom.xml | 22 ++-- .../camel/quarkus/support/jdbc/JdbcRecorder.java | 27 ++-- .../main/resources/META-INF/quarkus-extension.yaml | 28 +++++ extensions-support/pom.xml | 1 + extensions/jdbc/deployment/pom.xml | 4 + extensions/jdbc/runtime/pom.xml | 4 + extensions/sql/deployment/pom.xml | 4 + extensions/sql/runtime/pom.xml | 4 + .../camel/quarkus/component/jta/it/JtaRoutes.java | 10 +- poms/bom/pom.xml | 10 ++ poms/bom/src/main/generated/flattened-full-pom.xml | 10 ++ .../src/main/generated/flattened-reduced-pom.xml | 10 ++ .../generated/flattened-reduced-verbose-pom.xml | 10 ++ 23 files changed, 459 insertions(+), 58 deletions(-) diff --git a/extensions-core/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/CamelRegistryProcessor.java b/extensions-core/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/CamelRegistryProcessor.java index d27028eeb8..a9be5e7e26 100644 --- a/extensions-core/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/CamelRegistryProcessor.java +++ b/extensions-core/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/CamelRegistryProcessor.java @@ -16,15 +16,19 @@ */ package org.apache.camel.quarkus.core.deployment; +import java.util.HashMap; import java.util.List; +import java.util.Map; import io.quarkus.deployment.annotations.BuildStep; import io.quarkus.deployment.annotations.ExecutionTime; import io.quarkus.deployment.annotations.Record; import io.quarkus.deployment.builditem.ApplicationArchivesBuildItem; +import org.apache.camel.quarkus.core.CamelBeanQualifierResolver; import org.apache.camel.quarkus.core.CamelConfig; import org.apache.camel.quarkus.core.CamelRecorder; import org.apache.camel.quarkus.core.deployment.spi.CamelBeanBuildItem; +import org.apache.camel.quarkus.core.deployment.spi.CamelBeanQualifierResolverBuildItem; import org.apache.camel.quarkus.core.deployment.spi.CamelContextBuildItem; import org.apache.camel.quarkus.core.deployment.spi.CamelRegistryBuildItem; import org.apache.camel.quarkus.core.deployment.spi.CamelRuntimeBeanBuildItem; @@ -43,8 +47,17 @@ public class CamelRegistryProcessor { @Record(ExecutionTime.STATIC_INIT) @BuildStep - CamelRegistryBuildItem registry(CamelRecorder recorder) { - return new CamelRegistryBuildItem(recorder.createRegistry()); + CamelRegistryBuildItem registry( + List<CamelBeanQualifierResolverBuildItem> camelBeanQualifierResolvers, + CamelRecorder recorder) { + + Map<String, CamelBeanQualifierResolver> beanQualifierResolvers = new HashMap<>(); + for (CamelBeanQualifierResolverBuildItem resolver : camelBeanQualifierResolvers) { + recorder.registerCamelBeanQualifierResolver(resolver.getBeanTypeName(), resolver.getRuntimeValue(), + beanQualifierResolvers); + } + + return new CamelRegistryBuildItem(recorder.createRegistry(beanQualifierResolvers)); } @Record(ExecutionTime.STATIC_INIT) diff --git a/extensions-core/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/spi/CamelBeanQualifierResolverBuildItem.java b/extensions-core/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/spi/CamelBeanQualifierResolverBuildItem.java new file mode 100644 index 0000000000..7d9e96b0b9 --- /dev/null +++ b/extensions-core/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/spi/CamelBeanQualifierResolverBuildItem.java @@ -0,0 +1,46 @@ +/* + * 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. + */ +package org.apache.camel.quarkus.core.deployment.spi; + +import io.quarkus.builder.item.MultiBuildItem; +import io.quarkus.runtime.RuntimeValue; +import org.apache.camel.quarkus.core.CamelBeanQualifierResolver; + +/** + * Holds a {@link CamelBeanQualifierResolver} for a specified bean type. + */ +public final class CamelBeanQualifierResolverBuildItem extends MultiBuildItem { + private final RuntimeValue<CamelBeanQualifierResolver> runtimeValue; + private final Class<?> beanType; + + public CamelBeanQualifierResolverBuildItem(Class<?> beanType, RuntimeValue<CamelBeanQualifierResolver> runtimeValue) { + this.beanType = beanType; + this.runtimeValue = runtimeValue; + } + + public Class<?> getBeanType() { + return beanType; + } + + public String getBeanTypeName() { + return beanType.getName(); + } + + public RuntimeValue<CamelBeanQualifierResolver> getRuntimeValue() { + return runtimeValue; + } +} diff --git a/extensions-core/core/deployment/src/test/java/org/apache/camel/quarkus/core/deployment/CamelRegistryBeanQualifierResolutionTest.java b/extensions-core/core/deployment/src/test/java/org/apache/camel/quarkus/core/deployment/CamelRegistryBeanQualifierResolutionTest.java new file mode 100644 index 0000000000..df5a8745fa --- /dev/null +++ b/extensions-core/core/deployment/src/test/java/org/apache/camel/quarkus/core/deployment/CamelRegistryBeanQualifierResolutionTest.java @@ -0,0 +1,137 @@ +/* + * 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. + */ +package org.apache.camel.quarkus.core.deployment; + +import java.lang.annotation.Annotation; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; +import java.util.Set; +import java.util.function.Consumer; + +import javax.enterprise.context.ApplicationScoped; +import javax.enterprise.inject.Produces; +import javax.enterprise.util.AnnotationLiteral; +import javax.inject.Inject; +import javax.inject.Qualifier; + +import io.quarkus.arc.Unremovable; +import io.quarkus.builder.BuildChainBuilder; +import io.quarkus.builder.BuildContext; +import io.quarkus.builder.BuildStep; +import io.quarkus.deployment.builditem.StaticBytecodeRecorderBuildItem; +import io.quarkus.deployment.recording.BytecodeRecorderImpl; +import io.quarkus.runtime.RuntimeValue; +import io.quarkus.test.QuarkusUnitTest; +import org.apache.camel.CamelContext; +import org.apache.camel.quarkus.core.CamelBeanQualifierResolver; +import org.apache.camel.quarkus.core.deployment.spi.CamelBeanQualifierResolverBuildItem; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.TYPE; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class CamelRegistryBeanQualifierResolutionTest { + + @RegisterExtension + static final QuarkusUnitTest CONFIG = new QuarkusUnitTest() + .addBuildChainCustomizer(new Consumer<>() { + @Override + public void accept(BuildChainBuilder buildChainBuilder) { + buildChainBuilder.addBuildStep(new BuildStep() { + @Override + public void execute(BuildContext context) { + String methodName = "execute"; + BytecodeRecorderImpl recorder = new BytecodeRecorderImpl( + true, + getClass().getSimpleName(), + methodName, + Integer.toString(methodName.hashCode()), + true, s -> null); + + RuntimeValue<CamelBeanQualifierResolver> runtimeValue = recorder + .newInstance(TestBeanQualifierResolver.class.getName()); + context.produce(new StaticBytecodeRecorderBuildItem(recorder)); + + CamelBeanQualifierResolverBuildItem buildItem = new CamelBeanQualifierResolverBuildItem(Foo.class, + runtimeValue); + context.produce(buildItem); + } + }).produces(StaticBytecodeRecorderBuildItem.class).produces(CamelBeanQualifierResolverBuildItem.class) + .build(); + } + }) + .setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class)); + + @Inject + CamelContext context; + + @Test + public void testBeanLookupWithQualifiers() { + // Foo should be resolvable since we have a CamelBeanQualifierResolver for that type + Set<Foo> fooBeans = context.getRegistry().findByType(Foo.class); + assertEquals(1, fooBeans.size()); + + // Bar should not be resolvable as there is no CamelBeanQualifierResolver for that type + Set<Bar> barBeans = context.getRegistry().findByType(Bar.class); + assertTrue(barBeans.isEmpty()); + } + + @Qualifier + @Retention(RUNTIME) + @Target({ TYPE, METHOD }) + public @interface CamelQuarkusQualifier { + class CamelQuarkusLiteral extends AnnotationLiteral<CamelQuarkusQualifier> implements CamelQuarkusQualifier { + } + } + + public static class TestBeanQualifierResolver implements CamelBeanQualifierResolver { + @Override + public Annotation[] resolveQualifiers() { + return new Annotation[] { new CamelQuarkusQualifier.CamelQuarkusLiteral() }; + } + } + + public static class Foo { + } + + public static class Bar { + } + + @ApplicationScoped + public static class Service { + @Unremovable + @Produces + @CamelQuarkusQualifier + public Foo foo() { + return new Foo(); + } + + @Unremovable + @Produces + @CamelQuarkusQualifier + public Bar bar() { + return new Bar(); + } + } +} diff --git a/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/RuntimeRegistry.java b/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/CamelBeanQualifierResolver.java similarity index 67% copy from extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/RuntimeRegistry.java copy to extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/CamelBeanQualifierResolver.java index 6a89ba2b3c..c8d7cc5330 100644 --- a/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/RuntimeRegistry.java +++ b/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/CamelBeanQualifierResolver.java @@ -16,18 +16,11 @@ */ package org.apache.camel.quarkus.core; -import io.quarkus.runtime.RuntimeValue; -import org.apache.camel.support.DefaultRegistry; +import java.lang.annotation.Annotation; -public class RuntimeRegistry extends DefaultRegistry { - public RuntimeRegistry() { - super(new RuntimeBeanRepository()); - } - - @Override - public Object unwrap(Object value) { - return (value instanceof RuntimeValue) - ? ((RuntimeValue<?>) value).getValue() - : value; - } +/** + * Abstraction for resolving bean annotation qualifiers + */ +public interface CamelBeanQualifierResolver { + Annotation[] resolveQualifiers(); } diff --git a/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/CamelRecorder.java b/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/CamelRecorder.java index 67b16da1e9..d1217cb673 100644 --- a/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/CamelRecorder.java +++ b/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/CamelRecorder.java @@ -16,6 +16,7 @@ */ package org.apache.camel.quarkus.core; +import java.util.Map; import java.util.Set; import java.util.function.Supplier; @@ -47,8 +48,20 @@ import org.apache.camel.support.startup.DefaultStartupStepRecorder; @Recorder public class CamelRecorder { - public RuntimeValue<Registry> createRegistry() { - return new RuntimeValue<>(new RuntimeRegistry()); + public void registerCamelBeanQualifierResolver( + String className, + RuntimeValue<CamelBeanQualifierResolver> runtimeValue, + Map<String, CamelBeanQualifierResolver> beanQualifiers) { + + if (beanQualifiers.containsKey(className)) { + throw new RuntimeException("Duplicate CamelBeanQualifierResolver detected for class: " + className); + } + + beanQualifiers.put(className, runtimeValue.getValue()); + } + + public RuntimeValue<Registry> createRegistry(Map<String, CamelBeanQualifierResolver> beanQualifierResolvers) { + return new RuntimeValue<>(new RuntimeRegistry(beanQualifierResolvers)); } public RuntimeValue<TypeConverterRegistry> createTypeConverterRegistry() { diff --git a/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/RuntimeBeanRepository.java b/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/RuntimeBeanRepository.java index 934cb22ae0..24ace84985 100644 --- a/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/RuntimeBeanRepository.java +++ b/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/RuntimeBeanRepository.java @@ -34,6 +34,12 @@ import org.apache.camel.spi.BeanRepository; public final class RuntimeBeanRepository implements BeanRepository { + private final Map<String, CamelBeanQualifierResolver> beanQualifierResolvers; + + public RuntimeBeanRepository(Map<String, CamelBeanQualifierResolver> beanQualifierResolvers) { + this.beanQualifierResolvers = beanQualifierResolvers; + } + private static <T> Set<Bean<? extends T>> resolveAmbiguity(BeanManager manager, Set<Bean<? extends T>> beans) { if (beans.size() > 1) { try { @@ -111,13 +117,31 @@ public final class RuntimeBeanRepository implements BeanRepository { @Override public <T> Map<String, T> findByTypeWithName(Class<T> type) { + Optional<Annotation[]> qualifiers = resolveQualifiersForType(type); + if (qualifiers.isPresent()) { + return getReferencesByTypeWithName(type, qualifiers.get()); + } return getReferencesByTypeWithName(type); } @Override public <T> Set<T> findByType(Class<T> type) { + Optional<Annotation[]> qualifiers = resolveQualifiersForType(type); + if (qualifiers.isPresent()) { + return getBeanManager() + .map(manager -> getReferencesByType(manager, type, qualifiers.get())) + .orElseGet(Collections::emptySet); + } return getBeanManager() .map(manager -> getReferencesByType(manager, type)) .orElseGet(Collections::emptySet); } + + private Optional<Annotation[]> resolveQualifiersForType(Class<?> type) { + CamelBeanQualifierResolver resolver = beanQualifierResolvers.get(type.getName()); + if (resolver != null) { + return Optional.ofNullable(resolver.resolveQualifiers()); + } + return Optional.empty(); + } } diff --git a/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/RuntimeRegistry.java b/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/RuntimeRegistry.java index 6a89ba2b3c..3f547bd290 100644 --- a/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/RuntimeRegistry.java +++ b/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/RuntimeRegistry.java @@ -16,12 +16,14 @@ */ package org.apache.camel.quarkus.core; +import java.util.Map; + import io.quarkus.runtime.RuntimeValue; import org.apache.camel.support.DefaultRegistry; public class RuntimeRegistry extends DefaultRegistry { - public RuntimeRegistry() { - super(new RuntimeBeanRepository()); + public RuntimeRegistry(Map<String, CamelBeanQualifierResolver> beanQualifierResolvers) { + super(new RuntimeBeanRepository(beanQualifierResolvers)); } @Override diff --git a/extensions/jdbc/deployment/pom.xml b/extensions-support/jdbc/deployment/pom.xml similarity index 85% copy from extensions/jdbc/deployment/pom.xml copy to extensions-support/jdbc/deployment/pom.xml index 28017e970e..6e7c19a54a 100644 --- a/extensions/jdbc/deployment/pom.xml +++ b/extensions-support/jdbc/deployment/pom.xml @@ -20,30 +20,26 @@ <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <parent> <groupId>org.apache.camel.quarkus</groupId> - <artifactId>camel-quarkus-jdbc-parent</artifactId> + <artifactId>camel-quarkus-support-jdbc-parent</artifactId> <version>2.13.0-SNAPSHOT</version> </parent> <modelVersion>4.0.0</modelVersion> - <artifactId>camel-quarkus-jdbc-deployment</artifactId> - <name>Camel Quarkus :: JDBC :: Deployment</name> + <artifactId>camel-quarkus-support-jdbc-deployment</artifactId> + <name>Camel Quarkus :: Support :: JDBC :: Deployment</name> <dependencies> <dependency> <groupId>io.quarkus</groupId> <artifactId>quarkus-agroal-deployment</artifactId> </dependency> - <dependency> - <groupId>io.quarkus</groupId> - <artifactId>quarkus-narayana-jta-deployment</artifactId> - </dependency> <dependency> <groupId>org.apache.camel.quarkus</groupId> <artifactId>camel-quarkus-core-deployment</artifactId> </dependency> <dependency> <groupId>org.apache.camel.quarkus</groupId> - <artifactId>camel-quarkus-jdbc</artifactId> + <artifactId>camel-quarkus-support-jdbc</artifactId> </dependency> </dependencies> diff --git a/extensions-support/jdbc/deployment/src/main/java/org/apache/camel/quarkus/support/jdbc/deployment/JdbcSupportProcessor.java b/extensions-support/jdbc/deployment/src/main/java/org/apache/camel/quarkus/support/jdbc/deployment/JdbcSupportProcessor.java new file mode 100644 index 0000000000..0730784bb1 --- /dev/null +++ b/extensions-support/jdbc/deployment/src/main/java/org/apache/camel/quarkus/support/jdbc/deployment/JdbcSupportProcessor.java @@ -0,0 +1,56 @@ +/* + * 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. + */ +package org.apache.camel.quarkus.support.jdbc.deployment; + +import java.util.List; + +import javax.sql.DataSource; + +import io.quarkus.agroal.spi.JdbcDataSourceBuildItem; +import io.quarkus.deployment.annotations.BuildProducer; +import io.quarkus.deployment.annotations.BuildStep; +import io.quarkus.deployment.annotations.ExecutionTime; +import io.quarkus.deployment.annotations.Record; +import io.quarkus.runtime.RuntimeValue; +import org.apache.camel.quarkus.core.CamelBeanQualifierResolver; +import org.apache.camel.quarkus.core.deployment.spi.CamelBeanQualifierResolverBuildItem; +import org.apache.camel.quarkus.support.jdbc.JdbcRecorder; + +public class JdbcSupportProcessor { + + @Record(ExecutionTime.STATIC_INIT) + @BuildStep + void registerNamedDataSourceCamelBeanQualifierResolver( + List<JdbcDataSourceBuildItem> dataSources, + BuildProducer<CamelBeanQualifierResolverBuildItem> camelBeanQualifierResolver, + JdbcRecorder recorder) { + + // If there are multiple DataSource configs, then users need to explicitly state which one to use + // via their component / endpoint configuration. Otherwise if there is just 1, and it is not the default DataSource, + // we can create a resolver for DataSourceLiteral and make named DataSource autowiring work as expected + if (dataSources.size() == 1) { + JdbcDataSourceBuildItem dataSource = dataSources.get(0); + if (!dataSource.isDefault()) { + RuntimeValue<CamelBeanQualifierResolver> runtimeValue = recorder + .createDataSourceQualifierResolver(dataSource.getName()); + CamelBeanQualifierResolverBuildItem beanQualifierResolver = new CamelBeanQualifierResolverBuildItem( + DataSource.class, runtimeValue); + camelBeanQualifierResolver.produce(beanQualifierResolver); + } + } + } +} diff --git a/extensions-support/jdbc/pom.xml b/extensions-support/jdbc/pom.xml new file mode 100644 index 0000000000..d73c3b13f4 --- /dev/null +++ b/extensions-support/jdbc/pom.xml @@ -0,0 +1,39 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + 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. + +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + + <parent> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-extensions-support</artifactId> + <version>2.13.0-SNAPSHOT</version> + <relativePath>../pom.xml</relativePath> + </parent> + + <modelVersion>4.0.0</modelVersion> + + <artifactId>camel-quarkus-support-jdbc-parent</artifactId> + <name>Camel Quarkus :: Support :: JDBC</name> + <packaging>pom</packaging> + <modules> + <module>deployment</module> + <module>runtime</module> + </modules> + +</project> diff --git a/extensions/jdbc/deployment/pom.xml b/extensions-support/jdbc/runtime/pom.xml similarity index 77% copy from extensions/jdbc/deployment/pom.xml copy to extensions-support/jdbc/runtime/pom.xml index 28017e970e..e5845dd4f4 100644 --- a/extensions/jdbc/deployment/pom.xml +++ b/extensions-support/jdbc/runtime/pom.xml @@ -20,35 +20,31 @@ <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <parent> <groupId>org.apache.camel.quarkus</groupId> - <artifactId>camel-quarkus-jdbc-parent</artifactId> + <artifactId>camel-quarkus-support-jdbc-parent</artifactId> <version>2.13.0-SNAPSHOT</version> </parent> <modelVersion>4.0.0</modelVersion> - <artifactId>camel-quarkus-jdbc-deployment</artifactId> - <name>Camel Quarkus :: JDBC :: Deployment</name> + <artifactId>camel-quarkus-support-jdbc</artifactId> + <name>Camel Quarkus :: Support :: JDBC :: Runtime</name> <dependencies> <dependency> <groupId>io.quarkus</groupId> - <artifactId>quarkus-agroal-deployment</artifactId> - </dependency> - <dependency> - <groupId>io.quarkus</groupId> - <artifactId>quarkus-narayana-jta-deployment</artifactId> - </dependency> - <dependency> - <groupId>org.apache.camel.quarkus</groupId> - <artifactId>camel-quarkus-core-deployment</artifactId> + <artifactId>quarkus-agroal</artifactId> </dependency> <dependency> <groupId>org.apache.camel.quarkus</groupId> - <artifactId>camel-quarkus-jdbc</artifactId> + <artifactId>camel-quarkus-core</artifactId> </dependency> </dependencies> <build> <plugins> + <plugin> + <groupId>io.quarkus</groupId> + <artifactId>quarkus-extension-maven-plugin</artifactId> + </plugin> <plugin> <artifactId>maven-compiler-plugin</artifactId> <configuration> diff --git a/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/RuntimeRegistry.java b/extensions-support/jdbc/runtime/src/main/java/org/apache/camel/quarkus/support/jdbc/JdbcRecorder.java similarity index 53% copy from extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/RuntimeRegistry.java copy to extensions-support/jdbc/runtime/src/main/java/org/apache/camel/quarkus/support/jdbc/JdbcRecorder.java index 6a89ba2b3c..4812acd283 100644 --- a/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/RuntimeRegistry.java +++ b/extensions-support/jdbc/runtime/src/main/java/org/apache/camel/quarkus/support/jdbc/JdbcRecorder.java @@ -14,20 +14,25 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.camel.quarkus.core; +package org.apache.camel.quarkus.support.jdbc; +import java.lang.annotation.Annotation; + +import io.quarkus.agroal.DataSource; import io.quarkus.runtime.RuntimeValue; -import org.apache.camel.support.DefaultRegistry; +import io.quarkus.runtime.annotations.Recorder; +import org.apache.camel.quarkus.core.CamelBeanQualifierResolver; -public class RuntimeRegistry extends DefaultRegistry { - public RuntimeRegistry() { - super(new RuntimeBeanRepository()); - } +@Recorder +public class JdbcRecorder { + public RuntimeValue<CamelBeanQualifierResolver> createDataSourceQualifierResolver(String dataSourceName) { + return new RuntimeValue<>(new CamelBeanQualifierResolver() { + final DataSource.DataSourceLiteral datasourceLiteral = new DataSource.DataSourceLiteral(dataSourceName); - @Override - public Object unwrap(Object value) { - return (value instanceof RuntimeValue) - ? ((RuntimeValue<?>) value).getValue() - : value; + @Override + public Annotation[] resolveQualifiers() { + return new Annotation[] { datasourceLiteral }; + } + }); } } diff --git a/extensions-support/jdbc/runtime/src/main/resources/META-INF/quarkus-extension.yaml b/extensions-support/jdbc/runtime/src/main/resources/META-INF/quarkus-extension.yaml new file mode 100644 index 0000000000..b742d2e786 --- /dev/null +++ b/extensions-support/jdbc/runtime/src/main/resources/META-INF/quarkus-extension.yaml @@ -0,0 +1,28 @@ +# +# 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. +# + +--- +name: "Camel Quarkus Support JDBC" +description: "Camel Quarkus Support JDBC" +metadata: + unlisted: true + keywords: + - "camel" + - "JDBC" + guide: "https://quarkus.io/guides/camel" + categories: + - "integration" \ No newline at end of file diff --git a/extensions-support/pom.xml b/extensions-support/pom.xml index f83c8bf809..28ac6cbe07 100644 --- a/extensions-support/pom.xml +++ b/extensions-support/pom.xml @@ -47,6 +47,7 @@ <module>google-http-client</module> <module>httpclient</module> <module>jackson-dataformat-xml</module> + <module>jdbc</module> <module>jetty</module> <module>mail</module> <module>mongodb</module> diff --git a/extensions/jdbc/deployment/pom.xml b/extensions/jdbc/deployment/pom.xml index 28017e970e..6f4e6cb671 100644 --- a/extensions/jdbc/deployment/pom.xml +++ b/extensions/jdbc/deployment/pom.xml @@ -41,6 +41,10 @@ <groupId>org.apache.camel.quarkus</groupId> <artifactId>camel-quarkus-core-deployment</artifactId> </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-support-jdbc-deployment</artifactId> + </dependency> <dependency> <groupId>org.apache.camel.quarkus</groupId> <artifactId>camel-quarkus-jdbc</artifactId> diff --git a/extensions/jdbc/runtime/pom.xml b/extensions/jdbc/runtime/pom.xml index 274b508a6b..e908d778ad 100644 --- a/extensions/jdbc/runtime/pom.xml +++ b/extensions/jdbc/runtime/pom.xml @@ -38,6 +38,10 @@ <groupId>org.apache.camel.quarkus</groupId> <artifactId>camel-quarkus-core</artifactId> </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-support-jdbc</artifactId> + </dependency> <dependency> <groupId>io.quarkus</groupId> <artifactId>quarkus-agroal</artifactId> diff --git a/extensions/sql/deployment/pom.xml b/extensions/sql/deployment/pom.xml index db4c549222..1de88d41ba 100644 --- a/extensions/sql/deployment/pom.xml +++ b/extensions/sql/deployment/pom.xml @@ -43,6 +43,10 @@ <groupId>org.apache.camel.quarkus</groupId> <artifactId>camel-quarkus-core-deployment</artifactId> </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-support-jdbc-deployment</artifactId> + </dependency> <dependency> <groupId>org.apache.camel.quarkus</groupId> <artifactId>camel-quarkus-support-spring-deployment</artifactId> diff --git a/extensions/sql/runtime/pom.xml b/extensions/sql/runtime/pom.xml index af5b84d26a..f96535dc26 100644 --- a/extensions/sql/runtime/pom.xml +++ b/extensions/sql/runtime/pom.xml @@ -40,6 +40,10 @@ <groupId>org.apache.camel.quarkus</groupId> <artifactId>camel-quarkus-core</artifactId> </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-support-jdbc</artifactId> + </dependency> <dependency> <groupId>org.apache.camel.quarkus</groupId> <artifactId>camel-quarkus-support-spring</artifactId> diff --git a/integration-tests/jta/src/main/java/org/apache/camel/quarkus/component/jta/it/JtaRoutes.java b/integration-tests/jta/src/main/java/org/apache/camel/quarkus/component/jta/it/JtaRoutes.java index 3ccd650850..b04930abc6 100644 --- a/integration-tests/jta/src/main/java/org/apache/camel/quarkus/component/jta/it/JtaRoutes.java +++ b/integration-tests/jta/src/main/java/org/apache/camel/quarkus/component/jta/it/JtaRoutes.java @@ -71,7 +71,7 @@ public class JtaRoutes extends RouteBuilder { .setHeader("message", body()) .to("jms:queue:jdbcRollback?connectionFactory=#xaConnectionFactory&disableReplyTo=true") .transform().simple("insert into example(message, origin) values ('${body}', 'jdbcRollback')") - .to("jdbc:camel-ds?resetAutoCommit=false") + .to("jdbc:default?resetAutoCommit=false") .choice() .when(header("message").startsWith("rollback")) .log("Rolling back after rollback message") @@ -86,9 +86,7 @@ public class JtaRoutes extends RouteBuilder { .transacted() .setHeader("message", body()) .to("jms:queue:sqltx?connectionFactory=#xaConnectionFactory&disableReplyTo=true") - // TODO: Remove the explicit dataSource option - // https://github.com/apache/camel-quarkus/issues/4063 - .to("sql:insert into example(message, origin) values (:#message, 'sqltx')?dataSource=#camel-ds") + .to("sql:insert into example(message, origin) values (:#message, 'sqltx')") .choice() .when(header("message").startsWith("rollback")) .log("Failing forever with exception") @@ -105,9 +103,7 @@ public class JtaRoutes extends RouteBuilder { .transacted() .setHeader("message", body()) .to("jms:queue:sqltxRollback?connectionFactory=#xaConnectionFactory&disableReplyTo=true") - // TODO: Remove the explicit dataSource option - // https://github.com/apache/camel-quarkus/issues/4063 - .to("sql:insert into example(message, origin) values (:#message, 'sqltxRollback')?dataSource=#camel-ds") + .to("sql:insert into example(message, origin) values (:#message, 'sqltxRollback')") .choice() .when(header("message").startsWith("rollback")) .log("Rolling back after rollback message") diff --git a/poms/bom/pom.xml b/poms/bom/pom.xml index 5c1b44be07..01d90230b0 100644 --- a/poms/bom/pom.xml +++ b/poms/bom/pom.xml @@ -8873,6 +8873,16 @@ <artifactId>camel-quarkus-support-jackson-dataformat-xml-deployment</artifactId> <version>${camel-quarkus.version}</version> </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-support-jdbc</artifactId> + <version>${camel-quarkus.version}</version> + </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-support-jdbc-deployment</artifactId> + <version>${camel-quarkus.version}</version> + </dependency> <dependency> <groupId>org.apache.camel.quarkus</groupId> <artifactId>camel-quarkus-support-jetty</artifactId> diff --git a/poms/bom/src/main/generated/flattened-full-pom.xml b/poms/bom/src/main/generated/flattened-full-pom.xml index 9ad9c795b1..312d15a0ef 100644 --- a/poms/bom/src/main/generated/flattened-full-pom.xml +++ b/poms/bom/src/main/generated/flattened-full-pom.xml @@ -8810,6 +8810,16 @@ <artifactId>camel-quarkus-support-jackson-dataformat-xml-deployment</artifactId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} --> <version>2.13.0-SNAPSHOT</version><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} --> </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} --> + <artifactId>camel-quarkus-support-jdbc</artifactId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} --> + <version>2.13.0-SNAPSHOT</version><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} --> + </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} --> + <artifactId>camel-quarkus-support-jdbc-deployment</artifactId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} --> + <version>2.13.0-SNAPSHOT</version><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} --> + </dependency> <dependency> <groupId>org.apache.camel.quarkus</groupId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} --> <artifactId>camel-quarkus-support-jetty</artifactId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} --> diff --git a/poms/bom/src/main/generated/flattened-reduced-pom.xml b/poms/bom/src/main/generated/flattened-reduced-pom.xml index 6ef716cf68..5c9993ea7f 100644 --- a/poms/bom/src/main/generated/flattened-reduced-pom.xml +++ b/poms/bom/src/main/generated/flattened-reduced-pom.xml @@ -8810,6 +8810,16 @@ <artifactId>camel-quarkus-support-jackson-dataformat-xml-deployment</artifactId> <version>2.13.0-SNAPSHOT</version> </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-support-jdbc</artifactId> + <version>2.13.0-SNAPSHOT</version> + </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-support-jdbc-deployment</artifactId> + <version>2.13.0-SNAPSHOT</version> + </dependency> <dependency> <groupId>org.apache.camel.quarkus</groupId> <artifactId>camel-quarkus-support-jetty</artifactId> diff --git a/poms/bom/src/main/generated/flattened-reduced-verbose-pom.xml b/poms/bom/src/main/generated/flattened-reduced-verbose-pom.xml index 2f70e141a0..207a4cddda 100644 --- a/poms/bom/src/main/generated/flattened-reduced-verbose-pom.xml +++ b/poms/bom/src/main/generated/flattened-reduced-verbose-pom.xml @@ -8810,6 +8810,16 @@ <artifactId>camel-quarkus-support-jackson-dataformat-xml-deployment</artifactId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} --> <version>2.13.0-SNAPSHOT</version><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} --> </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} --> + <artifactId>camel-quarkus-support-jdbc</artifactId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} --> + <version>2.13.0-SNAPSHOT</version><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} --> + </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} --> + <artifactId>camel-quarkus-support-jdbc-deployment</artifactId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} --> + <version>2.13.0-SNAPSHOT</version><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} --> + </dependency> <dependency> <groupId>org.apache.camel.quarkus</groupId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} --> <artifactId>camel-quarkus-support-jetty</artifactId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} -->