B.1 Metadata Location


JDO metadata is specified in an XML file that must be available both during the enhancement process and at runtime. Because JDO can be used in many different application architecture scenarios, the location of the metadata file is quite flexible.

The metadata for a persistence-capable class can be located in a metadata file specific to the class or in a file that contains metadata for all persistence-capable classes in a given package hierarchy. A metadata file specific to a single class must be named after the class itself, but with a .jdo suffix. For example, the metadata for an Author class could be located in a file called Author.jdo . Alternatively, the metadata could be located in a file called package.jdo . This file would then contain the metadata for the Author class, as well as any other persistence-capable class in the same package hierarchy. In both situations, the metadata file should be available at runtime as a resource that can be loaded by the same class loader that loaded the class itself (i.e., it should be in the classpath). For example, the metadata for the class com.corejdo.examples.model.Author could be contained in one of the following files:

  • package.jdo

  • com/package.jdo

  • com/corejdo/package.jdo

  • com/corejdo/examples/package.jdo

  • com/corejdo/examples/model/package.jdo

  • com/corejdo/examples/model/Author.jdo

In addition to the above, the following locations are also supported:

  • META-INF/package.jdo

  • WEB-INF/package.jdo

The search order begins with META-INF/package.jdo , then goes to WEB-INF/package.jdo , followed by package.jdo , and then all the way down to com/corejdo/examples/model/Author.jdo . The first definition found for a given persistence-capable class is used. If no definition is found, a class is assumed to not be persistence capable.

The initial JDO 1.0 specification did not actually mandate the location and name of the XML metadata files. To aid in portability, the 1.0.1 maintenance release of the specification changed this to what has just been described.

Prior to this release, the name of a metadata file that contained multiple classes was the package name itself with a .jdo suffix, and it would have been located in the directory that contained the package directory. In the Author example, it would have been called model.jdo and would have been located in the com/corejdo/examples/ directory. JDO 1.0 implementations will still use this naming convention, and for backward compatibility, some JDO 1.0.1 implementations may also still allow this naming convention to be used.



Core Java Data Objects
Core Java Data Objects
ISBN: 0131407317
EAN: 2147483647
Year: 2003
Pages: 146

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net