Search in sources :

Example 6 with ClassLoaderService

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

the class TypeDefinitionBinder method processTypeDefinition.

/**
	 * Handling for a {@code <typedef/>} declaration
	 *
	 * @param context Access to information relative to the mapping document containing this binding
	 * @param typeDefinitionBinding The {@code <typedef/>} binding
	 */
public static void processTypeDefinition(HbmLocalMetadataBuildingContext context, JaxbHbmTypeDefinitionType typeDefinitionBinding) {
    final ClassLoaderService cls = context.getBuildingOptions().getServiceRegistry().getService(ClassLoaderService.class);
    final TypeDefinition definition = new TypeDefinition(typeDefinitionBinding.getName(), cls.classForName(typeDefinitionBinding.getClazz()), null, ConfigParameterHelper.extractConfigParameters(typeDefinitionBinding));
    log.debugf("Processed type-definition : %s -> %s", definition.getName(), definition.getTypeImplementorClass().getName());
    context.getMetadataCollector().addTypeDefinition(definition);
}
Also used : ClassLoaderService(org.hibernate.boot.registry.classloading.spi.ClassLoaderService) TypeDefinition(org.hibernate.boot.model.TypeDefinition)

Example 7 with ClassLoaderService

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

the class BeanValidationIntegrator method integrate.

@Override
public void integrate(final Metadata metadata, final SessionFactoryImplementor sessionFactory, final SessionFactoryServiceRegistry serviceRegistry) {
    final ConfigurationService cfgService = serviceRegistry.getService(ConfigurationService.class);
    // IMPL NOTE : see the comments on ActivationContext.getValidationModes() as to why this is multi-valued...
    final Set<ValidationMode> modes = ValidationMode.getModes(cfgService.getSettings().get(MODE_PROPERTY));
    if (modes.size() > 1) {
        LOG.multipleValidationModes(ValidationMode.loggable(modes));
    }
    if (modes.size() == 1 && modes.contains(ValidationMode.NONE)) {
        // we have nothing to do; just return
        return;
    }
    final ClassLoaderService classLoaderService = serviceRegistry.getService(ClassLoaderService.class);
    // see if the Bean Validation API is available on the classpath
    if (isBeanValidationApiAvailable(classLoaderService)) {
        // and if so, call out to the TypeSafeActivator
        try {
            final Class typeSafeActivatorClass = loadTypeSafeActivatorClass(classLoaderService);
            @SuppressWarnings("unchecked") final Method activateMethod = typeSafeActivatorClass.getMethod(ACTIVATE_METHOD_NAME, ActivationContext.class);
            final ActivationContext activationContext = new ActivationContext() {

                @Override
                public Set<ValidationMode> getValidationModes() {
                    return modes;
                }

                @Override
                public Metadata getMetadata() {
                    return metadata;
                }

                @Override
                public SessionFactoryImplementor getSessionFactory() {
                    return sessionFactory;
                }

                @Override
                public SessionFactoryServiceRegistry getServiceRegistry() {
                    return serviceRegistry;
                }
            };
            try {
                activateMethod.invoke(null, activationContext);
            } catch (InvocationTargetException e) {
                if (HibernateException.class.isInstance(e.getTargetException())) {
                    throw ((HibernateException) e.getTargetException());
                }
                throw new IntegrationException("Error activating Bean Validation integration", e.getTargetException());
            } catch (Exception e) {
                throw new IntegrationException("Error activating Bean Validation integration", e);
            }
        } catch (NoSuchMethodException e) {
            throw new HibernateException("Unable to locate TypeSafeActivator#activate method", e);
        }
    } else {
        // otherwise check the validation modes
        // todo : in many ways this duplicates thew checks done on the TypeSafeActivator when a ValidatorFactory could not be obtained
        validateMissingBeanValidationApi(modes);
    }
}
Also used : HibernateException(org.hibernate.HibernateException) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException) HibernateException(org.hibernate.HibernateException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ConfigurationService(org.hibernate.engine.config.spi.ConfigurationService) ClassLoaderService(org.hibernate.boot.registry.classloading.spi.ClassLoaderService)

Example 8 with ClassLoaderService

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

the class StandardJtaPlatformResolver method resolveJtaPlatform.

@Override
public JtaPlatform resolveJtaPlatform(Map configurationValues, ServiceRegistryImplementor registry) {
    final ClassLoaderService classLoaderService = registry.getService(ClassLoaderService.class);
    // Initially look for a JtaPlatformProvider
    for (JtaPlatformProvider provider : classLoaderService.loadJavaServices(JtaPlatformProvider.class)) {
        final JtaPlatform providedPlatform = provider.getProvidedJtaPlatform();
        log.tracef("Located JtaPlatformProvider [%s] provided JtaPlaform : %s", provider, providedPlatform);
        if (providedPlatform != null) {
            return providedPlatform;
        }
    }
    // JBoss ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    try {
        classLoaderService.classForName(JBossStandAloneJtaPlatform.JBOSS_TM_CLASS_NAME);
        classLoaderService.classForName(JBossStandAloneJtaPlatform.JBOSS_UT_CLASS_NAME);
        // should be relying on that
        return new JBossStandAloneJtaPlatform();
    } catch (ClassLoadingException ignore) {
    }
    // Bitronix ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    try {
        classLoaderService.classForName(BitronixJtaPlatform.TM_CLASS_NAME);
        return new BitronixJtaPlatform();
    } catch (ClassLoadingException ignore) {
    }
    // JOnAS ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    try {
        classLoaderService.classForName(JOnASJtaPlatform.TM_CLASS_NAME);
        return new JOnASJtaPlatform();
    } catch (ClassLoadingException ignore) {
    }
    // JOTM ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    try {
        classLoaderService.classForName(JOTMJtaPlatform.TM_CLASS_NAME);
        return new JOTMJtaPlatform();
    } catch (ClassLoadingException ignore) {
    }
    // WebSphere ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    for (WebSphereJtaPlatform.WebSphereEnvironment webSphereEnvironment : WebSphereJtaPlatform.WebSphereEnvironment.values()) {
        try {
            Class accessClass = classLoaderService.classForName(webSphereEnvironment.getTmAccessClassName());
            return new WebSphereJtaPlatform(accessClass, webSphereEnvironment);
        } catch (ClassLoadingException ignore) {
        }
    }
    // Finally, return the default...
    log.debugf("Could not resolve JtaPlatform, using default [%s]", NoJtaPlatform.class.getName());
    return NoJtaPlatform.INSTANCE;
}
Also used : JtaPlatform(org.hibernate.engine.transaction.jta.platform.spi.JtaPlatform) JtaPlatformProvider(org.hibernate.engine.transaction.jta.platform.spi.JtaPlatformProvider) ClassLoadingException(org.hibernate.boot.registry.classloading.spi.ClassLoadingException) ClassLoaderService(org.hibernate.boot.registry.classloading.spi.ClassLoaderService)

Example 9 with ClassLoaderService

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

the class SessionFactoryImpl method applyCfgXmlValues.

