Search in sources :

Example 21 with ClassLoaderService

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);
    }
}
Also used : XProperty(org.hibernate.annotations.common.reflection.XProperty) ClassLoadingException(org.hibernate.boot.registry.classloading.spi.ClassLoadingException) Annotation(java.lang.annotation.Annotation) ClassLoaderService(org.hibernate.boot.registry.classloading.spi.ClassLoaderService) MappingException(org.hibernate.MappingException)

Example 22 with ClassLoaderService

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;
}
Also used : AttributeConverter(javax.persistence.AttributeConverter) AttributeConverterDescriptorNonAutoApplicableImpl(org.hibernate.boot.internal.AttributeConverterDescriptorNonAutoApplicableImpl) MappingException(org.hibernate.MappingException) ClassLoadingException(org.hibernate.boot.registry.classloading.spi.ClassLoadingException) ClassLoaderService(org.hibernate.boot.registry.classloading.spi.ClassLoaderService)

Example 23 with ClassLoaderService

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();
        }
    }
}
Also used : ScriptSourceInput(org.hibernate.tool.schema.spi.ScriptSourceInput) Formatter(org.hibernate.engine.jdbc.internal.Formatter) AuxiliaryDatabaseObject(org.hibernate.boot.model.relational.AuxiliaryDatabaseObject) ServiceRegistry(org.hibernate.service.ServiceRegistry) ClassLoaderService(org.hibernate.boot.registry.classloading.spi.ClassLoaderService)

Example 24 with ClassLoaderService

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);
}
Also used : ClassLoaderService(org.hibernate.boot.registry.classloading.spi.ClassLoaderService)

Example 25 with 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);
}
Also used : BootstrapServiceRegistryBuilder(org.hibernate.boot.registry.BootstrapServiceRegistryBuilder) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) MetadataBuilder(org.hibernate.boot.MetadataBuilder) MetadataSources(org.hibernate.boot.MetadataSources) MetadataImplementor(org.hibernate.boot.spi.MetadataImplementor) BootstrapServiceRegistry(org.hibernate.boot.registry.BootstrapServiceRegistry) OutputStreamWriter(java.io.OutputStreamWriter) File(java.io.File) StandardServiceRegistryImpl(org.hibernate.boot.registry.internal.StandardServiceRegistryImpl) ClassLoaderService(org.hibernate.boot.registry.classloading.spi.ClassLoaderService)

Aggregations

ClassLoaderService (org.hibernate.boot.registry.classloading.spi.ClassLoaderService)29 HibernateException (org.hibernate.HibernateException)8 MappingException (org.hibernate.MappingException)6 ClassLoadingException (org.hibernate.boot.registry.classloading.spi.ClassLoadingException)6 HashSet (java.util.HashSet)3 ServiceRegistry (org.hibernate.service.ServiceRegistry)3 IOException (java.io.IOException)2 SQLException (java.sql.SQLException)2 Set (java.util.Set)2 AttributeConverter (javax.persistence.AttributeConverter)2 ClassLoaderAccessImpl (org.hibernate.boot.internal.ClassLoaderAccessImpl)2 ClassLoaderAccess (org.hibernate.boot.spi.ClassLoaderAccess)2 ServiceException (org.hibernate.service.spi.ServiceException)2 BasicTypeRegistry (org.hibernate.type.BasicTypeRegistry)2 File (java.io.File)1 InputStream (java.io.InputStream)1 InvalidObjectException (java.io.InvalidObjectException)1 OutputStreamWriter (java.io.OutputStreamWriter)1 Annotation (java.lang.annotation.Annotation)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1