org.hibernate.boot.spi.BootstrapContext Java Examples

The following examples show how to use org.hibernate.boot.spi.BootstrapContext. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: InFlightMetadataCollectorImpl.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
public InFlightMetadataCollectorImpl(
		BootstrapContext bootstrapContext,
		MetadataBuildingOptions options) {
	this.bootstrapContext = bootstrapContext;
	this.uuid = UUID.randomUUID();
	this.options = options;

	this.identifierGeneratorFactory = options.getServiceRegistry()
			.getService( MutableIdentifierGeneratorFactory.class );

	for ( Map.Entry<String, SQLFunction> sqlFunctionEntry : bootstrapContext.getSqlFunctions().entrySet() ) {
		if ( sqlFunctionMap == null ) {
			// we need this to be a ConcurrentHashMap for the one we ultimately pass along to the SF
			// but is this the reference that gets passed along?
			sqlFunctionMap = new ConcurrentHashMap<>( 16, .75f, 1 );
		}
		sqlFunctionMap.put( sqlFunctionEntry.getKey(), sqlFunctionEntry.getValue() );
	}

	bootstrapContext.getAuxiliaryDatabaseObjectList().forEach( getDatabase()::addAuxiliaryDatabaseObject );
}
 
Example #2
Source File: SchemaBuilderUtility.java    From teiid-spring-boot with Apache License 2.0 6 votes vote down vote up
public static ArtifactCollector generateHibernateModel(MetadataFactory source,
        StandardServiceRegistry serviceRegistry) {
    ReverseEngineeringStrategy strategy = new DefaultReverseEngineeringStrategy();
    MetadataBuildingOptions options = new MetadataBuildingOptionsImpl(serviceRegistry);

    BootstrapContext bootstrapContext = new BootstrapContextImpl(serviceRegistry, options);

    InFlightMetadataCollectorImpl metadataCollector = new InFlightMetadataCollectorImpl(bootstrapContext, options);
    MetadataBuildingContext buildingContext = new MetadataBuildingContextRootImpl(bootstrapContext, options,
            metadataCollector);

    TeiidJDBCBinder binder = new TeiidJDBCBinder(serviceRegistry, new Properties(), buildingContext, strategy,
            false, metadataCollector, source);
    Metadata metadata = metadataCollector.buildMetadataInstance(buildingContext);
    binder.readFromDatabase(null, null, buildMapping(metadata));

    HibernateMappingExporter exporter = new HibernateMappingExporter() {
        @Override
        public Metadata getMetadata() {
            return metadata;
        }
    };
    exporter.setOutputDirectory(TMP_DIR);
    exporter.start();
    return exporter.getArtifactCollector();
}
 
Example #3
Source File: ScanningCoordinator.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
public void coordinateScan(
		ManagedResourcesImpl managedResources,
		BootstrapContext bootstrapContext,
		XmlMappingBinderAccess xmlMappingBinderAccess) {
	if ( bootstrapContext.getScanEnvironment() == null ) {
		return;
	}

	final ClassLoaderService classLoaderService = bootstrapContext.getServiceRegistry().getService( ClassLoaderService.class );
	final ClassLoaderAccess classLoaderAccess = new ClassLoaderAccessImpl(
			bootstrapContext.getJpaTempClassLoader(),
			classLoaderService
	);

	// NOTE : the idea with JandexInitializer/JandexInitManager was to allow adding classes
	// to the index as we discovered them via scanning and .  Currently
	final Scanner scanner = buildScanner( bootstrapContext, classLoaderAccess );
	final ScanResult scanResult = scanner.scan(
			bootstrapContext.getScanEnvironment(),
			bootstrapContext.getScanOptions(),
			StandardScanParameters.INSTANCE
	);

	applyScanResultsToManagedResources( managedResources, scanResult, bootstrapContext, xmlMappingBinderAccess );
}
 
Example #4
Source File: SessionFactoryServiceRegistryImpl.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings( {"unchecked"})
public SessionFactoryServiceRegistryImpl(
		ServiceRegistryImplementor parent,
		List<SessionFactoryServiceInitiator> initiators,
		List<ProvidedService> providedServices,
		SessionFactoryImplementor sessionFactory,
		BootstrapContext bootstrapContext,
		SessionFactoryOptions sessionFactoryOptions) {
	super( parent );

	this.sessionFactory = sessionFactory;
	this.sessionFactoryOptions = sessionFactoryOptions;
	this.bootstrapContext = bootstrapContext;

	// for now, just use the standard initiator list
	for ( SessionFactoryServiceInitiator initiator : initiators ) {
		// create the bindings up front to help identify to which registry services belong
		createServiceBinding( initiator );
	}

	for ( ProvidedService providedService : providedServices ) {
		createServiceBinding( providedService );
	}

	bootstrapContext = null;
}
 
