类org.hibernate.boot.spi.BootstrapContext源码实例Demo

下面列出了怎么用org.hibernate.boot.spi.BootstrapContext的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: teiid-spring-boot   文件: SchemaBuilderUtility.java
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();
}
 
源代码2 项目: lams   文件: SessionFactoryServiceRegistryImpl.java
@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;
}
 
源代码3 项目: lams   文件: ScanningCoordinator.java
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 );
}
 
源代码4 项目: lams   文件: InFlightMetadataCollectorImpl.java
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 );
}
 
源代码5 项目: teiid-spring-boot   文件: SchemaBuilderUtility.java
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;
}
 
public SessionFactoryServiceRegistry buildSessionFactoryServiceRegistry(
		SessionFactoryImplementor sessionFactory,
		BootstrapContext bootstrapContext,
		SessionFactoryOptions options) {
	return new SessionFactoryServiceRegistryImpl(
			parent,
			initiators,
			providedServices,
			sessionFactory,
			bootstrapContext,
			options
	);
}
 
@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 );
}
 
源代码8 项目: lams   文件: EventListenerRegistryImpl.java
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();
}
 
源代码9 项目: lams   文件: MetadataBuildingProcess.java
/**
 * 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;
}
 
源代码10 项目: lams   文件: ManagedResourcesImpl.java
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;
}
 
源代码11 项目: lams   文件: MetadataBuildingContextRootImpl.java
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;
		}
	};
}
 
源代码12 项目: lams   文件: SessionFactoryBuilderImpl.java
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() );
		}
	}
}
 
源代码13 项目: lams   文件: TypeConfiguration.java
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 );
}
 
@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;
}
 
源代码15 项目: quarkus   文件: HibernateOrmIntegrations.java
public static void onMetadataInitialized(Metadata metadata, BootstrapContext bootstrapContext,
        BiConsumer<String, Object> propertyCollector) {
    for (HibernateOrmIntegrationListener listener : LISTENERS) {
        listener.onMetadataInitialized(metadata, bootstrapContext, propertyCollector);
    }
}
 
源代码16 项目: quarkus   文件: HibernateOrmIntegrationListener.java
void onMetadataInitialized(Metadata metadata, BootstrapContext bootstrapContext,
BiConsumer<String, Object> propertyCollector);
 
@Override
public void onMetadataInitialized(Metadata metadata, BootstrapContext bootstrapContext,
        BiConsumer<String, Object> propertyCollector) {
    HibernateOrmIntegrationBooter booter = HibernateOrmIntegrationBooter.create(metadata, bootstrapContext);
    booter.preBoot(propertyCollector);
}
 
源代码18 项目: lams   文件: XMLContext.java
public XMLContext(BootstrapContext bootstrapContext) {
	this.classLoaderAccess = bootstrapContext.getClassLoaderAccess();
}
 
源代码19 项目: lams   文件: JPAMetadataProvider.java
public JPAMetadataProvider(BootstrapContext bootstrapContext) {
	this( bootstrapContext.getClassLoaderAccess() );
}
 
源代码20 项目: lams   文件: JPAOverriddenAnnotationReader.java
public JPAOverriddenAnnotationReader(
		AnnotatedElement el,
		XMLContext xmlContext,
		BootstrapContext bootstrapContext) {
	this( el, xmlContext, bootstrapContext.getClassLoaderAccess() );
}
 
源代码21 项目: lams   文件: ComponentTuplizerFactory.java
public ComponentTuplizerFactory(BootstrapContext bootstrapContext) {
	classLoaderAccess = bootstrapContext.getClassLoaderAccess();
}
 
源代码22 项目: lams   文件: ComponentMetamodel.java
public ComponentMetamodel(Component component, BootstrapContext bootstrapContext) {
	this( component, new ComponentTuplizerFactory( bootstrapContext ) );
}
 
源代码23 项目: lams   文件: SessionFactoryServiceRegistryImpl.java
@Override
public BootstrapContext getBootstrapContext() {
	return bootstrapContext;
}
 
源代码24 项目: lams   文件: ScanningCoordinator.java
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()
		);
	}
}
 
源代码25 项目: lams   文件: MappingDocument.java
@Override
public BootstrapContext getBootstrapContext() {
	return rootBuildingContext.getBootstrapContext();
}
 
源代码26 项目: lams   文件: InFlightMetadataCollectorImpl.java
@Override
public BootstrapContext getBootstrapContext() {
	return bootstrapContext;
}
 
源代码27 项目: lams   文件: MetadataBuildingContextRootImpl.java
@Override
public BootstrapContext getBootstrapContext() {
	return bootstrapContext;
}
 
源代码28 项目: lams   文件: MetadataBuilderImpl.java
@Override
public BootstrapContext getBootstrapContext() {
	return bootstrapContext;
}
 
源代码29 项目: lams   文件: MetadataImpl.java
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;
}
 
源代码30 项目: lams   文件: MetadataBuildingProcess.java
/**
 * 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 );
}
 
 类所在包
 同包方法