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, .FileNotFoundException, .IOException, .InputStream, .Serializable, java.net.URL, java.util.ArrayList, .Collection, .Collections, .Enumeration, .LinkedHashSet, .List, .Objects, java.util.jar.JarFile, java.util.zip.ZipEntry, javax.xml.transform.dom.DOMSource, org.hibernate.HibernateException, org.hibernate.boot.archive.spi.InputStreamAccess, org.hibernate.boot.internal.MetadataBuilderImpl, org.hibernate.boot.jaxb.Origin, .SourceType, org.hibernate.boot.jaxb.internal.CacheableFileXmlSource, .JarFileEntryXmlSource, .JaxpSourceXmlSource, org.hibernate.boot.jaxb.spi.Binding, 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, org.w3c.dom.Document

Entry point into working with sources of metadata information (mapping XML, annotations). Tell Hibernate about sources and then call buildMetadata(), or use getMetadataBuilder() to customize how sources are processed (naming strategies, etc).
Author
Steve Ebersole
Since
5.0

Field Summary

Modifier and TypeField and Description
private LinkedHashSet<Class<?>>
private LinkedHashSet<String>
private LinkedHashSet<String>
private final boolean
private static final CoreMessageLogger
private final ServiceRegistry
private List<Binding<T>>
private XmlMappingBinderAccess

Constructor Summary

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

Create a metadata sources using the specified service registry.

public
MetadataSources(ServiceRegistry serviceRegistry, boolean disableXmlMappingBinders)

Consider this an SPI, used by Quarkus

Method Summary

Modifier and TypeMethod and Description
public MetadataSources

Returns:

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

Read metadata from the annotations attached to the given 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

Returns:

this (for method chaining purposes)
addCacheableFile
(String
The path to a file. Expected to be resolvable by java.io.File#File(String)
path
)

See addCacheableFile(java.io.File) for description

private void
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:

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

INTENDED FOR TESTSUITE USE ONLY!

public MetadataSources

Returns:

this (for method chaining purposes)
addClass
(Class<T>
The mapped class. Cannot be null null.
entityClass
)

Deprecated hbm.xml is a legacy mapping format now considered deprecated.
Read a mapping as an application resource using the convention that a class named foo.bar.Foo is mapped by a file named foo/bar/Foo.hbm.xml which can be resolved as a classpath resource.
public MetadataSources

Returns:

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

Read all mapping documents from a directory tree.

public MetadataSources

Returns:

this (for method chaining purposes)
addDocument
(Document
The DOM document
document
)

Deprecated since 5.0. Use one of the other methods for passing mapping source(s).
Read mappings from a DOM org.w3c.dom.Document
public MetadataSources

Returns:

this (for method chaining purposes)
addFile
(String
The path to a file. Expected to be resolvable by java.io.File#File(String)
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 java.io.InputStream access

public MetadataSources

Returns:

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

Read metadata from an java.io.InputStream.

public MetadataSources

Returns:

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

Read all 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

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 java.net.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
()

Short-hand form of calling getMetadataBuilder() and using its org.hibernate.boot.MetadataBuilder#build() method in cases where the application wants to accept the defaults.

public Metadata
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 the default builder.

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)

Deprecated Use getMetadataBuilder() instead
Get a builder for metadata where non-default options can be specified.
public ServiceRegistry
public List<Binding<T>>
private <Binding> List<E>
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
disableXmlMappingBindersback to summary
private final boolean disableXmlMappingBinders
LOGback to summary
private static final CoreMessageLogger LOG
serviceRegistryback to summary
private final ServiceRegistry serviceRegistry
xmlBindingsback to summary
private List<Binding<T>> xmlBindings
xmlMappingBinderAccessback to summary
private XmlMappingBinderAccess xmlMappingBinderAccess

Constructor Detail

MetadataSourcesback to summary
public MetadataSources()
MetadataSourcesback to summary
public MetadataSources(ServiceRegistry serviceRegistry)

Create a metadata sources using the specified service registry.

Parameters
serviceRegistry:ServiceRegistry

The service registry to use.

MetadataSourcesback to summary
public MetadataSources(ServiceRegistry serviceRegistry, boolean disableXmlMappingBinders)

Consider this an SPI, used by Quarkus

Method Detail

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

Read metadata from the annotations attached to the given class.

Parameters
annotatedClass:Class<T>

The class containing annotations

Returns:MetadataSources

this (for method chaining)

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)

addCacheableFileback to summary
public MetadataSources addCacheableFile(String path)

See addCacheableFile(java.io.File) for description

Parameters
path:String

The path to a file. Expected to be resolvable by java.io.File#File(String)

Returns:MetadataSources

this (for method chaining purposes)

See Also
addCacheableFile(java.io.File)
addCacheableFileback to summary
private void addCacheableFile(Origin origin, File 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)

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

INTENDED FOR TESTSUITE USE ONLY!

Much like addCacheableFile(java.io.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
FileNotFoundException:
Indicates that the cached file was not found or was not usable.
addClassback to summary
public MetadataSources addClass(Class<T> entityClass)

Deprecated

hbm.xml is a legacy mapping format now considered deprecated.

Read a mapping as an application resource using the convention that a class named foo.bar.Foo is mapped by a file named foo/bar/Foo.hbm.xml which can be resolved as a classpath resource.

Parameters
entityClass:Class<T>

The mapped class. Cannot be null null.

Returns:MetadataSources

this (for method chaining purposes)

Annotations
@Deprecated
addDirectoryback to summary
public MetadataSources addDirectory(File dir)

Read all mapping documents from a directory tree.

Assumes that any file named *.hbm.xml is a mapping document.

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.
addDocumentback to summary
public MetadataSources addDocument(Document document)

Deprecated

since 5.0. Use one of the other methods for passing mapping source(s).

Read mappings from a DOM org.w3c.dom.Document

Parameters
document:Document

The DOM document

Returns:MetadataSources

this (for method chaining purposes)

Annotations
@Deprecated
addFileback to summary
public MetadataSources addFile(String path)

Read mappings from a particular XML file

Parameters
path:String

The path to a file. Expected to be resolvable by java.io.File#File(String)

Returns:MetadataSources

this (for method chaining purposes)

See Also
addFile(java.io.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 java.io.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 java.io.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 mappings from a jar file.

Assumes that any file named *.hbm.xml is a mapping document.

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)
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 java.net.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()

Short-hand form of calling getMetadataBuilder() and using its org.hibernate.boot.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)
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 the default builder.

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)

Deprecated

Use getMetadataBuilder() instead

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

Returns:MetadataBuilder

The built metadata.

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