Search in sources :

Example 1 with MetadataBuilderFactory

use of org.hibernate.boot.spi.MetadataBuilderFactory in project hibernate-orm by hibernate.

the class MetadataSources method getCustomBuilderOrDefault.

/**
	 * In case a custom {@link MetadataBuilderFactory} creates a custom builder, return that one, otherwise the default
	 * builder.
	 */
private MetadataBuilder getCustomBuilderOrDefault(MetadataBuilderImpl defaultBuilder) {
    final ClassLoaderService cls = serviceRegistry.getService(ClassLoaderService.class);
    final java.util.Collection<MetadataBuilderFactory> discoveredBuilderFactories = cls.loadJavaServices(MetadataBuilderFactory.class);
    MetadataBuilder builder = null;
    List<String> activeFactoryNames = null;
    for (MetadataBuilderFactory discoveredBuilderFactory : discoveredBuilderFactories) {
        final MetadataBuilder returnedBuilder = discoveredBuilderFactory.getMetadataBuilder(this, defaultBuilder);
        if (returnedBuilder != null) {
            if (activeFactoryNames == null) {
                activeFactoryNames = new ArrayList<String>();
            }
            activeFactoryNames.add(discoveredBuilderFactory.getClass().getName());
            builder = returnedBuilder;
        }
    }
    if (activeFactoryNames != null && activeFactoryNames.size() > 1) {
        throw new HibernateException("Multiple active MetadataBuilder definitions were discovered : " + StringHelper.join(", ", activeFactoryNames));
    }
    return builder != null ? builder : defaultBuilder;
}
Also used : MetadataBuilderFactory(org.hibernate.boot.spi.MetadataBuilderFactory) HibernateException(org.hibernate.HibernateException) ClassLoaderService(org.hibernate.boot.registry.classloading.spi.ClassLoaderService)

Aggregations

HibernateException (org.hibernate.HibernateException)1 ClassLoaderService (org.hibernate.boot.registry.classloading.spi.ClassLoaderService)1 MetadataBuilderFactory (org.hibernate.boot.spi.MetadataBuilderFactory)1