io.micronaut.configuration.hibernate.jpa.conf.settings.internal.CurrentSessionContextClassSettingSupplier Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of micronaut-hibernate-jpa Show documentation
Show all versions of micronaut-hibernate-jpa Show documentation
Projects to support SQL Database access in Micronaut
/*
* Copyright 2017-2022 original authors
*
* 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
*
* https://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.micronaut.configuration.hibernate.jpa.conf.settings.internal;
import io.micronaut.configuration.hibernate.jpa.HibernateCurrentSessionContextClassProvider;
import io.micronaut.configuration.hibernate.jpa.JpaConfiguration;
import io.micronaut.configuration.hibernate.jpa.conf.settings.SettingsSupplier;
import io.micronaut.context.BeanProvider;
import io.micronaut.context.annotation.Prototype;
import io.micronaut.context.annotation.Requires;
import io.micronaut.core.annotation.Internal;
import io.micronaut.transaction.hibernate6.MicronautSessionContext;
import org.hibernate.cfg.AvailableSettings;
import java.util.Collections;
import java.util.Map;
/**
* Current settings settings supplier.
*
* @author Denis Stepanov
* @since 4.5.0
*/
@Requires(classes = MicronautSessionContext.class)
@Internal
@Prototype
final class CurrentSessionContextClassSettingSupplier implements SettingsSupplier {
private final BeanProvider provider;
CurrentSessionContextClassSettingSupplier(BeanProvider provider) {
this.provider = provider;
}
@Override
public Map supply(JpaConfiguration jpaConfiguration) {
String currentSession = provider.find(null)
.map(provider -> provider.get().getName())
.orElseGet(MicronautSessionContext.class::getName);
return Collections.singletonMap(AvailableSettings.CURRENT_SESSION_CONTEXT_CLASS, currentSession);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy