org.hibernate.tool.hbm2ddl.ImportSqlCommandExtractorInitiator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of hibernate-core Show documentation
Show all versions of hibernate-core Show documentation
JPMS Module-Info's for a few of the Jakarta Libraries just until they add them in themselves
/*
* 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.tool.hbm2ddl;
import java.util.Map;
import org.hibernate.HibernateException;
import org.hibernate.boot.registry.StandardServiceInitiator;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.cfg.Environment;
import org.hibernate.internal.util.StringHelper;
import org.hibernate.service.spi.ServiceRegistryImplementor;
/**
* Instantiates and configures an appropriate {@link ImportSqlCommandExtractor}. By default
* {@link SingleLineSqlCommandExtractor} is used.
*
* @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com)
*/
public class ImportSqlCommandExtractorInitiator implements StandardServiceInitiator {
public static final ImportSqlCommandExtractorInitiator INSTANCE = new ImportSqlCommandExtractorInitiator();
public static final ImportSqlCommandExtractor DEFAULT_EXTRACTOR = new SingleLineSqlCommandExtractor();
@Override
public ImportSqlCommandExtractor initiateService(Map configurationValues, ServiceRegistryImplementor registry) {
String extractorClassName = (String) configurationValues.get( Environment.HBM2DDL_IMPORT_FILES_SQL_EXTRACTOR );
if ( StringHelper.isEmpty( extractorClassName ) ) {
return DEFAULT_EXTRACTOR;
}
final ClassLoaderService classLoaderService = registry.getService( ClassLoaderService.class );
return instantiateExplicitCommandExtractor( extractorClassName, classLoaderService );
}
private ImportSqlCommandExtractor instantiateExplicitCommandExtractor(
String extractorClassName,
ClassLoaderService classLoaderService) {
try {
return (ImportSqlCommandExtractor) classLoaderService.classForName( extractorClassName ).newInstance();
}
catch (Exception e) {
throw new HibernateException(
"Could not instantiate import sql command extractor [" + extractorClassName + "]", e
);
}
}
@Override
public Class getServiceInitiated() {
return ImportSqlCommandExtractor.class;
}
}