Search in sources :

Example 41 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 42 with ClassLoaderService

use of org.hibernate.boot.registry.classloading.spi.ClassLoaderService in project jbosstools-hibernate by jbosstools.

the class ClassMetadataFacadeTest method setupFooBarPersister.

private ClassMetadata setupFooBarPersister() {
    StandardServiceRegistryBuilder ssrb = new StandardServiceRegistryBuilder();
    ssrb.applySetting(AvailableSettings.DIALECT, TestDialect.class.getName());
    StandardServiceRegistry serviceRegistry = ssrb.build();
    MetadataBuildingOptionsImpl metadataBuildingOptions = new MetadataBuildingOptionsImpl(serviceRegistry);
    InFlightMetadataCollector inFlightMetadataCollector = new InFlightMetadataCollectorImpl(metadataBuildingOptions, new TypeResolver());
    ClassLoaderService classLoaderService = metadataBuildingOptions.getServiceRegistry().getService(ClassLoaderService.class);
    ClassLoaderAccess classLoaderAccess = new ClassLoaderAccessImpl(metadataBuildingOptions.getTempClassLoader(), classLoaderService);
    MetadataBuildingContext metadataBuildingContext = new MetadataBuildingContextRootImpl(metadataBuildingOptions, classLoaderAccess, inFlightMetadataCollector);
    MetadataImplementor metadataImplementor = (MetadataImplementor) new MetadataSources(serviceRegistry).buildMetadata();
    return new TestEntityPersister(createPersistentClass(metadataBuildingContext, metadataImplementor), new TestCreationContext(metadataImplementor));
}
Also used : StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) TypeResolver(org.hibernate.type.TypeResolver) MetadataBuildingOptionsImpl(org.hibernate.boot.internal.MetadataBuilderImpl.MetadataBuildingOptionsImpl) MetadataSources(org.hibernate.boot.MetadataSources) ClassLoaderAccessImpl(org.hibernate.boot.internal.ClassLoaderAccessImpl) MetadataBuildingContext(org.hibernate.boot.spi.MetadataBuildingContext) MetadataImplementor(org.hibernate.boot.spi.MetadataImplementor) ClassLoaderAccess(org.hibernate.boot.spi.ClassLoaderAccess) InFlightMetadataCollector(org.hibernate.boot.spi.InFlightMetadataCollector) InFlightMetadataCollectorImpl(org.hibernate.boot.internal.InFlightMetadataCollectorImpl) MetadataBuildingContextRootImpl(org.hibernate.boot.internal.MetadataBuildingContextRootImpl) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) ClassLoaderService(org.hibernate.boot.registry.classloading.spi.ClassLoaderService)

Example 43 with ClassLoaderService

use of org.hibernate.boot.registry.classloading.spi.ClassLoaderService in project jbosstools-hibernate by jbosstools.

the class EntityMetamodelFacadeTest method createFooBarModel.