Example #5
Source File: SessionFactoryServiceRegistryFactoryImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public SessionFactoryServiceRegistry buildServiceRegistry(
		SessionFactoryImplementor sessionFactory,
		BootstrapContext bootstrapContext,
		SessionFactoryOptions options) {
	final ClassLoaderService cls = options.getServiceRegistry().getService( ClassLoaderService.class );
	final SessionFactoryServiceRegistryBuilderImpl builder = new SessionFactoryServiceRegistryBuilderImpl( theBasicServiceRegistry );

	for ( SessionFactoryServiceContributor contributor : cls.loadJavaServices( SessionFactoryServiceContributor.class ) ) {
		contributor.contribute( builder );
	}

	return builder.buildSessionFactoryServiceRegistry( sessionFactory, bootstrapContext, options );
}
 
Example #6
Source File: TypeConfiguration.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public MetamodelImplementor scope(SessionFactoryImplementor sessionFactory,  BootstrapContext bootstrapContext) {
	log.debugf( "Scoping TypeConfiguration [%s] to SessionFactoryImpl [%s]", this, sessionFactory );

	for ( Map.Entry<String, String> importEntry : scope.metadataBuildingContext.getMetadataCollector().getImports().entrySet() ) {
		if ( importMap.containsKey( importEntry.getKey() ) ) {
			continue;
		}

		importMap.put( importEntry.getKey(), importEntry.getValue() );
	}

	scope.setSessionFactory( sessionFactory );
	sessionFactory.addObserver( this );
	return new MetamodelImpl( sessionFactory, this );
}
 
Example #7
Source File: SessionFactoryBuilderImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public SessionFactoryBuilderImpl(MetadataImplementor metadata, BootstrapContext bootstrapContext) {
	this.metadata = metadata;
	this.bootstrapContext = bootstrapContext;

	this.optionsBuilder = new SessionFactoryOptionsBuilder(
			metadata.getMetadataBuildingOptions().getServiceRegistry(),
			bootstrapContext
	);

	if ( metadata.getSqlFunctionMap() != null ) {
		for ( Map.Entry<String, SQLFunction> sqlFunctionEntry : metadata.getSqlFunctionMap().entrySet() ) {
			applySqlFunction( sqlFunctionEntry.getKey(), sqlFunctionEntry.getValue() );
		}
	}
}
 
Example #8
Source File: MetadataBuildingContextRootImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public MetadataBuildingContextRootImpl(
		BootstrapContext bootstrapContext,
		MetadataBuildingOptions options,
		InFlightMetadataCollector metadataCollector) {
	this.bootstrapContext = bootstrapContext;
	this.options = options;
	this.mappingDefaults = options.getMappingDefaults();
	this.metadataCollector = metadataCollector;
	this.objectNameNormalizer = new ObjectNameNormalizer() {
		@Override
		protected MetadataBuildingContext getBuildingContext() {
			return MetadataBuildingContextRootImpl.this;
		}
	};
}
 
Example #9
Source File: ManagedResourcesImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public static ManagedResourcesImpl baseline(MetadataSources sources, BootstrapContext bootstrapContext) {
	final ManagedResourcesImpl impl = new ManagedResourcesImpl();
	bootstrapContext.getAttributeConverters().forEach( impl::addAttributeConverterDefinition );
	impl.annotatedClassReferences.addAll( sources.getAnnotatedClasses() );
	impl.annotatedClassNames.addAll( sources.getAnnotatedClassNames() );
	impl.annotatedPackageNames.addAll( sources.getAnnotatedPackages() );
	impl.mappingFileBindings.addAll( sources.getXmlBindings() );
	return impl;
}
 
Example #10
Source File: MetadataBuildingProcess.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * First step of 2-phase for MetadataSources->Metadata process
 *
 * @param sources The MetadataSources
 * @param bootstrapContext The bootstrapContext
 *
 * @return Token/memento representing all known users resources (classes, packages, mapping files, etc).
 */
public static ManagedResources prepare(
		final MetadataSources sources,
		final BootstrapContext bootstrapContext) {
	final ManagedResourcesImpl managedResources = ManagedResourcesImpl.baseline( sources, bootstrapContext );
	ScanningCoordinator.INSTANCE.coordinateScan(
			managedResources,
			bootstrapContext,
			sources.getXmlMappingBinderAccess()
	);
	return managedResources;
}
 
