Skip to content

Commit

Permalink
[#1425] Retain configurations added through MetadataContributor in …
Browse files Browse the repository at this point in the history
…Quarkus integration
  • Loading branch information
beikov committed Jan 16, 2022
1 parent 38ac606 commit 907a9b0
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Not yet released
* Fix dev UI support for Quarkus 2
* Fix support for non-public `@PostLoad` methods in entity view annotation processor
* Fix lookup of constantified attributes in functional dependency analysis
* Retain configurations added through `MetadataContributor` in Quarkus integration

### Backwards-incompatible changes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.blazebit.persistence.integration.hibernate;

import org.hibernate.boot.model.relational.SqlStringGenerationContext;
import org.hibernate.boot.model.relational.internal.SqlStringGenerationContextImpl;
import org.hibernate.boot.spi.MetadataImplementor;
import org.hibernate.boot.spi.SessionFactoryOptions;
import org.hibernate.engine.jdbc.connections.spi.JdbcConnectionAccess;
Expand Down Expand Up @@ -69,6 +70,13 @@ public DeleteHandler buildDeleteHandler(SessionFactoryImplementor factory, HqlSq
return delegate.buildDeleteHandler(factory, walker);
}

public void prepare(JdbcServices jdbcServices, JdbcConnectionAccess connectionAccess, MetadataImplementor metadata, SessionFactoryOptions sessionFactoryOptions) {
final SqlStringGenerationContext sqlStringGenerationContext = SqlStringGenerationContextImpl.fromExplicit(
jdbcServices.getJdbcEnvironment(), metadata.getDatabase(),
sessionFactoryOptions.getDefaultCatalog(), sessionFactoryOptions.getDefaultSchema());
delegate.prepare(jdbcServices, connectionAccess, metadata, sessionFactoryOptions, sqlStringGenerationContext);
}

@Override
public void prepare(JdbcServices jdbcServices, JdbcConnectionAccess connectionAccess, MetadataImplementor metadata, SessionFactoryOptions sessionFactoryOptions, SqlStringGenerationContext sqlStringGenerationContext) {
delegate.prepare(jdbcServices, connectionAccess, metadata, sessionFactoryOptions, sqlStringGenerationContext);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import com.blazebit.persistence.impl.function.entity.ValuesEntity;
import com.blazebit.persistence.integration.quarkus.runtime.BlazePersistenceConfiguration;
import com.blazebit.persistence.integration.quarkus.runtime.BlazePersistenceHibernateOrmIntegrationStaticInitListener;
import com.blazebit.persistence.integration.quarkus.runtime.BlazePersistenceInstance;
import com.blazebit.persistence.integration.quarkus.runtime.BlazePersistenceInstanceConfiguration;
import com.blazebit.persistence.integration.quarkus.runtime.BlazePersistenceInstanceUtil;
Expand All @@ -38,6 +39,7 @@
import io.quarkus.deployment.builditem.nativeimage.ServiceProviderBuildItem;
import io.quarkus.hibernate.orm.deployment.AdditionalJpaModelBuildItem;
import io.quarkus.hibernate.orm.deployment.PersistenceUnitDescriptorBuildItem;
import io.quarkus.hibernate.orm.deployment.integration.HibernateOrmIntegrationStaticConfiguredBuildItem;
import io.quarkus.hibernate.orm.runtime.PersistenceUnitUtil;
import io.quarkus.runtime.configuration.ConfigurationException;
import org.jboss.jandex.AnnotationInstance;
Expand Down Expand Up @@ -97,6 +99,13 @@ AdditionalIndexedClassesBuildItem addBlazePersistenceInstanceAnnotationToIndex()
return new AdditionalIndexedClassesBuildItem(BlazePersistenceInstance.class.getName());
}

@BuildStep
void addBlazePersistenceIntegrationDescriptor(List<PersistenceUnitDescriptorBuildItem> persistenceUnitDescriptors, BuildProducer<HibernateOrmIntegrationStaticConfiguredBuildItem> staticConfiguredBuildItemBuildProducer) {
for (PersistenceUnitDescriptorBuildItem persistenceUnitDescriptor : persistenceUnitDescriptors) {
staticConfiguredBuildItemBuildProducer.produce(new HibernateOrmIntegrationStaticConfiguredBuildItem(FEATURE, persistenceUnitDescriptor.getPersistenceUnitName()).setInitListener(new BlazePersistenceHibernateOrmIntegrationStaticInitListener()));
}
}

@BuildStep
void addBlazePersistenceEntities(BuildProducer<AdditionalJpaModelBuildItem> jpaModelBuildItemBuildProducer) {
Constructor<AdditionalJpaModelBuildItem> constructor = (Constructor<AdditionalJpaModelBuildItem>) AdditionalJpaModelBuildItem.class.getDeclaredConstructors()[0];
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright 2014 - 2022 Blazebit.
*
* Licensed 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 com.blazebit.persistence.integration.quarkus.runtime;

import io.quarkus.hibernate.orm.runtime.integration.HibernateOrmIntegrationStaticInitListener;
import org.hibernate.boot.Metadata;
import org.hibernate.boot.spi.BootstrapContext;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.engine.config.spi.ConfigurationService;

import java.util.function.BiConsumer;

/**
* @author Christian Beikov
* @since 1.6.5
*/
public class BlazePersistenceHibernateOrmIntegrationStaticInitListener implements HibernateOrmIntegrationStaticInitListener {
@Override
public void contributeBootProperties(BiConsumer<String, Object> propertyCollector) {
}

@Override
public void onMetadataInitialized(Metadata metadata, BootstrapContext bootstrapContext, BiConsumer<String, Object> propertyCollector) {
// Carry over the configured bulk-id strategy from Hibernate56MetadataContributor
propertyCollector.accept(AvailableSettings.HQL_BULK_ID_STRATEGY, bootstrapContext.getServiceRegistry().getService(ConfigurationService.class).getSettings().get(AvailableSettings.HQL_BULK_ID_STRATEGY));
}
}

0 comments on commit 907a9b0

Please sign in to comment.