Skip to content

Commit

Permalink
Remove QuarkusMutableIdentifierGeneratorFactory
Browse files Browse the repository at this point in the history
It no longer has a purpose:

1. We removed the type caching in a previous commit, because it wasn't
   used anymore: ORM hasn't needed access to generator types at runtime
   for a while now.
2. StandardIdentifierGeneratorFactory has a constructor parameter to
   disable reliance on CDI, so we don't need to rewrite that code.
3. StandardIdentifierGeneratorFactory is registering custom generators
   itself, so we don't need to make `register` public to register them
   externally.
  • Loading branch information
yrodiere committed Jul 1, 2024
1 parent f54e8c4 commit 6b3dc9c
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 259 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,12 @@
import org.hibernate.boot.model.process.spi.MetadataBuildingProcess;
import org.hibernate.boot.registry.StandardServiceRegistry;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.boot.registry.selector.spi.StrategySelector;
import org.hibernate.boot.spi.MetadataBuilderContributor;
import org.hibernate.boot.spi.MetadataBuilderImplementor;
import org.hibernate.cache.internal.CollectionCacheInvalidator;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.dialect.Dialect;
import org.hibernate.engine.jdbc.dialect.spi.DialectFactory;
import org.hibernate.id.factory.IdentifierGeneratorFactory;
import org.hibernate.integrator.spi.Integrator;
import org.hibernate.internal.EntityManagerMessageLogger;
import org.hibernate.internal.util.StringHelper;
Expand All @@ -60,7 +58,6 @@
import org.hibernate.jpa.boot.spi.TypeContributorList;
import org.hibernate.jpa.internal.util.LogHelper;
import org.hibernate.jpa.internal.util.PersistenceUnitTransactionTypeHelper;
import org.hibernate.jpa.spi.IdentifierGeneratorStrategyProvider;
import org.hibernate.resource.jdbc.spi.PhysicalConnectionHandlingMode;
import org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorBuilderImpl;
import org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorBuilderImpl;
Expand All @@ -80,7 +77,6 @@
import io.quarkus.hibernate.orm.runtime.recording.PrevalidatedQuarkusMetadata;
import io.quarkus.hibernate.orm.runtime.recording.RecordableBootstrap;
import io.quarkus.hibernate.orm.runtime.recording.RecordedState;
import io.quarkus.hibernate.orm.runtime.service.QuarkusMutableIdentifierGeneratorFactory;
import io.quarkus.hibernate.orm.runtime.service.QuarkusStaticInitDialectFactory;
import io.quarkus.hibernate.orm.runtime.tenant.HibernateMultiTenantConnectionProvider;

Expand Down Expand Up @@ -144,7 +140,6 @@ public FastBootMetadataBuilder(final QuarkusPersistenceUnitDefinition puDefiniti
ssrBuilder.applySettings(buildTimeSettings.getAllSettings());

this.standardServiceRegistry = ssrBuilder.build();
registerIdentifierGenerators(standardServiceRegistry);

this.providedServices = ssrBuilder.getProvidedServices();

Expand Down Expand Up @@ -615,32 +610,6 @@ private static void applyTransactionProperties(PersistenceUnitDescriptor persist
}
}

private void registerIdentifierGenerators(StandardServiceRegistry ssr) {
final StrategySelector strategySelector = ssr.getService(StrategySelector.class);

// apply id generators
final Object idGeneratorStrategyProviderSetting = buildTimeSettings
.get(AvailableSettings.IDENTIFIER_GENERATOR_STRATEGY_PROVIDER);
if (idGeneratorStrategyProviderSetting != null) {
final IdentifierGeneratorStrategyProvider idGeneratorStrategyProvider = strategySelector
.resolveStrategy(IdentifierGeneratorStrategyProvider.class, idGeneratorStrategyProviderSetting);
final IdentifierGeneratorFactory identifierGeneratorFactory = ssr
.getService(IdentifierGeneratorFactory.class);
if (identifierGeneratorFactory == null) {
throw persistenceException("Application requested custom identifier generator strategies, "
+ "but the MutableIdentifierGeneratorFactory could not be found");
}
if (!(identifierGeneratorFactory instanceof QuarkusMutableIdentifierGeneratorFactory)) {
throw persistenceException(
"Unexpected implementation of IdentifierGeneratorFactory: do not override core components");
}
final QuarkusMutableIdentifierGeneratorFactory qIdGenerator = (QuarkusMutableIdentifierGeneratorFactory) identifierGeneratorFactory;
for (Map.Entry<String, Class<?>> entry : idGeneratorStrategyProvider.getStrategies().entrySet()) {
qIdGenerator.register(entry.getKey(), entry.getValue());
}
}
}

