-
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.
Reworked the plugin to create injection points for each defined Persi…
…stenceUnit found in the config file
- Loading branch information
Eddie Carpenter
committed
Jun 21, 2024
1 parent
95073d9
commit baca9e8
Showing
12 changed files
with
263 additions
and
184 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
lombok.log.fieldName=LOG |
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
70 changes: 70 additions & 0 deletions
70
jpalite-quarkus-extension/runtime/src/main/java/io/jpalite/extension/JPALiteRecorder.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,70 @@ | ||
/* | ||
* 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 io.jpalite.extension; | ||
|
||
import io.quarkus.arc.SyntheticCreationalContext; | ||
import io.quarkus.runtime.annotations.Recorder; | ||
import jakarta.inject.Inject; | ||
import jakarta.persistence.EntityManager; | ||
import jakarta.persistence.EntityManagerFactory; | ||
import jakarta.persistence.Persistence; | ||
import jakarta.transaction.TransactionManager; | ||
import jakarta.transaction.TransactionSynchronizationRegistry; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
import java.util.Map; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
import java.util.function.Function; | ||
|
||
@Slf4j | ||
@Recorder | ||
public class JPALiteRecorder | ||
{ | ||
private final Map<String, EntityManagerFactory> entityManagerFactoryList = new ConcurrentHashMap<>(); | ||
|
||
@Inject | ||
TransactionManager transactionManager; | ||
Check warning on line 41 in jpalite-quarkus-extension/runtime/src/main/java/io/jpalite/extension/JPALiteRecorder.java GitHub Actions / qodanaInjection point with ambiguous dependencies
|
||
|
||
@Inject | ||
TransactionSynchronizationRegistry transactionSynchronizationRegistry; | ||
Check warning on line 44 in jpalite-quarkus-extension/runtime/src/main/java/io/jpalite/extension/JPALiteRecorder.java GitHub Actions / qodanaInjection point with ambiguous dependencies
|
||
|
||
public Function<SyntheticCreationalContext<EntityManagerFactory>, EntityManagerFactory> entityManagerFactorySupplier(String persistenceUnitName) | ||
{ | ||
return context -> entityManagerFactoryList.computeIfAbsent(persistenceUnitName, Persistence::createEntityManagerFactory); | ||
} | ||
|
||
public EntityManager getEntityManager(String persistenceUnit) | ||
{ | ||
EntityManagerFactory factory = entityManagerFactoryList.computeIfAbsent(persistenceUnit, Persistence::createEntityManagerFactory); | ||
return new TransactionScopedEntityManagerImpl(factory, | ||
transactionManager, | ||
transactionSynchronizationRegistry); | ||
}//getEntityManager | ||
|
||
public Function<SyntheticCreationalContext<EntityManager>, EntityManager> entityManagerSupplier(String persistenceUnitName) | ||
{ | ||
return context -> { | ||
TransactionManager transactionManager = context.getInjectedReference(TransactionManager.class); | ||
TransactionSynchronizationRegistry transactionSynchronizationRegistry = context.getInjectedReference(TransactionSynchronizationRegistry.class); | ||
EntityManagerFactory factory = entityManagerFactoryList.computeIfAbsent(persistenceUnitName, Persistence::createEntityManagerFactory); | ||
return new TransactionScopedEntityManagerImpl(factory, | ||
transactionManager, | ||
transactionSynchronizationRegistry); | ||
}; | ||
} | ||
} |
Oops, something went wrong.