All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.hibernate.testing.boot.ServiceRegistryTestingImpl Maven / Gradle / Ivy

There is a newer version: 7.0.0.Beta1
Show newest version
/*
 * Hibernate, Relational Persistence for Idiomatic Java
 *
 * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
 * See the lgpl.txt file in the root directory or .
 */
package org.hibernate.testing.boot;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import org.hibernate.boot.registry.BootstrapServiceRegistry;
import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder;
import org.hibernate.boot.registry.StandardServiceInitiator;
import org.hibernate.boot.registry.internal.StandardServiceRegistryImpl;
import org.hibernate.cfg.Environment;
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
import org.hibernate.engine.jdbc.dialect.spi.DialectFactory;
import org.hibernate.service.StandardServiceInitiators;
import org.hibernate.service.internal.ProvidedService;
import org.hibernate.service.spi.ServiceRegistryImplementor;

import org.hibernate.testing.env.ConnectionProviderBuilder;

/**
 * ServiceRegistry useful in testing
 *
 * @author Steve Ebersole
 */
public class ServiceRegistryTestingImpl
		extends StandardServiceRegistryImpl
		implements ServiceRegistryImplementor {

	public static ServiceRegistryTestingImpl forUnitTesting() {
		return new ServiceRegistryTestingImpl(
				true,
				new BootstrapServiceRegistryBuilder().build(),
				StandardServiceInitiators.LIST,
				Arrays.asList(
						dialectFactoryService(),
						connectionProviderService()
				),
				Environment.getProperties()
		);
	}

	public static ServiceRegistryTestingImpl forUnitTesting(Map settings) {
		return new ServiceRegistryTestingImpl(
				true,
				new BootstrapServiceRegistryBuilder().build(),
				StandardServiceInitiators.LIST,
				Arrays.asList(
						dialectFactoryService(),
						connectionProviderService()
				),
				settings
		);
	}

	private static ProvidedService dialectFactoryService() {
		return new ProvidedService( DialectFactory.class, new DialectFactoryTestingImpl() );
	}

	private static ProvidedService connectionProviderService() {
		return new ProvidedService(
				ConnectionProvider.class,
				ConnectionProviderBuilder.buildConnectionProvider( true )
		);
	}

	public ServiceRegistryTestingImpl(
			boolean autoCloseRegistry,
			BootstrapServiceRegistry bootstrapServiceRegistry,
			List serviceInitiators,
			List providedServices,
			Map configurationValues) {
		super( autoCloseRegistry, bootstrapServiceRegistry, serviceInitiators, providedServices, configurationValues );
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy