Class MetadataSources
- All Implemented Interfaces:
Serializable
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 Configuration
.
- Since:
- 5.0
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionCreate a new instance, using a defaultBootstrapServiceRegistry
.MetadataSources
(ServiceRegistry serviceRegistry) Create a new instance using the givenServiceRegistry
.MetadataSources
(ServiceRegistry serviceRegistry, XmlMappingBinderAccess xmlMappingBinderAccess) Create a new instance using the givenServiceRegistry
. -
Method Summary
Modifier and TypeMethodDescriptionaddAnnotatedClass
(Class<?> annotatedClass) Read metadata from the annotations attached to the given class.addAnnotatedClasses
(Class<?>... annotatedClasses) Vararg form ofaddAnnotatedClass(Class)
.addAnnotatedClassName
(String annotatedClassName) Read metadata from the annotations attached to the given class.addAnnotatedClassNames
(String... annotatedClassNames) Vararg form ofaddAnnotatedClassName(String)
.addCacheableFile
(File file) Add a cached mapping file.addCacheableFile
(File file, File cacheDirectory) Add a cached mapping file.addCacheableFile
(String path) Add acached mapping file
.addCacheableFile
(String path, File cacheDirectory) Add acached mapping file
.addCacheableFileStrictly
(File file) INTENDED FOR TESTSUITE USE ONLY!addCacheableFileStrictly
(File file, File cacheDir) INTENDED FOR TESTSUITE USE ONLY!addDirectory
(File dir) Read all.hbm.xml
mapping documents from a directory tree.Read mappings from a particular XML file.Read mappings from a particular XML file.addHbmXmlBinding
(Binding<JaxbHbmHibernateMapping> binding) addInputStream
(InputStream xmlInputStream) Read metadata from anInputStream
.addInputStream
(InputStreamAccess xmlInputStreamAccess) Read metadata from anInputStream
accessRead all.hbm.xml
mappings from a jar file.Add a binding for mapping.xsd documentaddPackage
(Package packageRef) Read package-level metadata.addPackage
(String packageName) Read package-level metadata.addQueryImport
(String importedName, Class<?> target) addResource
(String name) Read mappings as an application resourceName (i.e.Read mappings from aURL
addXmlBinding
(Binding<?> binding) Add XML mapping bindings created from an arbitrary source by the binder.Shorthand form of callinggetMetadataBuilder()
and using itsMetadataBuilder.build()
method in cases where the application wants to accept the defaults.buildMetadata
(StandardServiceRegistry serviceRegistry) Collection<Class<?>>
Get a builder for metadata where non-default options can be specified.getMetadataBuilder
(StandardServiceRegistry serviceRegistry) Get a builder for metadata where non-default options can be specified.Deprecated.Prefer getMappingXmlBindings() and/or getHbmXmlBindings()protected static boolean
isExpectedServiceRegistryType
(ServiceRegistry serviceRegistry)
-
Constructor Details
-
MetadataSources
public MetadataSources()Create a new instance, using a defaultBootstrapServiceRegistry
. -
MetadataSources
Create a new instance using the givenServiceRegistry
.- Parameters:
serviceRegistry
- The service registry to use.
-
MetadataSources
public MetadataSources(ServiceRegistry serviceRegistry, XmlMappingBinderAccess xmlMappingBinderAccess) Create a new instance using the givenServiceRegistry
.- Parameters:
serviceRegistry
- The service registry to use.
-
-
Method Details
-
isExpectedServiceRegistryType
-
getXmlMappingBinderAccess
-
getXmlBindings
Deprecated.Prefer getMappingXmlBindings() and/or getHbmXmlBindings() -
getMappingXmlBindings
-
getHbmXmlBindings
-
getAnnotatedPackages
-
getAnnotatedClasses
-
getAnnotatedClassNames
-
getExtraQueryImports
-
getServiceRegistry
-
getMetadataBuilder
Get a builder for metadata where non-default options can be specified.- Returns:
- The built metadata.
-
getMetadataBuilder
Get a builder for metadata where non-default options can be specified.- Returns:
- The built metadata.
-
buildMetadata
Shorthand form of callinggetMetadataBuilder()
and using itsMetadataBuilder.build()
method in cases where the application wants to accept the defaults.- Returns:
- The built metadata.
-
buildMetadata
-
addAnnotatedClass
Read metadata from the annotations attached to the given class.- Parameters:
annotatedClass
- The class containing annotations- Returns:
- this (for method chaining)
-
addAnnotatedClasses
Vararg form ofaddAnnotatedClass(Class)
. -
addAnnotatedClassName
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)
-
addAnnotatedClassNames
Vararg form ofaddAnnotatedClassName(String)
. -
addQueryImport
-
addPackage
Read package-level metadata.- Parameters:
packageName
- java package name without trailing '.', cannot benull
- Returns:
- this (for method chaining)
-
addPackage
Read package-level metadata.- Parameters:
packageRef
- Java Package reference- Returns:
- this (for method chaining)
-
addResource
Read mappings as an application resourceName (i.e. classpath lookup).- Parameters:
name
- The resource name- Returns:
- this (for method chaining purposes)
-
addFile
Read mappings from a particular XML file.The given path is resolved using
File(String)
.- Parameters:
path
- The path to a file- Returns:
- this (for method chaining purposes)
- See Also:
-
addFile
Read mappings from a particular XML file.- Parameters:
file
- The reference to the XML file- Returns:
- this (for method chaining purposes)
-
addXmlBinding
Add XML mapping bindings created from an arbitrary source by the binder.- Parameters:
binding
- The binding- Returns:
- this (for method chaining purposes)
-
addMappingXmlBinding
Add a binding for mapping.xsd document- Parameters:
binding
- The binding- Returns:
- this (for method chaining purposes)
-
addHbmXmlBinding
- Parameters:
binding
- The binding- Returns:
- this (for method chaining purposes)
-
addCacheableFile
Add acached mapping file
.The given path is resolved using
File(String)
.- Parameters:
path
- The path to a file- Returns:
- this (for method chaining purposes)
- See Also:
-
addCacheableFile
Add acached mapping file
.The given path is resolved using
File(String)
.- Parameters:
path
- The path to a file- Returns:
- this (for method chaining purposes)
- See Also:
-
addCacheableFile
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)
-
addCacheableFile
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
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
- The xml file, not the bin!- Returns:
- The dom "deserialized" from the cached file.
- Throws:
SerializationException
- Indicates a problem deserializing the cached dom treeMappingNotFoundException
- Indicates that the cached file was not found or was not usable.
-
addCacheableFileStrictly
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
- The xml file, not the bin!- Returns:
- The dom "deserialized" from the cached file.
- Throws:
SerializationException
- Indicates a problem deserializing the cached dom treeMappingNotFoundException
- Indicates that the cached file was not found or was not usable.
-
addInputStream
Read metadata from anInputStream
access- Parameters:
xmlInputStreamAccess
- Access to an input stream containing a DOM.- Returns:
- this (for method chaining purposes)
-
addInputStream
Read metadata from anInputStream
.- Parameters:
xmlInputStream
- The input stream containing a DOM.- Returns:
- this (for method chaining purposes)
-
addURL
Read mappings from aURL
- Parameters:
url
- The url for the mapping document to be read.- Returns:
- this (for method chaining purposes)
-
addJar
Read all.hbm.xml
mappings from a jar file.Assumes that any file named
*.hbm.xml
is a mapping document. This method does not supportorm.xml
files!- Parameters:
jar
- a jar file- Returns:
- this (for method chaining purposes)
-
addDirectory
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 supportorm.xml
files!- Parameters:
dir
- The directory- Returns:
- this (for method chaining purposes)
- Throws:
MappingException
- Indicates problems reading the jar file or processing the contained mapping documents.
-