private void applyCfgXmlValues(LoadedConfig aggregatedConfig, SessionFactoryServiceRegistry serviceRegistry) {
    final JaccService jaccService = serviceRegistry.getService(JaccService.class);
    if (jaccService.getContextId() != null) {
        final JaccPermissionDeclarations permissions = aggregatedConfig.getJaccPermissions(jaccService.getContextId());
        if (permissions != null) {
            for (GrantedPermission grantedPermission : permissions.getPermissionDeclarations()) {
                jaccService.addPermission(grantedPermission);
            }
        }
    }
    if (aggregatedConfig.getEventListenerMap() != null) {
        final ClassLoaderService cls = serviceRegistry.getService(ClassLoaderService.class);
        final EventListenerRegistry eventListenerRegistry = serviceRegistry.getService(EventListenerRegistry.class);
        for (Map.Entry<EventType, Set<String>> entry : aggregatedConfig.getEventListenerMap().entrySet()) {
            final EventListenerGroup group = eventListenerRegistry.getEventListenerGroup(entry.getKey());
            for (String listenerClassName : entry.getValue()) {
                try {
                    group.appendListener(cls.classForName(listenerClassName).newInstance());
                } catch (Exception e) {
                    throw new ConfigurationException("Unable to instantiate event listener class : " + listenerClassName, e);
                }
            }
        }
    }
}
Also used : Set(java.util.Set) EventListenerGroup(org.hibernate.event.service.spi.EventListenerGroup) EventType(org.hibernate.event.spi.EventType) JaccService(org.hibernate.secure.spi.JaccService) GrantedPermission(org.hibernate.secure.spi.GrantedPermission) InvalidObjectException(java.io.InvalidObjectException) HibernateException(org.hibernate.HibernateException) SQLException(java.sql.SQLException) ConfigurationException(org.hibernate.internal.util.config.ConfigurationException) IOException(java.io.IOException) PersistenceException(javax.persistence.PersistenceException) MappingException(org.hibernate.MappingException) EventListenerRegistry(org.hibernate.event.service.spi.EventListenerRegistry) JaccPermissionDeclarations(org.hibernate.secure.spi.JaccPermissionDeclarations) ConfigurationException(org.hibernate.internal.util.config.ConfigurationException) Map(java.util.Map) HashMap(java.util.HashMap) ClassLoaderService(org.hibernate.boot.registry.classloading.spi.ClassLoaderService)

Example 10 with ClassLoaderService

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

the class UUIDGenerator method configure.

@Override
public void configure(Type type, Properties params, ServiceRegistry serviceRegistry) throws MappingException {
    // check first for the strategy instance
    strategy = (UUIDGenerationStrategy) params.get(UUID_GEN_STRATEGY);
    if (strategy == null) {
        // next check for the strategy class
        final String strategyClassName = params.getProperty(UUID_GEN_STRATEGY_CLASS);
        if (strategyClassName != null) {
            try {
                final ClassLoaderService cls = serviceRegistry.getService(ClassLoaderService.class);
                final Class strategyClass = cls.classForName(strategyClassName);
                try {
                    strategy = (UUIDGenerationStrategy) strategyClass.newInstance();
                } catch (Exception ignore) {
                    LOG.unableToInstantiateUuidGenerationStrategy(ignore);
                }
            } catch (ClassLoadingException ignore) {
                LOG.unableToLocateUuidGenerationStrategy(strategyClassName);
            }
        }
    }
    if (strategy == null) {
        // lastly use the standard random generator
        strategy = StandardRandomStrategy.INSTANCE;
    }
    if (UUID.class.isAssignableFrom(type.getReturnedClass())) {
        valueTransformer = UUIDTypeDescriptor.PassThroughTransformer.INSTANCE;
    } else if (String.class.isAssignableFrom(type.getReturnedClass())) {
        valueTransformer = UUIDTypeDescriptor.ToStringTransformer.INSTANCE;
    } else if (byte[].class.isAssignableFrom(type.getReturnedClass())) {
        valueTransformer = UUIDTypeDescriptor.ToBytesTransformer.INSTANCE;
    } else {
        throw new HibernateException("Unanticipated return type [" + type.getReturnedClass().getName() + "] for UUID conversion");
    }
}
Also used : HibernateException(org.hibernate.HibernateException) ClassLoadingException(org.hibernate.boot.registry.classloading.spi.ClassLoadingException) MappingException(org.hibernate.MappingException) HibernateException(org.hibernate.HibernateException) ClassLoadingException(org.hibernate.boot.registry.classloading.spi.ClassLoadingException) 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