Skip to content

Commit

Permalink
attempt to fix #877
Browse files Browse the repository at this point in the history
  • Loading branch information
gavinking committed Jul 26, 2021
1 parent 52a98ad commit daf5f2e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.boot.spi.MetadataImplementor;
import org.hibernate.boot.spi.SessionFactoryBuilderImplementor;
import org.hibernate.internal.util.config.ConfigurationHelper;
import org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl;
import org.hibernate.jpa.boot.spi.PersistenceUnitDescriptor;
import org.hibernate.reactive.bulk.impl.ReactiveBulkIdStrategy;
import org.hibernate.reactive.provider.ReactiveServiceRegistryBuilder;
import org.hibernate.reactive.provider.Settings;
import org.hibernate.reactive.provider.service.ReactiveSessionFactoryBuilder;

import javax.persistence.EntityManagerFactory;
Expand Down Expand Up @@ -50,6 +52,8 @@ public EntityManagerFactory build() {
);
optionsBuilder.enableCollectionInDefaultFetchGroup(true);
optionsBuilder.applyMultiTableBulkIdStrategy( new ReactiveBulkIdStrategy( metadata ) );
int batchSize = ConfigurationHelper.getInt( Settings.STATEMENT_BATCH_SIZE, getConfigurationValues(), 0 );
optionsBuilder.applyJdbcBatchSize(batchSize);

final SessionFactoryBuilderImpl defaultBuilder = new SessionFactoryBuilderImpl( metadata, optionsBuilder );
final SessionFactoryBuilderImplementor reactiveSessionFactoryBuilder = new ReactiveSessionFactoryBuilder( metadata, defaultBuilder );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,24 @@
import org.hibernate.boot.spi.BootstrapContext;
import org.hibernate.boot.spi.SessionFactoryBuilderImplementor;
import org.hibernate.boot.spi.SessionFactoryBuilderService;
import org.hibernate.internal.util.config.ConfigurationHelper;
import org.hibernate.reactive.bulk.impl.ReactiveBulkIdStrategy;
import org.hibernate.reactive.provider.Settings;
import org.hibernate.service.spi.Configurable;

import java.util.Map;

/**
* A {@link SessionFactoryBuilderService} that creates instances of {@link ReactiveSessionFactoryBuilder}.
*/
final class ReactiveSessionFactoryBuilderService implements SessionFactoryBuilderService {
final class ReactiveSessionFactoryBuilderService implements SessionFactoryBuilderService, Configurable {

private int batchSize;

@Override
public void configure(Map configurationValues) {
batchSize = ConfigurationHelper.getInt(Settings.STATEMENT_BATCH_SIZE, configurationValues, 0);
}

@Override
public SessionFactoryBuilderImplementor createSessionFactoryBuilder(final MetadataImpl metadata, final BootstrapContext bootstrapContext) {
Expand All @@ -26,6 +38,7 @@ public SessionFactoryBuilderImplementor createSessionFactoryBuilder(final Metada
);
optionsBuilder.enableCollectionInDefaultFetchGroup(true);
optionsBuilder.applyMultiTableBulkIdStrategy( new ReactiveBulkIdStrategy( metadata ) );
optionsBuilder.applyJdbcBatchSize(batchSize);
return new ReactiveSessionFactoryBuilder( metadata, new SessionFactoryBuilderImpl( metadata, optionsBuilder ) );
}

Expand Down

0 comments on commit daf5f2e

Please sign in to comment.