Top Description Fields Constructors Methods
org.hibernate.boot

public Class MetadataSources

extends Object
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable
Imports
java.io.File, .InputStream, .Serializable, java.net.URL, java.util.ArrayList, .Collection, .Collections, .HashMap, .LinkedHashSet, .List, .Map, org.hibernate.HibernateException, .Internal, org.hibernate.boot.archive.spi.InputStreamAccess, org.hibernate.boot.internal.MetadataBuilderImpl, org.hibernate.boot.jaxb.internal.XmlSources, org.hibernate.boot.jaxb.spi.BindableMappingDescriptor, .Binding, .XmlSource, org.hibernate.boot.registry.BootstrapServiceRegistry, .BootstrapServiceRegistryBuilder, .StandardServiceRegistry, org.hibernate.boot.registry.classloading.spi.ClassLoaderService, org.hibernate.boot.spi.MetadataBuilderFactory, .XmlMappingBinderAccess, org.hibernate.internal.CoreLogging, .CoreMessageLogger, org.hibernate.service.ServiceRegistry, org.hibernate.type.SerializationException

Entry point for working with sources of O/R mapping metadata, either in the form of annotated classes, or as XML mapping documents.

Note that XML mappings may be expressed using the JPA orm.xml format, or in Hibernate's legacy .hbm.xml format.

An instance of MetadataSources may be obtained simply by instantiation, using new MetadataSources(). The client must register sources and then call buildMetadata(), or use getMetadataBuilder() to customize how the sources are processed (by registering naming strategies, etc).

As an alternative to working directly with MetadataSources, and Metadata, a program may use org.hibernate.cfg.Configuration.

Author
Steve Ebersole
Since
5.0

Field Summary

Modifier and TypeField and Description
private LinkedHashSet<Class<?>>
private LinkedHashSet<String>
private LinkedHashSet<String>
private final ClassLoaderService
private Map<String, Class<?>>
private static final CoreMessageLogger
private final ServiceRegistry
private List<Binding<BindableMappingDescriptor>>
private XmlMappingBinderAccess

Constructor Summary

AccessConstructor and Description
public
MetadataSources()

Create a new instance, using a default BootstrapServiceRegistry.

public
MetadataSources(ServiceRegistry
The service registry to use.
serviceRegistry
)

Create a new instance using the given ServiceRegistry.

public
MetadataSources(ServiceRegistry
The service registry to use.
serviceRegistry
,
XmlMappingBinderAccess xmlMappingBinderAccess)

Create a new instance using the given ServiceRegistry.

Method Summary

Modifier and TypeMethod and Description
public MetadataSources

Returns:

this (for method chaining)
addAnnotatedClass
(Class<?>
The class containing annotations
annotatedClass
)

Read metadata from the annotations attached to the given class.

public MetadataSources
addAnnotatedClasses(Class<?>... annotatedClasses)

Vararg form of addAnnotatedClass(Class).

public MetadataSources

Returns:

this (for method chaining)
addAnnotatedClassName
(String
The name of a class containing annotations
annotatedClassName
)

Read metadata from the annotations attached to the given class.

public MetadataSources
addAnnotatedClassNames(String... annotatedClassNames)

Vararg form of addAnnotatedClassName(String).

public MetadataSources

Returns:

this (for method chaining purposes)
addCacheableFile
(String
The path to a file
path
)

Add a cached mapping file.

public MetadataSources

Returns:

this (for method chaining purposes)
addCacheableFile
(String
The path to a file
path
,
File cacheDirectory)

Add a cached mapping file.

public MetadataSources

Returns:

this (for method chaining purposes)
addCacheableFile
(File
The cacheable mapping file to be added, {xmlFile} in above discussion.
file
)

Add a cached mapping file.

public MetadataSources

Returns:

this (for method chaining purposes)
addCacheableFile
(File
The cacheable mapping file to be added, {xmlFile} in above discussion.
file
,
File cacheDirectory)

Add a cached mapping file.

public MetadataSources

Returns:

The dom "deserialized" from the cached file.
addCacheableFileStrictly
(File
The xml file, not the bin!
file
)

INTENDED FOR TESTSUITE USE ONLY!

public MetadataSources

Returns:

The dom "deserialized" from the cached file.
addCacheableFileStrictly
(File
The xml file, not the bin!
file
,
File cacheDir)

INTENDED FOR TESTSUITE USE ONLY!

public MetadataSources

Returns:

this (for method chaining purposes)
addDirectory
(File
The directory
dir
)

