
io.quarkus.hibernate.orm.runtime.JPAConfig Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of quarkus-hibernate-orm Show documentation
Show all versions of quarkus-hibernate-orm Show documentation
Define your persistent model with Hibernate ORM and JPA
package io.quarkus.hibernate.orm.runtime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import jakarta.enterprise.context.spi.CreationalContext;
import jakarta.inject.Inject;
import jakarta.persistence.EntityManagerFactory;
import jakarta.persistence.Persistence;
import org.jboss.logging.Logger;
import io.quarkus.arc.BeanDestroyer;
import io.quarkus.hibernate.orm.runtime.boot.QuarkusPersistenceUnitDescriptor;
public class JPAConfig {
private static final Logger LOGGER = Logger.getLogger(JPAConfig.class.getName());
private final Map persistenceUnits = new HashMap<>();
private final Set deactivatedPersistenceUnitNames = new HashSet<>();
@Inject
public JPAConfig(HibernateOrmRuntimeConfig hibernateOrmRuntimeConfig) {
for (QuarkusPersistenceUnitDescriptor descriptor : PersistenceUnitsHolder.getPersistenceUnitDescriptors()) {
String puName = descriptor.getName();
var puConfig = hibernateOrmRuntimeConfig.persistenceUnits().get(descriptor.getConfigurationName());
if (puConfig.active().isPresent() && !puConfig.active().get()) {
LOGGER.infof("Hibernate ORM persistence unit '%s' was deactivated through configuration properties",
puName);
deactivatedPersistenceUnitNames.add(puName);
} else {
persistenceUnits.put(puName, new LazyPersistenceUnit(puName));
}
}
}
void startAll() {
List> start = new ArrayList<>();
//by using a dedicated thread for starting up the PR,
//we work around https://github.com/quarkusio/quarkus/issues/17304 to some extent
//as the main thread is now no longer polluted with ThreadLocals by default
//this is not a complete fix, but will help as long as the test methods
//don't access the datasource directly, but only over HTTP calls
boolean moreThanOneThread = persistenceUnits.size() > 1;
//start PUs in parallel, for faster startup
for (Map.Entry i : persistenceUnits.entrySet()) {
CompletableFuture
© 2015 - 2025 Weber Informatics LLC | Privacy Policy