use of org.hibernate.boot.registry.classloading.spi.ClassLoaderService in project hibernate-orm by hibernate.
the class SimpleValue method createParameterImpl.
private void createParameterImpl() {
try {
String[] columnsNames = new String[columns.size()];
for (int i = 0; i < columns.size(); i++) {
Selectable column = columns.get(i);
if (column instanceof Column) {
columnsNames[i] = ((Column) column).getName();
}
}
final XProperty xProperty = (XProperty) typeParameters.get(DynamicParameterizedType.XPROPERTY);
// todo : not sure this works for handling @MapKeyEnumerated
final Annotation[] annotations = xProperty == null ? null : xProperty.getAnnotations();
final ClassLoaderService classLoaderService = getMetadata().getMetadataBuildingOptions().getServiceRegistry().getService(ClassLoaderService.class);
typeParameters.put(DynamicParameterizedType.PARAMETER_TYPE, new ParameterTypeImpl(classLoaderService.classForName(typeParameters.getProperty(DynamicParameterizedType.RETURNED_CLASS)), annotations, table.getCatalog(), table.getSchema(), table.getName(), Boolean.valueOf(typeParameters.getProperty(DynamicParameterizedType.IS_PRIMARY_KEY)), columnsNames));
} catch (ClassLoadingException e) {
throw new MappingException("Could not create DynamicParameterizedType for type: " + typeName, e);
}
}
use of org.hibernate.boot.registry.classloading.spi.ClassLoaderService in project hibernate-orm by hibernate.
the class SimpleValue method setTypeName.
public void setTypeName(String typeName) {
if (typeName != null && typeName.startsWith(AttributeConverterTypeAdapter.NAME_PREFIX)) {
final String converterClassName = typeName.substring(AttributeConverterTypeAdapter.NAME_PREFIX.length());
final ClassLoaderService cls = getMetadata().getMetadataBuildingOptions().getServiceRegistry().getService(ClassLoaderService.class);
try {
final Class<AttributeConverter> converterClass = cls.classForName(converterClassName);
attributeConverterDescriptor = new AttributeConverterDescriptorNonAutoApplicableImpl(converterClass.newInstance());
return;
} catch (Exception e) {
log.logBadHbmAttributeConverterType(typeName, e.getMessage());
}
}
this.typeName = typeName;
}
use of org.hibernate.boot.registry.classloading.spi.ClassLoaderService in project hibernate-orm by hibernate.
the class SchemaCreatorImpl method applyImportSources.
private void applyImportSources(ExecutionOptions options, ImportSqlCommandExtractor commandExtractor, boolean format, GenerationTarget... targets) {
final ServiceRegistry serviceRegistry = tool.getServiceRegistry();
final ClassLoaderService classLoaderService = serviceRegistry.getService(ClassLoaderService.class);
// I have had problems applying the formatter to these imported statements.
// and legacy SchemaExport did not format them, so doing same here
//final Formatter formatter = format ? DDLFormatterImpl.INSTANCE : FormatStyle.NONE.getFormatter();
final Formatter formatter = FormatStyle.NONE.getFormatter();
final Object importScriptSetting = options.getConfigurationValues().get(HBM2DDL_LOAD_SCRIPT_SOURCE);
String charsetName = (String) options.getConfigurationValues().get(HBM2DDL_CHARSET_NAME);
if (importScriptSetting != null) {
final ScriptSourceInput importScriptInput = interpretScriptSourceSetting(importScriptSetting, classLoaderService, charsetName);
log.executingImportScript(importScriptInput.toString());
importScriptInput.prepare();
try {
for (String command : importScriptInput.read(commandExtractor)) {
applySqlString(command, formatter, options, targets);
}
} finally {
importScriptInput.release();
}
}
final String importFiles = ConfigurationHelper.getString(AvailableSettings.HBM2DDL_IMPORT_FILES, options.getConfigurationValues(), DEFAULT_IMPORT_FILE);
for (String currentFile : importFiles.split(",")) {
final String resourceName = currentFile.trim();
final ScriptSourceInput importScriptInput = interpretLegacyImportScriptSetting(resourceName, classLoaderService, charsetName);
importScriptInput.prepare();
try {
log.executingImportScript(importScriptInput.toString());
for (String command : importScriptInput.read(commandExtractor)) {
applySqlString(command, formatter, options, targets);
}
} finally {
importScriptInput.release();
}
}
}
use of org.hibernate.boot.registry.classloading.spi.ClassLoaderService in project hibernate-orm by hibernate.
the class ImportSqlCommandExtractorInitiator method initiateService.
@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);
}
use of org.hibernate.boot.registry.classloading.spi.ClassLoaderService in project hibernate-orm by hibernate.
the class SchemaExportTask method doExecution.
private void doExecution() throws Exception {
final BootstrapServiceRegistry bsr = new BootstrapServiceRegistryBuilder().build();
final StandardServiceRegistryBuilder ssrBuilder = new StandardServiceRegistryBuilder(bsr);
final MetadataSources metadataSources = new MetadataSources(bsr);
if (configurationFile != null) {
ssrBuilder.configure(configurationFile);
}
if (propertiesFile != null) {
ssrBuilder.loadProperties(propertiesFile);
}
ssrBuilder.applySettings(getProject().getProperties());
for (String fileName : getFiles()) {
if (fileName.endsWith(".jar")) {
metadataSources.addJar(new File(fileName));
} else {
metadataSources.addFile(fileName);
}
}
ssrBuilder.applySetting(AvailableSettings.HBM2DDL_DELIMITER, delimiter);
ExportType exportType = ExportType.interpret(drop, create);
Target output = Target.interpret(!quiet, !text);
if (output.doScript()) {
ssrBuilder.applySetting(AvailableSettings.HBM2DDL_SCRIPTS_ACTION, exportType.getAction());
final Object scriptTarget;
if (outputFile == null) {
scriptTarget = new OutputStreamWriter(System.out);
} else {
scriptTarget = outputFile;
}
if (exportType.doCreate()) {
ssrBuilder.applySetting(AvailableSettings.HBM2DDL_SCRIPTS_CREATE_TARGET, scriptTarget);
}
if (exportType.doDrop()) {
ssrBuilder.applySetting(AvailableSettings.HBM2DDL_SCRIPTS_DROP_TARGET, scriptTarget);
}
}
if (output.doExport()) {
ssrBuilder.applySetting(AvailableSettings.HBM2DDL_DATABASE_ACTION, exportType.getAction());
}
final StandardServiceRegistryImpl ssr = (StandardServiceRegistryImpl) ssrBuilder.build();
final MetadataBuilder metadataBuilder = metadataSources.getMetadataBuilder(ssr);
ClassLoaderService classLoaderService = bsr.getService(ClassLoaderService.class);
if (implicitNamingStrategy != null) {
metadataBuilder.applyImplicitNamingStrategy((ImplicitNamingStrategy) classLoaderService.classForName(implicitNamingStrategy).newInstance());
}
if (physicalNamingStrategy != null) {
metadataBuilder.applyPhysicalNamingStrategy((PhysicalNamingStrategy) classLoaderService.classForName(physicalNamingStrategy).newInstance());
}
final MetadataImplementor metadata = (MetadataImplementor) metadataBuilder.build();
metadata.validate();
SchemaManagementToolCoordinator.process(metadata, ssr, ssr.getService(ConfigurationService.class).getSettings(), DelayedDropRegistryNotAvailableImpl.INSTANCE);
}
Aggregations