Read all .hbm.xml mapping documents from a directory tree.

public MetadataSources

Returns:

this (for method chaining purposes)
addFile
(String
The path to a file
path
)

Read mappings from a particular XML file.

public MetadataSources

Returns:

this (for method chaining purposes)
addFile
(File
The reference to the XML file
file
)

Read mappings from a particular XML file.

public MetadataSources

Returns:

this (for method chaining purposes)
addInputStream
(InputStreamAccess
Access to an input stream containing a DOM.
xmlInputStreamAccess
)

Read metadata from an InputStream access

public MetadataSources

Returns:

this (for method chaining purposes)
addInputStream
(InputStream
The input stream containing a DOM.
xmlInputStream
)

Read metadata from an InputStream.

public MetadataSources

Returns:

this (for method chaining purposes)
addJar
(File
a jar file
jar
)

Read all .hbm.xml mappings from a jar file.

public MetadataSources

Returns:

this (for method chaining)
addPackage
(String
java package name without trailing '.', cannot be null
packageName
)

Read package-level metadata.

public MetadataSources

Returns:

this (for method chaining)
addPackage
(Package
Java Package reference
packageRef
)

Read package-level metadata.

private void
public MetadataSources
addQueryImport(String importedName, Class<?> target)

public MetadataSources

Returns:

this (for method chaining purposes)
addResource
(String
The resource name
name
)

Read mappings as an application resourceName (i.e. classpath lookup).

public MetadataSources

Returns:

this (for method chaining purposes)
addURL
(URL
The url for the mapping document to be read.
url
)

Read mappings from a URL

public MetadataSources

Returns:

this (for method chaining purposes)
addXmlBinding
(Binding<?>
The binding
binding
)

Add XML mapping bindings created from an arbitrary source by the binder.

public Metadata

Returns:

The built metadata.
buildMetadata
()

Deprecated as a consequence of Metadata being deprecated.
Shorthand form of calling getMetadataBuilder() and using its MetadataBuilder#build() method in cases where the application wants to accept the defaults.
public Metadata
buildMetadata(StandardServiceRegistry serviceRegistry)

Deprecated as a consequence of Metadata being deprecated.
public Collection<Class<?>>
public Collection<String>
public Collection<String>
private MetadataBuilder
getCustomBuilderOrDefault(MetadataBuilderImpl defaultBuilder)

In case a custom MetadataBuilderFactory creates a custom builder, return that one, otherwise return the default builder.

public Map<String, Class<?>>
public MetadataBuilder

Returns:

The built metadata.
getMetadataBuilder
()

Get a builder for metadata where non-default options can be specified.

public MetadataBuilder

Returns:

The built metadata.
getMetadataBuilder
(StandardServiceRegistry serviceRegistry)

Get a builder for metadata where non-default options can be specified.

public ServiceRegistry
public List<Binding<BindableMappingDescriptor>>
private List<Binding<BindableMappingDescriptor>>
public XmlMappingBinderAccess
protected static boolean
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

annotatedClassesback to summary
private LinkedHashSet<Class<?>> annotatedClasses
annotatedClassNamesback to summary
private LinkedHashSet<String> annotatedClassNames
annotatedPackagesback to summary
private LinkedHashSet<String> annotatedPackages
classLoaderServiceback to summary
private final ClassLoaderService classLoaderService
extraQueryImportsback to summary
private Map<String, Class<?>> extraQueryImports
LOGback to summary
private static final CoreMessageLogger LOG
serviceRegistryback to summary
private final ServiceRegistry serviceRegistry
xmlBindingsback to summary
private List<Binding<BindableMappingDescriptor>> xmlBindings
xmlMappingBinderAccessback to summary
private XmlMappingBinderAccess xmlMappingBinderAccess

Constructor Detail

MetadataSourcesback to summary
public MetadataSources()

Create a new instance, using a default BootstrapServiceRegistry.

MetadataSourcesback to summary
public MetadataSources(ServiceRegistry serviceRegistry)

Create a new instance using the given ServiceRegistry.

Parameters
serviceRegistry:ServiceRegistry

The service registry to use.

MetadataSourcesback to summary
public MetadataSources(ServiceRegistry serviceRegistry, XmlMappingBinderAccess xmlMappingBinderAccess)

Create a new instance using the given ServiceRegistry.

Parameters
serviceRegistry:ServiceRegistry

The service registry to use.

Method Detail

addAnnotatedClassback to summary
public MetadataSources addAnnotatedClass(Class<?> annotatedClass)