/**
* Greatly simplified copy of
* org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl#populate(org.hibernate.boot.MetadataBuilder,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,21 @@

import org.hibernate.boot.registry.StandardServiceInitiator;
import org.hibernate.id.factory.IdentifierGeneratorFactory;
import org.hibernate.id.factory.internal.StandardIdentifierGeneratorFactory;
import org.hibernate.service.spi.ServiceRegistryImplementor;

/**
* We need to mimic the standard IdentifierGeneratorFactory but allowing
* to capture which Identifier strategies are being used, so that we can keep a reference to the classed
* needed at runtime.
* Uses a StandardIdentifierGeneratorFactory, but one that doesn't retrieve generators from CDI.
*
* @see IdentifierGeneratorFactory
*/
public final class QuarkusMutableIdentifierGeneratorFactoryInitiator
public final class QuarkusIdentifierGeneratorFactoryInitiator
implements StandardServiceInitiator<IdentifierGeneratorFactory> {

@Override
public IdentifierGeneratorFactory initiateService(final Map configurationValues,
final ServiceRegistryImplementor registry) {
return new QuarkusMutableIdentifierGeneratorFactory(registry);
return new StandardIdentifierGeneratorFactory(registry, true /* ignore bean container */);
}

@Override
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ public List<StandardServiceInitiator<?>> initialInitiatorList() {
serviceInitiators.add(JdbcServicesInitiator.INSTANCE);
serviceInitiators.add(RefCursorSupportInitiator.INSTANCE);

// Custom one! Also, this one has state so can't use the singleton.
serviceInitiators.add(new QuarkusMutableIdentifierGeneratorFactoryInitiator());// MutableIdentifierGeneratorFactoryInitiator.INSTANCE);
// Custom one!
serviceInitiators.add(new QuarkusIdentifierGeneratorFactoryInitiator());

serviceInitiators.add(QuarkusJtaPlatformInitiator.INSTANCE);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
import io.quarkus.hibernate.orm.runtime.customized.BootstrapOnlyProxyFactoryFactoryInitiator;
import io.quarkus.hibernate.orm.runtime.customized.QuarkusJndiServiceInitiator;
import io.quarkus.hibernate.orm.runtime.service.InitialInitiatorListProvider;
import io.quarkus.hibernate.orm.runtime.service.QuarkusIdentifierGeneratorFactoryInitiator;
import io.quarkus.hibernate.orm.runtime.service.QuarkusImportSqlCommandExtractorInitiator;
import io.quarkus.hibernate.orm.runtime.service.QuarkusMutableIdentifierGeneratorFactoryInitiator;
import io.quarkus.hibernate.orm.runtime.service.QuarkusRegionFactoryInitiator;
import io.quarkus.hibernate.orm.runtime.service.QuarkusStaticInitDialectFactoryInitiator;
import io.quarkus.hibernate.orm.runtime.service.StandardHibernateORMInitiatorListProvider;
Expand Down Expand Up @@ -96,8 +96,8 @@ public List<StandardServiceInitiator<?>> initialInitiatorList() {
serviceInitiators.add(JdbcServicesInitiator.INSTANCE);
serviceInitiators.add(RefCursorSupportInitiator.INSTANCE);

// Custom one! Also, this one has state so can't use the singleton.
serviceInitiators.add(new QuarkusMutableIdentifierGeneratorFactoryInitiator());// MutableIdentifierGeneratorFactoryInitiator.INSTANCE);
// Custom one!
serviceInitiators.add(new QuarkusIdentifierGeneratorFactoryInitiator());

// Custom for Hibernate Reactive:
serviceInitiators.add(NoJtaPlatformInitiator.INSTANCE);
Expand Down

0 comments on commit 6b3dc9c

Please sign in to comment.