Example #11
Source File: EventListenerRegistryImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
EventListenerRegistryImpl(BootstrapContext bootstrapContext, SessionFactoryImplementor sessionFactory) {
	this.sessionFactory = sessionFactory;

	this.callbackRegistry = new CallbackRegistryImpl();
	this.callbackBuilder = new CallbackBuilderLegacyImpl(
			bootstrapContext.getServiceRegistry().getService( ManagedBeanRegistry.class ),
			bootstrapContext.getReflectionManager()
	);

	this.registeredEventListeners = buildListenerGroups();
}
 
Example #12
Source File: SessionFactoryServiceRegistryBuilderImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public SessionFactoryServiceRegistry buildSessionFactoryServiceRegistry(
		SessionFactoryImplementor sessionFactory,
		BootstrapContext bootstrapContext,
		SessionFactoryOptions options) {
	return new SessionFactoryServiceRegistryImpl(
			parent,
			initiators,
			providedServices,
			sessionFactory,
			bootstrapContext,
			options
	);
}
 
Example #13
Source File: SchemaBuilderUtility.java    From teiid-spring-boot with Apache License 2.0 5 votes vote down vote up
public static Metadata generateHbmModel(ConnectionProvider provider, Dialect dialect) throws SQLException {
    MetadataSources metadataSources = new MetadataSources();
    ServiceRegistry registry = metadataSources.getServiceRegistry();

    StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder(
            (BootstrapServiceRegistry) registry).applySetting(AvailableSettings.DIALECT, TeiidDialect.class)
            .addService(ConnectionProvider.class, provider).addService(JdbcEnvironment.class,
                    new JdbcEnvironmentImpl(provider.getConnection().getMetaData(), dialect))
            .build();

    MetadataBuildingOptions options = new MetadataBuildingOptionsImpl(serviceRegistry);
    BootstrapContext bootstrapContext = new BootstrapContextImpl( serviceRegistry, options );

    ReverseEngineeringStrategy strategy = new DefaultReverseEngineeringStrategy();

    InFlightMetadataCollectorImpl metadataCollector =  new InFlightMetadataCollectorImpl(bootstrapContext, options);
    MetadataBuildingContext buildingContext = new MetadataBuildingContextRootImpl(bootstrapContext, options,
            metadataCollector);

    JDBCBinder binder = new JDBCBinder(serviceRegistry, new Properties(), buildingContext, strategy, false);
    Metadata metadata = metadataCollector.buildMetadataInstance(buildingContext);
    binder.readFromDatabase(null, null, buildMapping(metadata));
    HibernateMappingExporter exporter = new HibernateMappingExporter() {
        @Override
        public Metadata getMetadata() {
            return metadata;
        }
    };
    exporter.start();
    return metadata;
}
 