private EntityMetamodel createFooBarModel() {
    StandardServiceRegistryBuilder ssrb = new StandardServiceRegistryBuilder();
    ssrb.applySetting(AvailableSettings.DIALECT, TestDialect.class.getName());
    StandardServiceRegistry serviceRegistry = ssrb.build();
    MetadataBuildingOptionsImpl metadataBuildingOptions = new MetadataBuildingOptionsImpl(serviceRegistry);
    InFlightMetadataCollector inFlightMetadataCollector = new InFlightMetadataCollectorImpl(metadataBuildingOptions, new TypeResolver());
    ClassLoaderService classLoaderService = metadataBuildingOptions.getServiceRegistry().getService(ClassLoaderService.class);
    ClassLoaderAccess classLoaderAccess = new ClassLoaderAccessImpl(metadataBuildingOptions.getTempClassLoader(), classLoaderService);
    MetadataBuildingContext metadataBuildingContext = new MetadataBuildingContextRootImpl(metadataBuildingOptions, classLoaderAccess, inFlightMetadataCollector);
    MetadataSources metadataSources = new MetadataSources(serviceRegistry);
    PersistentClass persistentClass = createPersistentClass(metadataBuildingContext, (MetadataImplementor) metadataSources.buildMetadata());
    SessionFactoryImplementor sessionFactoryImplementor = (SessionFactoryImplementor) metadataSources.buildMetadata().buildSessionFactory();
    return new EntityMetamodel(persistentClass, null, sessionFactoryImplementor) {

        private static final long serialVersionUID = 1L;

        @Override
        public EntityTuplizer getTuplizer() {
            return (EntityTuplizer) Proxy.newProxyInstance(FACADE_FACTORY.getClassLoader(), new Class[] { EntityTuplizer.class }, new TestInvocationHandler());
        }

        @Override
        public Integer getPropertyIndexOrNull(String id) {
            methodName = "getPropertyIndexOrNull";
            arguments = new Object[] { id };
            return INDEX;
        }
    };
}
Also used : EntityTuplizer(org.hibernate.tuple.entity.EntityTuplizer) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) TypeResolver(org.hibernate.type.TypeResolver) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) MetadataBuildingOptionsImpl(org.hibernate.boot.internal.MetadataBuilderImpl.MetadataBuildingOptionsImpl) MetadataSources(org.hibernate.boot.MetadataSources) ClassLoaderAccessImpl(org.hibernate.boot.internal.ClassLoaderAccessImpl) MetadataBuildingContext(org.hibernate.boot.spi.MetadataBuildingContext) ClassLoaderAccess(org.hibernate.boot.spi.ClassLoaderAccess) InFlightMetadataCollector(org.hibernate.boot.spi.InFlightMetadataCollector) InFlightMetadataCollectorImpl(org.hibernate.boot.internal.InFlightMetadataCollectorImpl) RootClass(org.hibernate.mapping.RootClass) PersistentClass(org.hibernate.mapping.PersistentClass) MetadataBuildingContextRootImpl(org.hibernate.boot.internal.MetadataBuildingContextRootImpl) IEntityMetamodel(org.jboss.tools.hibernate.runtime.spi.IEntityMetamodel) EntityMetamodel(org.hibernate.tuple.entity.EntityMetamodel) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) ClassLoaderService(org.hibernate.boot.registry.classloading.spi.ClassLoaderService) PersistentClass(org.hibernate.mapping.PersistentClass)

Aggregations

ClassLoaderService (org.hibernate.boot.registry.classloading.spi.ClassLoaderService)43 HibernateException (org.hibernate.HibernateException)9 ClassLoaderAccessImpl (org.hibernate.boot.internal.ClassLoaderAccessImpl)9 ClassLoaderAccess (org.hibernate.boot.spi.ClassLoaderAccess)9 InFlightMetadataCollectorImpl (org.hibernate.boot.internal.InFlightMetadataCollectorImpl)8 MetadataBuildingContextRootImpl (org.hibernate.boot.internal.MetadataBuildingContextRootImpl)8 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)8 MetadataSources (org.hibernate.boot.MetadataSources)7 InFlightMetadataCollector (org.hibernate.boot.spi.InFlightMetadataCollector)7 TypeResolver (org.hibernate.type.TypeResolver)7 MappingException (org.hibernate.MappingException)6 MetadataBuildingOptionsImpl (org.hibernate.boot.internal.MetadataBuilderImpl.MetadataBuildingOptionsImpl)6 StandardServiceRegistry (org.hibernate.boot.registry.StandardServiceRegistry)6 ClassLoadingException (org.hibernate.boot.registry.classloading.spi.ClassLoadingException)6 MetadataBuildingContext (org.hibernate.boot.spi.MetadataBuildingContext)6 HashSet (java.util.HashSet)5 MetadataImplementor (org.hibernate.boot.spi.MetadataImplementor)4 ConfigurationService (org.hibernate.engine.config.spi.ConfigurationService)4 ServiceRegistry (org.hibernate.service.ServiceRegistry)4 Set (java.util.Set)3