Read metadata from the annotations attached to the given class.

Parameters
annotatedClass:Class<?>

The class containing annotations

Returns:MetadataSources

this (for method chaining)

addAnnotatedClassesback to summary
public MetadataSources addAnnotatedClasses(Class<?>... annotatedClasses)

Vararg form of addAnnotatedClass(Class).

addAnnotatedClassNameback to summary
public MetadataSources addAnnotatedClassName(String annotatedClassName)

Read metadata from the annotations attached to the given class. The important distinction here is that the Class will not be accessed until later, which is important for on-the-fly bytecode enhancement

Parameters
annotatedClassName:String

The name of a class containing annotations

Returns:MetadataSources

this (for method chaining)

addAnnotatedClassNamesback to summary
public MetadataSources addAnnotatedClassNames(String... annotatedClassNames)

Vararg form of addAnnotatedClassName(String).

addCacheableFileback to summary
public MetadataSources addCacheableFile(String path)

Add a cached mapping file.

The given path is resolved using File#File(String).

Parameters
path:String

The path to a file

Returns:MetadataSources

this (for method chaining purposes)

See Also
addCacheableFile(File)
addCacheableFileback to summary
public MetadataSources addCacheableFile(String path, File cacheDirectory)

Add a cached mapping file.

The given path is resolved using File#File(String).

Parameters
path:String

The path to a file

Returns:MetadataSources

this (for method chaining purposes)

See Also
addCacheableFile(File)
addCacheableFileback to summary
public MetadataSources addCacheableFile(File file)

Add a cached mapping file. A cached file is a serialized representation of the DOM structure of a particular mapping. It is saved from a previous call as a file with the name {xmlFile}.bin where {xmlFile} is the name of the original mapping file.

If a cached {xmlFile}.bin exists and is newer than {xmlFile}, the {xmlFile}.bin file will be read directly. Otherwise {xmlFile} is read and then serialized to {xmlFile}.bin for use the next time.

Parameters
file:File

The cacheable mapping file to be added, {xmlFile} in above discussion.

Returns:MetadataSources

this (for method chaining purposes)

addCacheableFileback to summary
public MetadataSources addCacheableFile(File file, File cacheDirectory)

Add a cached mapping file. A cached file is a serialized representation of the DOM structure of a particular mapping. It is saved from a previous call as a file with the name {xmlFile}.bin where {xmlFile} is the name of the original mapping file.

If a cached {xmlFile}.bin exists and is newer than {xmlFile}, the {xmlFile}.bin file will be read directly. Otherwise {xmlFile} is read and then serialized to {xmlFile}.bin for use the next time.

Parameters
file:File

The cacheable mapping file to be added, {xmlFile} in above discussion.

Returns:MetadataSources

this (for method chaining purposes)

addCacheableFileStrictlyback to summary
public MetadataSources addCacheableFileStrictly(File file) throws SerializationException

INTENDED FOR TESTSUITE USE ONLY!

Much like addCacheableFile(File) except that here we will fail immediately if the cache version cannot be found or used for whatever reason.

Parameters
file:File

The xml file, not the bin!

Returns:MetadataSources

The dom "deserialized" from the cached file.

Exceptions
SerializationException:
Indicates a problem deserializing the cached dom tree
MappingNotFoundException:
Indicates that the cached file was not found or was not usable.
addCacheableFileStrictlyback to summary
public MetadataSources addCacheableFileStrictly(File file, File cacheDir) throws SerializationException

INTENDED FOR TESTSUITE USE ONLY!

Much like addCacheableFile(File) except that here we will fail immediately if the cache version cannot be found or used for whatever reason.

Parameters
file:File

The xml file, not the bin!

Returns:MetadataSources

The dom "deserialized" from the cached file.

Exceptions
SerializationException:
Indicates a problem deserializing the cached dom tree
MappingNotFoundException:
Indicates that the cached file was not found or was not usable.
addDirectoryback to summary
public MetadataSources addDirectory(File dir)

Read all .hbm.xml mapping documents from a directory tree.

Assumes that any file named *.hbm.xml is a mapping document. This method does not support orm.xml files!

Parameters
dir:File

The directory

Returns:MetadataSources

this (for method chaining purposes)

Exceptions
MappingException:
Indicates problems reading the jar file or processing the contained mapping documents.
addFileback to summary
public MetadataSources addFile(String path)

Read mappings from a particular XML file.

The given path is resolved using File#File(String).

Parameters
path:String

The path to a file

Returns:MetadataSources

this (for method chaining purposes)

