forked from apache/camel-quarkus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revisit apache#4048 to Springless JPA extension
- Loading branch information
Showing
17 changed files
with
296 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,29 @@ | ||
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, | ||
Refer to the https://quarkus.io/guides/hibernate-orm[Quarkus Hibernate ORM] documentation to see how to configure Hibernate and your datasource. | ||
|
||
Also, it leverages https://quarkus.io/guides/transaction#programmatic-approach[Quarkus TX API] to provide `TransactionStrategy` implementation. | ||
|
||
When a single persistence unit is used, the Camel Quarkus JPA extension will automatically configure the JPA component with a | ||
`EntityManagerFactory` and `TransactionManager`. | ||
`EntityManagerFactory` and `TransactionStrategy`. | ||
|
||
=== Configuring JpaMessageIdRepository | ||
It needs to use `EntityManagerFactory` and `TransactionStrategy` from the CDI container to configure the `JpaMessageIdRepository`: | ||
[source, java] | ||
---- | ||
@Inject | ||
EntityManagerFactory entityManagerFactory; | ||
@Inject | ||
TransactionStrategy transactionStrategy; | ||
from("direct:idempotent") | ||
.idempotentConsumer( | ||
header("messageId"), | ||
new JpaMessageIdRepository(entityManagerFactory, transactionStrategy, "idempotentProcessor")); | ||
---- | ||
|
||
[NOTE] | ||
==== | ||
Since it excludes the `spring-orm` dependency, some options such as `sharedEntityManager`, `transactionManager` are not supported. | ||
==== |
31 changes: 31 additions & 0 deletions
31
...ns/jpa/runtime/src/main/java/org/apache/camel/quarkus/component/jpa/CamelJpaProducer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* 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 jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.enterprise.context.Dependent; | ||
import jakarta.enterprise.inject.Produces; | ||
import org.apache.camel.component.jpa.TransactionStrategy; | ||
|
||
@Dependent | ||
public class CamelJpaProducer { | ||
@Produces | ||
@ApplicationScoped | ||
public TransactionStrategy quarkusTransactionStrategy() { | ||
return new QuarkusTransactionStrategy(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
...time/src/main/java/org/apache/camel/quarkus/component/jpa/QuarkusTransactionStrategy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* 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 io.quarkus.narayana.jta.QuarkusTransaction; | ||
import io.quarkus.narayana.jta.RunOptions; | ||
import org.apache.camel.component.jpa.TransactionStrategy; | ||
|
||
import static io.quarkus.narayana.jta.QuarkusTransaction.runOptions; | ||
|
||
public class QuarkusTransactionStrategy implements TransactionStrategy { | ||
@Override | ||
public void executeInTransaction(Runnable runnable) { | ||
QuarkusTransaction.run(runOptions().semantic(RunOptions.Semantic.JOIN_EXISTING), runnable); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
.../org/apache/camel/quarkus/component/jpa/graal/DefaultTransactionStrategySubstitution.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* 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.graal; | ||
|
||
import com.oracle.svm.core.annotate.Delete; | ||
import com.oracle.svm.core.annotate.TargetClass; | ||
import org.apache.camel.component.jpa.DefaultTransactionStrategy; | ||
|
||
@TargetClass(DefaultTransactionStrategy.class) | ||
@Delete | ||
final public class DefaultTransactionStrategySubstitution { | ||
} |
55 changes: 55 additions & 0 deletions
55
.../src/main/java/org/apache/camel/quarkus/component/jpa/graal/JpaComponentSubstitution.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* 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.graal; | ||
|
||
import com.oracle.svm.core.annotate.Alias; | ||
import com.oracle.svm.core.annotate.Substitute; | ||
import com.oracle.svm.core.annotate.TargetClass; | ||
import jakarta.persistence.EntityManagerFactory; | ||
import org.apache.camel.component.jpa.JpaComponent; | ||
import org.apache.camel.component.jpa.TransactionStrategy; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
@TargetClass(JpaComponent.class) | ||
final public class JpaComponentSubstitution { | ||
@Alias | ||
private TransactionStrategy transactionStrategy; | ||
|
||
@Alias | ||
private EntityManagerFactory entityManagerFactory; | ||
|
||
@Alias | ||
private void initEntityManagerFactory() { | ||
} | ||
|
||
@Substitute | ||
protected void doInit() throws Exception { | ||
initEntityManagerFactory(); | ||
|
||
Logger LOG = LoggerFactory.getLogger(JpaComponent.class); | ||
if (entityManagerFactory == null) { | ||
LOG.warn( | ||
"No EntityManagerFactory has been configured on this JpaComponent. Each JpaEndpoint will auto create their own EntityManagerFactory."); | ||
} | ||
|
||
if (transactionStrategy != null) { | ||
LOG.info("Using TransactionStrategy configured: {}", transactionStrategy); | ||
} | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
...e/src/main/java/org/apache/camel/quarkus/component/jpa/graal/JpaEndpointSubstitution.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* 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.graal; | ||
|
||
import com.oracle.svm.core.annotate.Alias; | ||
import com.oracle.svm.core.annotate.Substitute; | ||
import com.oracle.svm.core.annotate.TargetClass; | ||
import jakarta.persistence.EntityManagerFactory; | ||
import org.apache.camel.component.jpa.JpaEndpoint; | ||
import org.apache.camel.component.jpa.TransactionStrategy; | ||
|
||
@TargetClass(JpaEndpoint.class) | ||
final public class JpaEndpointSubstitution { | ||
@Alias | ||
private TransactionStrategy transactionStrategy; | ||
|
||
@Substitute | ||
protected EntityManagerFactory createEntityManagerFactory() { | ||
throw new UnsupportedOperationException("createEntityManagerFactory is not supported"); | ||
} | ||
|
||
@Substitute | ||
public TransactionStrategy getTransactionStrategy() { | ||
return transactionStrategy; | ||
} | ||
|
||
} |
27 changes: 27 additions & 0 deletions
27
...ons/jpa/runtime/src/main/java/org/springframework/orm/jpa/SharedEntityManagerCreator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* 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.springframework.orm.jpa; | ||
|
||
import jakarta.persistence.EntityManager; | ||
import jakarta.persistence.EntityManagerFactory; | ||
|
||
public abstract class SharedEntityManagerCreator { | ||
public static EntityManager createSharedEntityManager(EntityManagerFactory emf) { | ||
throw new UnsupportedOperationException("createSharedEntityManager is not supported"); | ||
} | ||
} |
Oops, something went wrong.