Example #14
Source File: ScanningCoordinator.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public void applyScanResultsToManagedResources(
		ManagedResourcesImpl managedResources,
		ScanResult scanResult,
		BootstrapContext bootstrapContext,
		XmlMappingBinderAccess xmlMappingBinderAccess) {

	final ScanEnvironment scanEnvironment = bootstrapContext.getScanEnvironment();
	final ServiceRegistry serviceRegistry = bootstrapContext.getServiceRegistry();
	final ClassLoaderService classLoaderService = serviceRegistry.getService( ClassLoaderService.class );


	// mapping files ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

	final Set<String> nonLocatedMappingFileNames = new HashSet<String>();
	final List<String> explicitMappingFileNames = scanEnvironment.getExplicitlyListedMappingFiles();
	if ( explicitMappingFileNames != null ) {
		nonLocatedMappingFileNames.addAll( explicitMappingFileNames );
	}

	for ( MappingFileDescriptor mappingFileDescriptor : scanResult.getLocatedMappingFiles() ) {
		managedResources.addXmlBinding( xmlMappingBinderAccess.bind( mappingFileDescriptor.getStreamAccess() ) );
		nonLocatedMappingFileNames.remove( mappingFileDescriptor.getName() );
	}

	for ( String name : nonLocatedMappingFileNames ) {
		final URL url = classLoaderService.locateResource( name );
		if ( url == null ) {
			throw new MappingException(
					"Unable to resolve explicitly named mapping-file : " + name,
					new Origin( SourceType.RESOURCE, name )
			);
		}
		final UrlInputStreamAccess inputStreamAccess = new UrlInputStreamAccess( url );
		managedResources.addXmlBinding( xmlMappingBinderAccess.bind( inputStreamAccess ) );
	}


	// classes and packages ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

	final List<String> unresolvedListedClassNames = scanEnvironment.getExplicitlyListedClassNames() == null
			? new ArrayList<String>()
			: new ArrayList<String>( scanEnvironment.getExplicitlyListedClassNames() );

	for ( ClassDescriptor classDescriptor : scanResult.getLocatedClasses() ) {
		if ( classDescriptor.getCategorization() == ClassDescriptor.Categorization.CONVERTER ) {
			// converter classes are safe to load because we never enhance them,
			// and notice we use the ClassLoaderService specifically, not the temp ClassLoader (if any)
			managedResources.addAttributeConverterDefinition(
					AttributeConverterDefinition.from(
							classLoaderService.<AttributeConverter>classForName( classDescriptor.getName() )
					)
			);
		}
		else if ( classDescriptor.getCategorization() == ClassDescriptor.Categorization.MODEL ) {
			managedResources.addAnnotatedClassName( classDescriptor.getName() );
		}
		unresolvedListedClassNames.remove( classDescriptor.getName() );
	}

	// IMPL NOTE : "explicitlyListedClassNames" can contain class or package names...
	for ( PackageDescriptor packageDescriptor : scanResult.getLocatedPackages() ) {
		managedResources.addAnnotatedPackageName( packageDescriptor.getName() );
		unresolvedListedClassNames.remove( packageDescriptor.getName() );
	}

	for ( String unresolvedListedClassName : unresolvedListedClassNames ) {
		// because the explicit list can contain either class names or package names
		// we need to check for both here...

		// First, try it as a class name
		final String classFileName = unresolvedListedClassName.replace( '.', '/' ) + ".class";
		final URL classFileUrl = classLoaderService.locateResource( classFileName );
		if ( classFileUrl != null ) {
			managedResources.addAnnotatedClassName( unresolvedListedClassName );
			continue;
		}

		// Then, try it as a package name
		final String packageInfoFileName = unresolvedListedClassName.replace( '.', '/' ) + "/package-info.class";
		final URL packageInfoFileUrl = classLoaderService.locateResource( packageInfoFileName );
		if ( packageInfoFileUrl != null ) {
			managedResources.addAnnotatedPackageName( unresolvedListedClassName );
			continue;
		}

		log.debugf(
				"Unable to resolve class [%s] named in persistence unit [%s]",
				unresolvedListedClassName,
				scanEnvironment.getRootUrl()
		);
	}
}
 
Example #15
Source File: HibernateOrmIntegrations.java    From quarkus with Apache License 2.0 4 votes vote down vote up
public static void onMetadataInitialized(Metadata metadata, BootstrapContext bootstrapContext,
        BiConsumer<String, Object> propertyCollector) {
    for (HibernateOrmIntegrationListener listener : LISTENERS) {
        listener.onMetadataInitialized(metadata, bootstrapContext, propertyCollector);
    }
}
 
Example #16
Source File: HibernateOrmIntegrationListener.java    From quarkus with Apache License 2.0 4 votes vote down vote up
void onMetadataInitialized(Metadata metadata, BootstrapContext bootstrapContext,
BiConsumer<String, Object> propertyCollector);
 
Example #17
Source File: MetadataImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
MetadataImpl(
		UUID uuid,
		MetadataBuildingOptions metadataBuildingOptions,
		MutableIdentifierGeneratorFactory identifierGeneratorFactory,
		Map<String, PersistentClass> entityBindingMap,
		Map<Class, MappedSuperclass> mappedSuperclassMap,
		Map<String, Collection> collectionBindingMap,
		Map<String, TypeDefinition> typeDefinitionMap,
		Map<String, FilterDefinition> filterDefinitionMap,
		Map<String, FetchProfile> fetchProfileMap,
		Map<String, String> imports,
		Map<String, IdentifierGeneratorDefinition> idGeneratorDefinitionMap,
		Map<String, NamedQueryDefinition> namedQueryMap,
		Map<String, NamedSQLQueryDefinition> namedNativeQueryMap,
		Map<String, NamedProcedureCallDefinition> namedProcedureCallMap,
		Map<String, ResultSetMappingDefinition> sqlResultSetMappingMap,
		Map<String, NamedEntityGraphDefinition> namedEntityGraphMap,
		Map<String, SQLFunction> sqlFunctionMap,
		java.util.Collection<DomainDataRegionConfigImpl.Builder> cacheRegionConfigBuilders,
		Database database,
		BootstrapContext bootstrapContext) {
	this.uuid = uuid;
	this.metadataBuildingOptions = metadataBuildingOptions;
	this.identifierGeneratorFactory = identifierGeneratorFactory;
	this.entityBindingMap = entityBindingMap;
	this.mappedSuperclassMap = mappedSuperclassMap;
	this.collectionBindingMap = collectionBindingMap;
	this.typeDefinitionMap = typeDefinitionMap;
	this.filterDefinitionMap = filterDefinitionMap;
	this.fetchProfileMap = fetchProfileMap;
	this.imports = imports;
	this.idGeneratorDefinitionMap = idGeneratorDefinitionMap;
	this.namedQueryMap = namedQueryMap;
	this.namedNativeQueryMap = namedNativeQueryMap;
	this.namedProcedureCallMap = namedProcedureCallMap;
	this.sqlResultSetMappingMap = sqlResultSetMappingMap;
	this.namedEntityGraphMap = namedEntityGraphMap;
	this.sqlFunctionMap = sqlFunctionMap;
	this.cacheRegionConfigBuilders = cacheRegionConfigBuilders;
	this.database = database;
	this.bootstrapContext = bootstrapContext;
}
 