See Also
addFile(File)
addFileback to summary
public MetadataSources addFile(File file)

Read mappings from a particular XML file.

Parameters
file:File

The reference to the XML file

Returns:MetadataSources

this (for method chaining purposes)

addInputStreamback to summary
public MetadataSources addInputStream(InputStreamAccess xmlInputStreamAccess)

Read metadata from an InputStream access

Parameters
xmlInputStreamAccess:InputStreamAccess

Access to an input stream containing a DOM.

Returns:MetadataSources

this (for method chaining purposes)

addInputStreamback to summary
public MetadataSources addInputStream(InputStream xmlInputStream)

Read metadata from an InputStream.

Parameters
xmlInputStream:InputStream

The input stream containing a DOM.

Returns:MetadataSources

this (for method chaining purposes)

addJarback to summary
public MetadataSources addJar(File jar)

Read all .hbm.xml mappings from a jar file.

Assumes that any file named *.hbm.xml is a mapping document. This method does not support orm.xml files!

Parameters
jar:File

a jar file

Returns:MetadataSources

this (for method chaining purposes)

addPackageback to summary
public MetadataSources addPackage(String packageName)

Read package-level metadata.

Parameters
packageName:String

java package name without trailing '.', cannot be null

Returns:MetadataSources

this (for method chaining)

addPackageback to summary
public MetadataSources addPackage(Package packageRef)

Read package-level metadata.

Parameters
packageRef:Package

Java Package reference

Returns:MetadataSources

this (for method chaining)

addPackageInternalback to summary
private void addPackageInternal(String packageName)
addQueryImportback to summary
public MetadataSources addQueryImport(String importedName, Class<?> target)
addResourceback to summary
public MetadataSources addResource(String name)

Read mappings as an application resourceName (i.e. classpath lookup).

Parameters
name:String

The resource name

Returns:MetadataSources

this (for method chaining purposes)

addURLback to summary
public MetadataSources addURL(URL url)

Read mappings from a URL

Parameters
url:URL

The url for the mapping document to be read.

Returns:MetadataSources

this (for method chaining purposes)

addXmlBindingback to summary
public MetadataSources addXmlBinding(Binding<?> binding)

Add XML mapping bindings created from an arbitrary source by the binder.

Parameters
binding:Binding<?>

The binding

Returns:MetadataSources

this (for method chaining purposes)

buildMetadataback to summary
public Metadata buildMetadata()

Deprecated

as a consequence of Metadata being deprecated. See corresponding docs for further information.

Shorthand form of calling getMetadataBuilder() and using its MetadataBuilder#build() method in cases where the application wants to accept the defaults.

Returns:Metadata

The built metadata.

buildMetadataback to summary
public Metadata buildMetadata(StandardServiceRegistry serviceRegistry)

Deprecated

as a consequence of Metadata being deprecated. See corresponding docs for further information.

getAnnotatedClassesback to summary
public Collection<Class<?>> getAnnotatedClasses()
getAnnotatedClassNamesback to summary
public Collection<String> getAnnotatedClassNames()
getAnnotatedPackagesback to summary
public Collection<String> getAnnotatedPackages()
getCustomBuilderOrDefaultback to summary
private MetadataBuilder getCustomBuilderOrDefault(MetadataBuilderImpl defaultBuilder)

In case a custom MetadataBuilderFactory creates a custom builder, return that one, otherwise return the default builder.

getExtraQueryImportsback to summary
public Map<String, Class<?>> getExtraQueryImports()
getMetadataBuilderback to summary
public MetadataBuilder getMetadataBuilder()

Get a builder for metadata where non-default options can be specified.

Returns:MetadataBuilder

The built metadata.

getMetadataBuilderback to summary
public MetadataBuilder getMetadataBuilder(StandardServiceRegistry serviceRegistry)

Get a builder for metadata where non-default options can be specified.

Returns:MetadataBuilder

The built metadata.

Annotations
@Internal
getServiceRegistryback to summary
public ServiceRegistry getServiceRegistry()
getXmlBindingsback to summary
public List<Binding<BindableMappingDescriptor>> getXmlBindings()
getXmlBindingsForWriteback to summary
private List<Binding<BindableMappingDescriptor>> getXmlBindingsForWrite()
getXmlMappingBinderAccessback to summary
public XmlMappingBinderAccess getXmlMappingBinderAccess()
isExpectedServiceRegistryTypeback to summary
protected static boolean isExpectedServiceRegistryType(ServiceRegistry serviceRegistry)