Chapter 5 JDO metadata
JDO requires every long-lasting class must have dollar data. The metadata has three basic functions: 1) Identification persistent class 2) Rebuilder JDO behavior 3) Tell the JDO persistent class within the provincial information
Metadata is an XML document. The next section will discuss its DTD. No need to ask yourself immediately understand DTD, we will fully introduce it next section.
The JDO element is the root element of the metadata document. It has only one child element. Every package element must use the package full name to specify the name attribute.
The package element contains one or more Class elements. There are 0 or more extended elements behind the child. The role of the extended element is to interpret the metadata with the information specified by the vendor. The extended element can also include an extension sub-element. It has three Property: Vendor Name: Which vendor applied to extended elements. Must be provided. Keyword: The name of the extended attribute you set. Each manufacturer will provide a list of supported properties. Value: The value of the property is in the package element The lasting class must have a class element. Before explanation it, you will easily understand how JDO is parsed. Some metadata properties require you to specify the class name. Category Name must be followed: 1) If the package is the package is the current package Elements, then just give the class name. You don't have to specify the package name. For example, if the current package is org.mag, the class name is org.mag.magazine, then the class name is only written by Magazine 2) Otherwise, you must give the package Class name. 3) If the class is embedded, it must be written in the form of an inline class. Such as SubscriptionForm $ LineItem
Continue to introduce Class elements now. This element has the following properties: name: Class name, required attribute persistence-capable-superclass: If the parent class is persistent, you want JDO to know this inheritance level, then you must be in this property Specify the parent class. If the parent class is non-persistent, you should not use this attribute Identity-Type: The JDO ID used by the class .Application means using the application ID, Datastore means that NONE is not used. If the ObjectID-Class property is specified, the default value is Application. Otherwise, for the DataStore ObjectID-Class: Use the identity of the application. The property value is the value of the JDO identification class. Note Simply give the value of the base class Requires-Extent: If you don't query this class's persistence instance, the property value is false. (For example, all objects of this class can be found through the JDO identity to find or pass the relationship between other objects) Default to true TRUE
The Class element can contain the extension element and the field element. Field element reflects a field that can last-time declaration, which is optional. If the class declaration is not given in the field element, its value is shown below the attributes listed below Come. Thank JDO to understand the default settings, many fields do not have to be explicitly listed. Field elements have the following properties: Name: field name. Persistent class declaration field name. Required. Persistence-modifier: Specify how JDO management Field. This approach is reasonable. If it is a persistence field, set to Persistent. If it is a transaction, it is set to Non-persistent. And none. Default value is determined by the type of field. 1) State as Static, TRANSIENT, FINAL for None 2) Any basic type and basic type package is Persistent 3) java.lang.string, java.lang.Number, Java.math.Big IndiMal, Java.math.biginteger, ava.util.locale, and Java .util.date default for the Persistent 4) Field Type to Custom Sustained Class For Persistent 5) The above types of the array is also a collection class in Persistent 6) java.util, such as List, Map, Set, Collection, Hashset Equally, for Persistent 7) Other all none primary-key: If the class uses the application ID and the field is the primary key field, set to true, otherwise, if the value is Null, the field is written to the data. Stored. If the value of this field is stored as NULL, set none. If you want to store the default value of a database, set to the default, finally, if the field will be written to the data store, its value is null, and you I want to throw an exception. So you should be set to Exception. The default is none default-fetch-group: The default detail group field as a group management. This can improve efficiency. For example, from the database read a batch of data, put one Batch data is written to the database. If the field type is the basic type, the basic type packaging, string, date, BigDecimal, and Biginteger, the property value is true. The other types of defaults are false. (Note that the default is false does not represent false) Embedded : This property prompts JDO to store this field as part of the class instance to the database. Not saved as a separate entity. If the type is the basic type, the basic type packaging, the date, the BigDecimal, and Biginteger, the array, the collection, and the Map type, the default is true. Other types of default is false. Embedded objects cannot be class EXTENT appears and cannot be obtained by query.
All Field elements should include Extension child elements. If the field is an array, a collection or MAP may further include an array, a collection, or Map child element. Separately, each such sub-elements will contain additional extension element Array Elements only one Properties. EMBEDDED-Element, this property maps the Attribute property of the Class element, is applied to each array index. The Collection element also has .embedded-element properties. There is a Element-Type property. This property tells the collection. What is included? The default is included Object
MSP elements define four properties, they are: 1) Key-Type: MAP type. The default is Object 2) Embedded-key: Similar to the attributes of the collection. Application to all map keys 3) value-type: map Value type, default is Object 4) Embedded-value: and Embedded-key Similar to all MAP Value
The document structure of metadata is listed here. The following is provided with a complete example:
5.2. Metadata positioning
ORG / MAG / MAGAZINE.JDO ORG / MAG / PACKAGE.JDO ORG / PACKAGE.JDO PACKAGE.JDO
Metadata is required when enhancing classes and runts. The metadata documentation must be loaded as a resource. You must be placed in the following locations: 1) Take a resource file named class .jdo. The class name refers to the class that the metadata will work on. This resource file must be placed under the same package. 2) Named. JDO. This resource file must be stored with the corresponding package, or the package of any ancestors. The package level document must contain metadata including all sustainable classes, except for those classes that have their own class name. JDO. They may also contain metadata of the subparacket. Suppose you use a standard type-loader, there is a class Magazine definition in file org / mag / magazine.class, then the corresponding metadata document should be defined below: 1) ORG / MAG / MAGAZINE.JDO 2 ) ORG / MAG / PACKAGE.JDO 3) ORG / PACKAGE.JDO 4) Package.JDO
Since metadata is loaded as a resource, the JDO page can read it from the FAR file.