Package org.hibernate.boot
Class MetadataSources
- java.lang.Object
-
- org.hibernate.boot.MetadataSources
-
- All Implemented Interfaces:
Serializable
public class MetadataSources extends Object implements Serializable
Entry point into working with sources of metadata information (mapping XML, annotations). Tell Hibernate about sources and then callbuildMetadata()
, or usegetMetadataBuilder()
to customize how sources are processed (naming strategies, etc).- Since:
- 5.0
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description MetadataSources()
MetadataSources(ServiceRegistry serviceRegistry)
Create a metadata sources using the specified service registry.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description MetadataSources
addAnnotatedClass(Class annotatedClass)
Read metadata from the annotations attached to the given class.MetadataSources
addAnnotatedClassName(String annotatedClassName)
Read metadata from the annotations attached to the given class.MetadataSources
addCacheableFile(File file)
Add a cached mapping file.MetadataSources
addCacheableFile(String path)
SeeaddCacheableFile(java.io.File)
for descriptionMetadataSources
addCacheableFileStrictly(File file)
INTENDED FOR TESTSUITE USE ONLY!MetadataSources
addClass(Class entityClass)
Deprecated.hbm.xml is a legacy mapping format now considered deprecated.MetadataSources
addDirectory(File dir)
Read all mapping documents from a directory tree.MetadataSources
addDocument(Document document)
Deprecated.since 5.0.MetadataSources
addFile(File file)
Read mappings from a particular XML fileMetadataSources
addFile(String path)
Read mappings from a particular XML fileMetadataSources
addInputStream(InputStream xmlInputStream)
Read metadata from anInputStream
.MetadataSources
addInputStream(InputStreamAccess xmlInputStreamAccess)
Read metadata from anInputStream
accessMetadataSources
addJar(File jar)
Read all mappings from a jar file.MetadataSources
addPackage(Package packageRef)
Read package-level metadata.MetadataSources
addPackage(String packageName)
Read package-level metadata.MetadataSources
addResource(String name)
Read mappings as a application resourceName (i.e.MetadataSources
addURL(URL url)
Read mappings from aURL
Metadata
buildMetadata()
Short-hand form of callinggetMetadataBuilder()
and using itsMetadataBuilder.build()
method in cases where the application wants to accept the defaults.Metadata
buildMetadata(StandardServiceRegistry serviceRegistry)
Collection<Class<?>>
getAnnotatedClasses()
Collection<String>
getAnnotatedClassNames()
Collection<String>
getAnnotatedPackages()
MetadataBuilder
getMetadataBuilder()
Get a builder for metadata where non-default options can be specified.MetadataBuilder
getMetadataBuilder(StandardServiceRegistry serviceRegistry)
Deprecated.UsegetMetadataBuilder()
insteadServiceRegistry
getServiceRegistry()
List<Binding>
getXmlBindings()
XmlMappingBinderAccess
getXmlMappingBinderAccess()
protected static boolean
isExpectedServiceRegistryType(ServiceRegistry serviceRegistry)
-
-
-
Constructor Detail
-
MetadataSources
public MetadataSources()
-
MetadataSources
public MetadataSources(ServiceRegistry serviceRegistry)
Create a metadata sources using the specified service registry.- Parameters:
serviceRegistry
- The service registry to use.
-
-
Method Detail
-
isExpectedServiceRegistryType
protected static boolean isExpectedServiceRegistryType(ServiceRegistry serviceRegistry)
-
getXmlMappingBinderAccess
public XmlMappingBinderAccess getXmlMappingBinderAccess()
-
getAnnotatedPackages
public Collection<String> getAnnotatedPackages()
-
getAnnotatedClasses
public Collection<Class<?>> getAnnotatedClasses()
-
getAnnotatedClassNames
public Collection<String> getAnnotatedClassNames()
-
getServiceRegistry
public ServiceRegistry getServiceRegistry()
-
getMetadataBuilder
public MetadataBuilder getMetadataBuilder()
Get a builder for metadata where non-default options can be specified.- Returns:
- The built metadata.
-
getMetadataBuilder
@Deprecated public MetadataBuilder getMetadataBuilder(StandardServiceRegistry serviceRegistry)
Deprecated.UsegetMetadataBuilder()
insteadGet a builder for metadata where non-default options can be specified.- Returns:
- The built metadata.
-
buildMetadata
public Metadata buildMetadata()
Short-hand form of callinggetMetadataBuilder()
and using itsMetadataBuilder.build()
method in cases where the application wants to accept the defaults.- Returns:
- The built metadata.
-
buildMetadata
public Metadata buildMetadata(StandardServiceRegistry serviceRegistry)
-
addAnnotatedClass
public MetadataSources addAnnotatedClass(Class annotatedClass)
Read metadata from the annotations attached to the given class.- Parameters:
annotatedClass
- The class containing annotations- Returns:
- this (for method chaining)
-
addAnnotatedClassName
public MetadataSources addAnnotatedClassName(String annotatedClassName)
Read metadata from the annotations attached to the given class. The important distinction here is that theClass
will not be accessed until later which is important for on-the-fly bytecode-enhancement- Parameters:
annotatedClassName
- The name of a class containing annotations- Returns:
- this (for method chaining)
-
addPackage
public MetadataSources addPackage(String packageName)
Read package-level metadata.- Parameters:
packageName
- java package name without trailing '.', cannot benull
- Returns:
- this (for method chaining)
-
addPackage
public MetadataSources addPackage(Package packageRef)
Read package-level metadata.- Parameters:
packageRef
- Java Package reference- Returns:
- this (for method chaining)
-
addClass
@Deprecated public MetadataSources addClass(Class 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 namedfoo.bar.Foo
is mapped by a file namedfoo/bar/Foo.hbm.xml
which can be resolved as a classpath resource.- Parameters:
entityClass
- The mapped class. Cannot benull
null.- Returns:
- this (for method chaining purposes)
-
addResource
public MetadataSources addResource(String name)
Read mappings as a application resourceName (i.e. classpath lookup).- Parameters:
name
- The resource name- Returns:
- this (for method chaining purposes)
-
addFile
public MetadataSources addFile(String path)
Read mappings from a particular XML file- Parameters:
path
- The path to a file. Expected to be resolvable byFile(String)
- Returns:
- this (for method chaining purposes)
- See Also:
addFile(java.io.File)
-
addFile
public MetadataSources addFile(File file)
Read mappings from a particular XML file- Parameters:
file
- The reference to the XML file- Returns:
- this (for method chaining purposes)
-
addCacheableFile
public MetadataSources addCacheableFile(String path)
SeeaddCacheableFile(java.io.File)
for description- Parameters:
path
- The path to a file. Expected to be resolvable byFile(String)
- Returns:
- this (for method chaining purposes)
- See Also:
addCacheableFile(java.io.File)
-
addCacheableFile
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
- The cacheable mapping file to be added,{xmlFile}
in above discussion.- Returns:
- this (for method chaining purposes)
-
addCacheableFileStrictly
public MetadataSources addCacheableFileStrictly(File file) throws SerializationException, FileNotFoundException
INTENDED FOR TESTSUITE USE ONLY! Much likeaddCacheableFile(java.io.File)
except that here we will fail immediately if the cache version cannot be found or used for whatever reason- Parameters:
file
- The xml file, not the bin!- Returns:
- The dom "deserialized" from the cached file.
- Throws:
SerializationException
- Indicates a problem deserializing the cached dom treeFileNotFoundException
- Indicates that the cached file was not found or was not usable.
-
addInputStream
public MetadataSources addInputStream(InputStreamAccess xmlInputStreamAccess)
Read metadata from anInputStream
access- Parameters:
xmlInputStreamAccess
- Access to an input stream containing a DOM.- Returns:
- this (for method chaining purposes)
-
addInputStream
public MetadataSources addInputStream(InputStream xmlInputStream)
Read metadata from anInputStream
.- Parameters:
xmlInputStream
- The input stream containing a DOM.- Returns:
- this (for method chaining purposes)
-
addURL
public MetadataSources addURL(URL url)
Read mappings from aURL
- Parameters:
url
- The url for the mapping document to be read.- Returns:
- this (for method chaining purposes)
-
addDocument
@Deprecated public MetadataSources addDocument(Document document)
Deprecated.since 5.0. Use one of the other methods for passing mapping source(s).Read mappings from a DOMDocument
- Parameters:
document
- The DOM document- Returns:
- this (for method chaining purposes)
-
addJar
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
- a jar file- Returns:
- this (for method chaining purposes)
-
addDirectory
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
- The directory- Returns:
- this (for method chaining purposes)
- Throws:
MappingException
- Indicates problems reading the jar file or processing the contained mapping documents.
-
-