Example #18
Source File: MetadataBuilderImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public BootstrapContext getBootstrapContext() {
	return bootstrapContext;
}
 
Example #19
Source File: MetadataBuildingContextRootImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public BootstrapContext getBootstrapContext() {
	return bootstrapContext;
}
 
Example #20
Source File: HibernateSearchElasticsearchRecorder.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@Override
public void onMetadataInitialized(Metadata metadata, BootstrapContext bootstrapContext,
        BiConsumer<String, Object> propertyCollector) {
    HibernateOrmIntegrationBooter booter = HibernateOrmIntegrationBooter.create(metadata, bootstrapContext);
    booter.preBoot(propertyCollector);
}
 
Example #21
Source File: InFlightMetadataCollectorImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public BootstrapContext getBootstrapContext() {
	return bootstrapContext;
}
 
Example #22
Source File: MappingDocument.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public BootstrapContext getBootstrapContext() {
	return rootBuildingContext.getBootstrapContext();
}
 
Example #23
Source File: XMLContext.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public XMLContext(BootstrapContext bootstrapContext) {
	this.classLoaderAccess = bootstrapContext.getClassLoaderAccess();
}
 
Example #24
Source File: JPAMetadataProvider.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public JPAMetadataProvider(BootstrapContext bootstrapContext) {
	this( bootstrapContext.getClassLoaderAccess() );
}
 
Example #25
Source File: JPAOverriddenAnnotationReader.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public JPAOverriddenAnnotationReader(
		AnnotatedElement el,
		XMLContext xmlContext,
		BootstrapContext bootstrapContext) {
	this( el, xmlContext, bootstrapContext.getClassLoaderAccess() );
}
 
Example #26
Source File: ComponentTuplizerFactory.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public ComponentTuplizerFactory(BootstrapContext bootstrapContext) {
	classLoaderAccess = bootstrapContext.getClassLoaderAccess();
}
 
Example #27
Source File: ReactiveSessionFactoryBuilderService.java    From hibernate-reactive with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
public SessionFactoryBuilderImplementor createSessionFactoryBuilder(final MetadataImpl metadata, final BootstrapContext bootstrapContext) {
	final SessionFactoryBuilderImpl defaultBuilder = new SessionFactoryBuilderImpl( metadata, bootstrapContext );
	final SessionFactoryBuilderImplementor reactiveSessionFactoryBuilder = new ReactiveSessionFactoryBuilder( metadata, defaultBuilder );
	return reactiveSessionFactoryBuilder;
}
 
Example #28
Source File: ComponentMetamodel.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public ComponentMetamodel(Component component, BootstrapContext bootstrapContext) {
	this( component, new ComponentTuplizerFactory( bootstrapContext ) );
}
 
Example #29
Source File: SessionFactoryServiceRegistryImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public BootstrapContext getBootstrapContext() {
	return bootstrapContext;
}
 
Example #30
Source File: MetadataBuildingProcess.java    From lams with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Unified single phase for MetadataSources->Metadata process
 *
 * @param sources The MetadataSources
 * @param options The building options
 *
 * @return The built Metadata
 */
public static MetadataImplementor build(
		final MetadataSources sources,
		final BootstrapContext bootstrapContext,
		final MetadataBuildingOptions options) {
	return complete( prepare( sources, bootstrapContext ), bootstrapContext, options );
}