-
Notifications
You must be signed in to change notification settings - Fork 194
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Revert "Fixed JPA (CAMEL-19225)" This reverts commit 256e2f9. * Revisit #4048 to Springless JPA extension * Apply suggestions from code review Co-authored-by: James Netherton <[email protected]> * Fix jpa docs * Refactor graal substitution --------- Co-authored-by: James Netherton <[email protected]>
- Loading branch information
1 parent
83e7d46
commit 770223e
Showing
15 changed files
with
284 additions
and
48 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,3 +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 `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(); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
...ns/jpa/runtime/src/main/java/org/apache/camel/quarkus/component/jpa/CamelJpaRecorder.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.runtime.RuntimeValue; | ||
import io.quarkus.runtime.annotations.Recorder; | ||
import org.apache.camel.component.jpa.JpaComponent; | ||
|
||
@Recorder | ||
public class CamelJpaRecorder { | ||
|
||
public RuntimeValue<JpaComponent> createJpaComponent() { | ||
JpaComponent component = new JpaComponent(); | ||
component.setTransactionStrategy(new QuarkusTransactionStrategy()); | ||
return new RuntimeValue<>(component); | ||
} | ||
} |
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); | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
...a/runtime/src/main/java/org/apache/camel/quarkus/component/jpa/graal/JpaSubstitution.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,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.graal; | ||
|
||
import com.oracle.svm.core.annotate.Alias; | ||
import com.oracle.svm.core.annotate.Delete; | ||
import com.oracle.svm.core.annotate.Substitute; | ||
import com.oracle.svm.core.annotate.TargetClass; | ||
import jakarta.persistence.EntityManagerFactory; | ||
import org.apache.camel.component.jpa.DefaultTransactionStrategy; | ||
import org.apache.camel.component.jpa.JpaComponent; | ||
import org.apache.camel.component.jpa.JpaEndpoint; | ||
import org.apache.camel.component.jpa.TransactionStrategy; | ||
|
||
final public class JpaSubstitution { | ||
} | ||
|
||
@TargetClass(JpaEndpoint.class) | ||
final class JpaEndpointSubstitution { | ||
@Alias | ||
private TransactionStrategy transactionStrategy; | ||
|
||
@Substitute | ||
protected EntityManagerFactory createEntityManagerFactory() { | ||
throw new UnsupportedOperationException("createEntityManagerFactory is not supported"); | ||
} | ||
|
||
@Substitute | ||
public TransactionStrategy getTransactionStrategy() { | ||
return transactionStrategy; | ||
} | ||
} | ||
|
||
@TargetClass(JpaComponent.class) | ||
final class JpaComponentSubstitution { | ||
@Substitute | ||
private void createTransactionStrategy() { | ||
} | ||
} | ||
|
||
@TargetClass(DefaultTransactionStrategy.class) | ||
@Delete | ||
final class DefaultTransactionStrategySubstitution { | ||
} |
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"); | ||
} | ||
} |
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
Oops, something went wrong.