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 call buildMetadata()
, or use getMetadataBuilder()
to customize
how sources are processed (naming strategies, etc).
Constructor and Description |
---|
MetadataSources() |
MetadataSources(ServiceRegistry serviceRegistry)
Create a metadata sources using the specified service registry.
|
Modifier and Type | Method and 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)
See
addCacheableFile(java.io.File) for description |
MetadataSources |
addCacheableFileStrictly(File file)
<b>INTENDED FOR TESTSUITE USE ONLY!</b>
<p/>
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 |
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. Use one of the other methods for passing mapping source(s).
|
MetadataSources |
addFile(File file)
Read mappings from a particular XML file
|
MetadataSources |
addFile(String path)
Read mappings from a particular XML file
|
MetadataSources |
addInputStream(InputStream xmlInputStream)
Read metadata from an
InputStream . |
MetadataSources |
addInputStream(InputStreamAccess xmlInputStreamAccess)
Read metadata from an
InputStream access |
MetadataSources |
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 a
URL |
Metadata |
buildMetadata()
Short-hand form of calling
getMetadataBuilder() and using its
MetadataBuilder.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.
Use
getMetadataBuilder() instead |
ServiceRegistry |
getServiceRegistry() |
List<Binding> |
getXmlBindings() |
XmlMappingBinderAccess |
getXmlMappingBinderAccess() |
protected static boolean |
isExpectedServiceRegistryType(ServiceRegistry serviceRegistry) |
public MetadataSources()
public MetadataSources(ServiceRegistry serviceRegistry)
Create a metadata sources using the specified service registry.
serviceRegistry
- The service registry to use.protected static boolean isExpectedServiceRegistryType(ServiceRegistry serviceRegistry)
public XmlMappingBinderAccess getXmlMappingBinderAccess()
public Collection<String> getAnnotatedPackages()
public Collection<Class<?>> getAnnotatedClasses()
public Collection<String> getAnnotatedClassNames()
public ServiceRegistry getServiceRegistry()
public MetadataBuilder getMetadataBuilder()
Get a builder for metadata where non-default options can be specified.
@Deprecated public MetadataBuilder getMetadataBuilder(StandardServiceRegistry serviceRegistry)
getMetadataBuilder()
insteadGet a builder for metadata where non-default options can be specified.
public Metadata buildMetadata()
Short-hand 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)
public MetadataSources addAnnotatedClass(Class annotatedClass)
Read metadata from the annotations attached to the given class.
annotatedClass
- The class containing annotationspublic 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
annotatedClassName
- The name of a class containing annotationspublic MetadataSources addPackage(String packageName)
Read package-level metadata.
packageName
- java package name without trailing '.', cannot be null
public MetadataSources addPackage(Package packageRef)
Read package-level metadata.
packageRef
- Java Package reference@Deprecated public MetadataSources addClass(Class entityClass)
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.
entityClass
- The mapped class. Cannot be null
null.public MetadataSources addResource(String name)
Read mappings as a application resourceName (i.e. classpath lookup).
name
- The resource namepublic MetadataSources addFile(String path)
Read mappings from a particular XML file
path
- The path to a file. Expected to be resolvable by File.File(String)
addFile(java.io.File)
public MetadataSources addFile(File file)
Read mappings from a particular XML file
file
- The reference to the XML filepublic MetadataSources addCacheableFile(String path)
See addCacheableFile(java.io.File)
for description
path
- The path to a file. Expected to be resolvable by File.File(String)
addCacheableFile(java.io.File)
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.
</p>
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.
file
- The cacheable mapping file to be added, {xmlFile}
in above discussion.public MetadataSources addCacheableFileStrictly(File file) throws SerializationException, FileNotFoundException
<b>INTENDED FOR TESTSUITE USE ONLY!</b>
<p/>
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
file
- The xml file, not the bin!SerializationException
- Indicates a problem deserializing the cached dom treeFileNotFoundException
- Indicates that the cached file was not found or was not usable.public MetadataSources addInputStream(InputStreamAccess xmlInputStreamAccess)
Read metadata from an InputStream
access
xmlInputStreamAccess
- Access to an input stream containing a DOM.public MetadataSources addInputStream(InputStream xmlInputStream)
Read metadata from an InputStream
.
xmlInputStream
- The input stream containing a DOM.public MetadataSources addURL(URL url)
Read mappings from a URL
url
- The url for the mapping document to be read.@Deprecated public MetadataSources addDocument(Document document)
Read mappings from a DOM Document
document
- The DOM documentpublic MetadataSources addJar(File jar)
Read all mappings from a jar file. <p/> Assumes that any file named <tt>*.hbm.xml</tt> is a mapping document.
jar
- a jar filepublic MetadataSources addDirectory(File dir)
Read all mapping documents from a directory tree. <p/> Assumes that any file named <tt>*.hbm.xml</tt> is a mapping document.
dir
- The directoryMappingException
- Indicates problems reading the jar file or
processing the contained mapping documents.Copyright © 2001-2018 Red Hat, Inc. All Rights Reserved.