This is an automated email from the ASF dual-hosted git repository. jamesnetherton pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git
The following commit(s) were added to refs/heads/master by this push: new 0684fee Add JPA extension 0684fee is described below commit 0684fee6e361b6f3788cf10c8fb447e09ecf007a Author: James Netherton <jamesnether...@gmail.com> AuthorDate: Thu Jul 9 13:51:41 2020 +0100 Add JPA extension Fixes #889 --- docs/modules/ROOT/pages/extensions/jpa.adoc | 38 ++++++ .../pages/list-of-camel-quarkus-extensions.adoc | 4 +- extensions/jpa/deployment/pom.xml | 71 +++++++++++ .../component/jpa/deployment/JpaProcessor.java | 63 ++++++++++ extensions/jpa/pom.xml | 39 ++++++ extensions/jpa/runtime/pom.xml | 106 ++++++++++++++++ .../jpa/runtime/src/main/doc/configuration.adoc | 6 + .../quarkus/component/jpa/CamelJpaRecorder.java | 38 ++++++ .../main/resources/META-INF/quarkus-extension.yaml | 29 +++++ extensions/pom.xml | 1 + integration-tests/jpa/pom.xml | 139 +++++++++++++++++++++ .../quarkus/component/jpa/it/JpaResource.java | 59 +++++++++ .../quarkus/component/jpa/it/model/Fruit.java | 57 +++++++++ .../jpa/src/main/resources/application.properties | 22 ++++ .../camel/quarkus/component/jpa/it/JpaIT.java | 24 ++++ .../camel/quarkus/component/jpa/it/JpaTest.java | 52 ++++++++ integration-tests/pom.xml | 1 + poms/bom/pom.xml | 21 ++++ tooling/scripts/test-categories.yaml | 1 + 19 files changed, 770 insertions(+), 1 deletion(-) diff --git a/docs/modules/ROOT/pages/extensions/jpa.adoc b/docs/modules/ROOT/pages/extensions/jpa.adoc new file mode 100644 index 0000000..1380339 --- /dev/null +++ b/docs/modules/ROOT/pages/extensions/jpa.adoc @@ -0,0 +1,38 @@ +// Do not edit directly! +// This file was generated by camel-quarkus-maven-plugin:update-extension-doc-page + +[[jpa]] += JPA + +[.badges] +[.badge-key]##Since Camel Quarkus##[.badge-version]##1.0.0-CR4## [.badge-key]##JVM##[.badge-supported]##supported## [.badge-key]##Native##[.badge-supported]##supported## + +Store and retrieve Java objects from databases using Java Persistence API (JPA). + +== What's inside + +* https://camel.apache.org/components/latest/jpa-component.html[JPA component], URI syntax: `jpa:entityType` + +Please refer to the above link for usage and configuration details. + +== Maven coordinates + +[source,xml] +---- +<dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-jpa</artifactId> +</dependency> +---- + +Check the xref:user-guide/index.adoc[User guide] for more information about writing Camel Quarkus applications. + +== Additional Camel Quarkus configuration + +The extension leverages https://quarkus.io/guides/hibernate-orm[Quarkus Hibernate ORM] to provide the JPA implementation via Hibernate. + +Refer to the https://quarkus.io/guides/hibernate-orm[Quarkus Hibernate ORM] documentation to see how to configure Hibernate and your datasource, + +When a single persistence unit is used, the Camel Quarkus JPA extension will automatically configure the JPA component with a +`EntityManagerFactory` and `TransactionManager`. + diff --git a/docs/modules/ROOT/pages/list-of-camel-quarkus-extensions.adoc b/docs/modules/ROOT/pages/list-of-camel-quarkus-extensions.adoc index 823d5f1..b5b03d3 100644 --- a/docs/modules/ROOT/pages/list-of-camel-quarkus-extensions.adoc +++ b/docs/modules/ROOT/pages/list-of-camel-quarkus-extensions.adoc @@ -18,7 +18,7 @@ In case you are missing some Camel feature in the list: == Camel Components // components: START -Number of Camel components: 154 in 119 JAR artifacts (0 deprecated) +Number of Camel components: 155 in 120 JAR artifacts (0 deprecated) [width="100%",cols="4,1,1,1,5",options="header"] |=== @@ -190,6 +190,8 @@ Number of Camel components: 154 in 119 JAR artifacts (0 deprecated) | xref:extensions/jolt.adoc[JOLT] | camel-quarkus-jolt | Native + Stable | 1.0.0-CR3 | JSON to JSON transformation using JOLT. +| xref:extensions/jpa.adoc[JPA] | camel-quarkus-jpa | Native + Stable | 1.0.0-CR4 | Store and retrieve Java objects from databases using Java Persistence API (JPA). + | xref:extensions/json-validator.adoc[JSON Schema Validator] | camel-quarkus-json-validator | Native + Stable | 1.0.0-CR3 | Validate JSON payloads using NetworkNT JSON Schema. | xref:extensions/kafka.adoc[Kafka] | camel-quarkus-kafka | Native + Stable | 1.0.0-M1 | Sent and receive messages to/from an Apache Kafka broker. diff --git a/extensions/jpa/deployment/pom.xml b/extensions/jpa/deployment/pom.xml new file mode 100644 index 0000000..4c47be4 --- /dev/null +++ b/extensions/jpa/deployment/pom.xml @@ -0,0 +1,71 @@ +<?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"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-jpa-parent</artifactId> + <version>1.1.0-SNAPSHOT</version> + <relativePath>../pom.xml</relativePath> + </parent> + + <artifactId>camel-quarkus-jpa-deployment</artifactId> + <name>Camel Quarkus :: JPA :: Deployment</name> + + <dependencies> + <dependency> + <groupId>io.quarkus</groupId> + <artifactId>quarkus-hibernate-orm-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-support-spring-deployment</artifactId> + </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-jpa</artifactId> + </dependency> + </dependencies> + + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <configuration> + <annotationProcessorPaths> + <path> + <groupId>io.quarkus</groupId> + <artifactId>quarkus-extension-processor</artifactId> + <version>${quarkus.version}</version> + </path> + </annotationProcessorPaths> + </configuration> + </plugin> + </plugins> + </build> + +</project> diff --git a/extensions/jpa/deployment/src/main/java/org/apache/camel/quarkus/component/jpa/deployment/JpaProcessor.java b/extensions/jpa/deployment/src/main/java/org/apache/camel/quarkus/component/jpa/deployment/JpaProcessor.java new file mode 100644 index 0000000..10be6fb --- /dev/null +++ b/extensions/jpa/deployment/src/main/java/org/apache/camel/quarkus/component/jpa/deployment/JpaProcessor.java @@ -0,0 +1,63 @@ +/* + * 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.component.jpa.deployment; + +import java.util.List; + +import io.quarkus.arc.deployment.AdditionalBeanBuildItem; +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.deployment.builditem.FeatureBuildItem; +import io.quarkus.hibernate.orm.deployment.PersistenceUnitDescriptorBuildItem; +import io.quarkus.hibernate.orm.runtime.DefaultEntityManagerFactoryProducer; +import org.apache.camel.component.jpa.JpaComponent; +import org.apache.camel.quarkus.component.jpa.CamelJpaRecorder; +import org.apache.camel.quarkus.core.deployment.spi.CamelRuntimeBeanBuildItem; + +class JpaProcessor { + + private static final String FEATURE = "camel-jpa"; + + @BuildStep + FeatureBuildItem feature() { + return new FeatureBuildItem(FEATURE); + } + + @Record(ExecutionTime.RUNTIME_INIT) + @BuildStep + void configureJpaComponentBean( + BuildProducer<CamelRuntimeBeanBuildItem> camelRuntimeBean, + BuildProducer<AdditionalBeanBuildItem> additionalBeans, + List<PersistenceUnitDescriptorBuildItem> descriptors, + CamelJpaRecorder recorder) { + + // If there's only 1 persistent unit, then auto configure the JPA component with the EntityManagerFactory + if (descriptors.size() == 1) { + // Set DefaultEntityManagerFactoryProducer as unremovable as there's no hard requirement for Camel users to @Inject EntityManagerFactory + AdditionalBeanBuildItem bean = AdditionalBeanBuildItem.unremovableOf(DefaultEntityManagerFactoryProducer.class); + additionalBeans.produce(bean); + + camelRuntimeBean.produce( + new CamelRuntimeBeanBuildItem( + "jpa", + JpaComponent.class.getName(), + recorder.createJpaComponent())); + } + } +} diff --git a/extensions/jpa/pom.xml b/extensions/jpa/pom.xml new file mode 100644 index 0000000..ef14169 --- /dev/null +++ b/extensions/jpa/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"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-build-parent</artifactId> + <version>1.1.0-SNAPSHOT</version> + <relativePath>../../poms/build-parent/pom.xml</relativePath> + </parent> + + <artifactId>camel-quarkus-jpa-parent</artifactId> + <name>Camel Quarkus :: JPA</name> + <packaging>pom</packaging> + + <modules> + <module>deployment</module> + <module>runtime</module> + </modules> +</project> diff --git a/extensions/jpa/runtime/pom.xml b/extensions/jpa/runtime/pom.xml new file mode 100644 index 0000000..c5058d5 --- /dev/null +++ b/extensions/jpa/runtime/pom.xml @@ -0,0 +1,106 @@ +<?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"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-jpa-parent</artifactId> + <version>1.1.0-SNAPSHOT</version> + <relativePath>../pom.xml</relativePath> + </parent> + + <artifactId>camel-quarkus-jpa</artifactId> + <name>Camel Quarkus :: JPA :: Runtime</name> + <description>Store and retrieve Java objects from databases using Java Persistence API (JPA).</description> + + <properties> + <firstVersion>1.0.0-CR4</firstVersion> + </properties> + + <dependencyManagement> + <dependencies> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-bom</artifactId> + <version>${project.version}</version> + <type>pom</type> + <scope>import</scope> + </dependency> + </dependencies> + </dependencyManagement> + + <dependencies> + <dependency> + <groupId>io.quarkus</groupId> + <artifactId>quarkus-hibernate-orm</artifactId> + </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-core</artifactId> + </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-support-spring</artifactId> + </dependency> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-jpa</artifactId> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-context</artifactId> + </dependency> + </dependencies> + + <build> + <plugins> + <plugin> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-maven-plugin</artifactId> + <executions> + <execution> + <id>update-extension-doc-page</id> + <goals><goal>update-extension-doc-page</goal></goals> + <phase>process-classes</phase> + </execution> + </executions> + </plugin> + <plugin> + <groupId>io.quarkus</groupId> + <artifactId>quarkus-bootstrap-maven-plugin</artifactId> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <configuration> + <annotationProcessorPaths> + <path> + <groupId>io.quarkus</groupId> + <artifactId>quarkus-extension-processor</artifactId> + <version>${quarkus.version}</version> + </path> + </annotationProcessorPaths> + </configuration> + </plugin> + </plugins> + </build> +</project> diff --git a/extensions/jpa/runtime/src/main/doc/configuration.adoc b/extensions/jpa/runtime/src/main/doc/configuration.adoc new file mode 100644 index 0000000..ebb4d86 --- /dev/null +++ b/extensions/jpa/runtime/src/main/doc/configuration.adoc @@ -0,0 +1,6 @@ +The extension leverages https://quarkus.io/guides/hibernate-orm[Quarkus Hibernate ORM] to provide the JPA implementation via Hibernate. + +Refer to the https://quarkus.io/guides/hibernate-orm[Quarkus Hibernate ORM] documentation to see how to configure Hibernate and your datasource, + +When a single persistence unit is used, the Camel Quarkus JPA extension will automatically configure the JPA component with a +`EntityManagerFactory` and `TransactionManager`. diff --git a/extensions/jpa/runtime/src/main/java/org/apache/camel/quarkus/component/jpa/CamelJpaRecorder.java b/extensions/jpa/runtime/src/main/java/org/apache/camel/quarkus/component/jpa/CamelJpaRecorder.java new file mode 100644 index 0000000..ee5940b --- /dev/null +++ b/extensions/jpa/runtime/src/main/java/org/apache/camel/quarkus/component/jpa/CamelJpaRecorder.java @@ -0,0 +1,38 @@ +/* + * 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.component.jpa; + +import javax.transaction.TransactionManager; +import javax.transaction.UserTransaction; + +import io.quarkus.runtime.RuntimeValue; +import io.quarkus.runtime.annotations.Recorder; +import org.apache.camel.component.jpa.JpaComponent; +import org.springframework.transaction.jta.JtaTransactionManager; + +@Recorder +public class CamelJpaRecorder { + + public RuntimeValue<JpaComponent> createJpaComponent() { + TransactionManager transactionManager = com.arjuna.ats.jta.TransactionManager.transactionManager(); + UserTransaction userTransaction = com.arjuna.ats.jta.UserTransaction.userTransaction(); + + JpaComponent component = new JpaComponent(); + component.setTransactionManager(new JtaTransactionManager(userTransaction, transactionManager)); + return new RuntimeValue<>(component); + } +} diff --git a/extensions/jpa/runtime/src/main/resources/META-INF/quarkus-extension.yaml b/extensions/jpa/runtime/src/main/resources/META-INF/quarkus-extension.yaml new file mode 100644 index 0000000..9e0ba69 --- /dev/null +++ b/extensions/jpa/runtime/src/main/resources/META-INF/quarkus-extension.yaml @@ -0,0 +1,29 @@ +# +# 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. +# + +# This is a generated file. Do not edit directly! +# To re-generate, run the following command from the top level directory: +# +# mvn -N cq:update-quarkus-metadata +# +--- +name: "Camel JPA" +description: "Store and retrieve Java objects from databases using Java Persistence API (JPA)" +metadata: + guide: "https://camel.apache.org/components/latest/jpa-component.html" + categories: + - "integration" diff --git a/extensions/pom.xml b/extensions/pom.xml index 5757f6d..58ecf64 100644 --- a/extensions/pom.xml +++ b/extensions/pom.xml @@ -113,6 +113,7 @@ <module>jms</module> <module>johnzon</module> <module>jolt</module> + <module>jpa</module> <module>json-validator</module> <module>jsonpath</module> <module>jta</module> diff --git a/integration-tests/jpa/pom.xml b/integration-tests/jpa/pom.xml new file mode 100644 index 0000000..aedddb2 --- /dev/null +++ b/integration-tests/jpa/pom.xml @@ -0,0 +1,139 @@ +<?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"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-integration-tests</artifactId> + <version>1.1.0-SNAPSHOT</version> + <relativePath>../pom.xml</relativePath> + </parent> + + <artifactId>camel-quarkus-integration-test-jpa</artifactId> + <name>Camel Quarkus :: Integration Tests :: JPA</name> + <description>Integration tests for Camel Quarkus JPA extension</description> + + <properties> + <!-- mvnd, a.k.a. Maven Daemon: https://github.com/gnodet/mvnd --> + <!-- The following rule tells mvnd to build the listed deployment modules before this module. --> + <!-- This is important because mvnd builds modules in parallel by default. The deployment modules are not --> + <!-- explicit dependencies of this module in the Maven sense, although they are required by the Quarkus Maven plugin. --> + <!-- Please update rule whenever you change the dependencies of this module by running --> + <!-- mvn process-resources -Pformat from the root directory --> + <mvnd.builder.rule>camel-quarkus-jpa-deployment,camel-quarkus-support-policy-deployment</mvnd.builder.rule> + </properties> + + <dependencyManagement> + <dependencies> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-bom-test</artifactId> + <version>${project.version}</version> + <type>pom</type> + <scope>import</scope> + </dependency> + </dependencies> + </dependencyManagement> + + <dependencies> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-jpa</artifactId> + </dependency> + <dependency> + <groupId>io.quarkus</groupId> + <artifactId>quarkus-resteasy</artifactId> + </dependency> + <dependency> + <groupId>io.quarkus</groupId> + <artifactId>quarkus-resteasy-jsonb</artifactId> + </dependency> + <dependency> + <groupId>io.quarkus</groupId> + <artifactId>quarkus-jdbc-h2</artifactId> + </dependency> + + <!-- test dependencies --> + <dependency> + <groupId>io.quarkus</groupId> + <artifactId>quarkus-junit5</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>io.rest-assured</groupId> + <artifactId>rest-assured</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>io.quarkus</groupId> + <artifactId>quarkus-test-h2</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + + <build> + <plugins> + <plugin> + <groupId>io.quarkus</groupId> + <artifactId>quarkus-maven-plugin</artifactId> + <executions> + <execution> + <goals> + <goal>build</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + </build> + + <profiles> + <profile> + <id>native</id> + <activation> + <property> + <name>native</name> + </property> + </activation> + <properties> + <quarkus.package.type>native</quarkus.package.type> + </properties> + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-failsafe-plugin</artifactId> + <executions> + <execution> + <goals> + <goal>integration-test</goal> + <goal>verify</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + </build> + </profile> + </profiles> + +</project> diff --git a/integration-tests/jpa/src/main/java/org/apache/camel/quarkus/component/jpa/it/JpaResource.java b/integration-tests/jpa/src/main/java/org/apache/camel/quarkus/component/jpa/it/JpaResource.java new file mode 100644 index 0000000..76304ef --- /dev/null +++ b/integration-tests/jpa/src/main/java/org/apache/camel/quarkus/component/jpa/it/JpaResource.java @@ -0,0 +1,59 @@ +/* + * 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.component.jpa.it; + +import java.net.URI; +import java.util.List; + +import javax.inject.Inject; +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +import org.apache.camel.ConsumerTemplate; +import org.apache.camel.ProducerTemplate; +import org.apache.camel.quarkus.component.jpa.it.model.Fruit; + +@Path("/jpa") +public class JpaResource { + + @Inject + ProducerTemplate producerTemplate; + + @Inject + ConsumerTemplate consumerTemplate; + + @Path("/get") + @GET + @Produces(MediaType.APPLICATION_JSON) + @SuppressWarnings("unchecked") + public List<Fruit> getFruits() { + return consumerTemplate.receiveBodyNoWait("jpa:" + Fruit.class.getName(), List.class); + } + + @Path("/post") + @POST + @Consumes(MediaType.TEXT_PLAIN) + public Response createFruit(String name) throws Exception { + producerTemplate.sendBody("jpa:" + Fruit.class.getName(), new Fruit(name)); + return Response.created(new URI("https://camel.apache.org/")).build(); + } +} diff --git a/integration-tests/jpa/src/main/java/org/apache/camel/quarkus/component/jpa/it/model/Fruit.java b/integration-tests/jpa/src/main/java/org/apache/camel/quarkus/component/jpa/it/model/Fruit.java new file mode 100644 index 0000000..3cdc0be --- /dev/null +++ b/integration-tests/jpa/src/main/java/org/apache/camel/quarkus/component/jpa/it/model/Fruit.java @@ -0,0 +1,57 @@ +/* + * 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.component.jpa.it.model; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; + +@Entity +public class Fruit { + + @Id + @GeneratedValue + private Integer id; + + @Column(length = 50, unique = true) + private String name; + + public Fruit() { + } + + public Fruit(String name) { + this.name = name; + } + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + +} diff --git a/integration-tests/jpa/src/main/resources/application.properties b/integration-tests/jpa/src/main/resources/application.properties new file mode 100644 index 0000000..d979e98 --- /dev/null +++ b/integration-tests/jpa/src/main/resources/application.properties @@ -0,0 +1,22 @@ +## --------------------------------------------------------------------------- +## 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. +## --------------------------------------------------------------------------- +quarkus.datasource.url=jdbc:h2:tcp://localhost/mem:test +quarkus.datasource.driver=org.h2.Driver +quarkus.datasource.max-size=8 +quarkus.datasource.min-size=2 + +quarkus.hibernate-orm.database.generation=drop-and-create diff --git a/integration-tests/jpa/src/test/java/org/apache/camel/quarkus/component/jpa/it/JpaIT.java b/integration-tests/jpa/src/test/java/org/apache/camel/quarkus/component/jpa/it/JpaIT.java new file mode 100644 index 0000000..33e8391 --- /dev/null +++ b/integration-tests/jpa/src/test/java/org/apache/camel/quarkus/component/jpa/it/JpaIT.java @@ -0,0 +1,24 @@ +/* + * 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.component.jpa.it; + +import io.quarkus.test.junit.NativeImageTest; + +@NativeImageTest +class JpaIT extends JpaTest { + +} diff --git a/integration-tests/jpa/src/test/java/org/apache/camel/quarkus/component/jpa/it/JpaTest.java b/integration-tests/jpa/src/test/java/org/apache/camel/quarkus/component/jpa/it/JpaTest.java new file mode 100644 index 0000000..ac5aa3b --- /dev/null +++ b/integration-tests/jpa/src/test/java/org/apache/camel/quarkus/component/jpa/it/JpaTest.java @@ -0,0 +1,52 @@ +/* + * 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.component.jpa.it; + +import io.quarkus.test.common.QuarkusTestResource; +import io.quarkus.test.h2.H2DatabaseTestResource; +import io.quarkus.test.junit.QuarkusTest; +import io.restassured.RestAssured; +import io.restassured.http.ContentType; +import org.junit.jupiter.api.Test; + +import static org.hamcrest.Matchers.contains; + +@QuarkusTest +@QuarkusTestResource(H2DatabaseTestResource.class) +class JpaTest { + + @Test + public void testJpaComponent() { + String[] fruits = new String[] { "Orange", "Lemon", "Plum" }; + + // Create Fruit entities + for (String fruit : fruits) { + RestAssured.given() + .contentType(ContentType.TEXT) + .body(fruit) + .post("/jpa/post") + .then() + .statusCode(201); + } + + // Retrieve Fruit entities + RestAssured.get("/jpa/get") + .then() + .statusCode(200) + .body("name", contains(fruits)); + } +} diff --git a/integration-tests/pom.xml b/integration-tests/pom.xml index 7bf7399..95519d2 100644 --- a/integration-tests/pom.xml +++ b/integration-tests/pom.xml @@ -100,6 +100,7 @@ <module>jdbc</module> <module>jira</module> <module>jolt</module> + <module>jpa</module> <module>json-validator</module> <module>jsonpath</module> <module>jta</module> diff --git a/poms/bom/pom.xml b/poms/bom/pom.xml index 13332de..4135874 100644 --- a/poms/bom/pom.xml +++ b/poms/bom/pom.xml @@ -773,6 +773,17 @@ </dependency> <dependency> <groupId>org.apache.camel</groupId> + <artifactId>camel-jpa</artifactId> + <version>${camel.version}</version> + <exclusions> + <exclusion> + <groupId>org.apache.camel</groupId> + <artifactId>camel-spring</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.apache.camel</groupId> <artifactId>camel-json-validator</artifactId> <version>${camel.version}</version> </dependency> @@ -2130,6 +2141,16 @@ </dependency> <dependency> <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-jpa</artifactId> + <version>${camel-quarkus.version}</version> + </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-jpa-deployment</artifactId> + <version>${camel-quarkus.version}</version> + </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> <artifactId>camel-quarkus-json-validator</artifactId> <version>${camel-quarkus.version}</version> </dependency> diff --git a/tooling/scripts/test-categories.yaml b/tooling/scripts/test-categories.yaml index fa6396c..3dc42a0 100644 --- a/tooling/scripts/test-categories.yaml +++ b/tooling/scripts/test-categories.yaml @@ -36,6 +36,7 @@ database: - debezium - influxdb - jdbc + - jpa - kudu - mongodb - sql