JDO metadata introduction
The Meta Data in JDO is a key content in JDO, just like EJB-JAR.XML in EJB, I write this article is exactly the convenience of review, because most JDO tools or wizards can be based on you The persistent object automatically generates the corresponding JDO metadata, but in order to facilitate you to learn and understand their meaning, I still put it here hoping to help you learn JDO.
In JDO, each of the sustainable classes has a corresponding metadata file, and the role of this metadata file is embodied in three aspects:
1. Maintain the consistency of persistence classes
2, overloading the default persistence behavior
3. Additional information that provides a persistent class itself for JDO itself is unable to provide.
The JDO metadata file is a file in XML format. The root element of this file must be a JDO, and he has a unique child element package element, and the package element represents the package where the persistence class is located. He has a Name property, the value of this attribute, the full name of the Package. Below I give an example of the most basic JDO metadata:
XML Version = "1.0"?>
..............
package>
..............
package>
jdo>
The package element can contain 1-N Class elements, and there are 0-N extended elements that typically provide information on specific JDO vendors. The extended element is generally an extension element, he has 3 properties:
Vender-name: The name of the vendor must have attributes.
Key: The name of the extension attribute, each JDO implementation vendor provides a range of attribute names.
Value: Value of extended attributes
The description of each class in Package uses the Class element, the CALSS element requires a Name property to describe his name, and the Name property is generally followed by the following Price principles:
l If this CLSS element is included in the package element, his name can write directly to the class name, no need to include the package name, such as com.lgd.test.helloWorld this class his name directly writes HellpWorld.
l The same for java.lang, java.util, and java.math can also write his class name directly.
l In addition to the above case, the NAME of the class must be a complete name, and the specific package path is included.
l If the described class is an internal class, his writing is like this, Parent-Calss $ Inner-Class. For example: human $ man.
Let's take a look at the properties of Class:
l Name: The name of the class, the necessary properties.
l Persistence-Capable-Suppover: If the superclass of this class is also a sustainable class, and you want JDO to understand their direct inheritance relationship, you will be specified here.
l Identity-Type: It specifies the consistency type of the persistence class. If you define ObjectID-Class, this property is default to Application Otherwise, Datastore is DataStore.
l ObjectID-Class: For the application JDO consistent persistence class to specify his JDO consistency class, this class is located at the bottom of the inherited tree.
l Requires-extent: If you don't query data from this class, you can set it to false. By default, it is True. The example is given below: An example of the Class element:
XML Version = "1.0"?>
...
clas>
...
clas>
...
clas>
...
clas>
package>
jdo>
The Class element also contains Extension and Field sub-elements. Let's take a look at the field element. It is used to describe the fields in the persistence class. This field is an optional field if you don't describe the Field field in the metadata file, JDO will use the default description of each field, so it will save us a lot of work. Let's take a look at the Filed elements.
l Name: The name of the field is consistent with the field name you in the persistence class.
l Persistence-modifier: Defines how JDO operates this field if it is a sustainable field value: Persistent. If it is a non-persistent field but can be rolled out, the value is Transactional. If it is not, then the value is none. The default of these fields should be determined according to the type of field:
m If the field is declared as Fianl, Transient or Static then his default is: None.
m If the field type is the original type or the original type of package type, then his default is: Pesistent
m If the field type is java.util.date, java.util.locale, java.lang.string, java.lang.number, java.math.bigDecimail or java.math.biginteger is then: Persistent
m If the field type is the user-defined sustainable type, the default is: Persistent
m The array of fields that we have said before: Persistent
M field type If it is the following type in java.util package default to Persistent .: Collection, Set, List, Map, Arraylist, Hashmap, Hashset, Hashtable, LinkedList, Treemap, Treeset, Vector
m other types of defaults NONE
l Primary-key: If this field is the primary key field, set it to true, default to false.
l None-value: The default setting is set to the None representative to set an empty value into the database.
l Default-fetch-group: Original Type and Original Package Type The default is TRUE other types to false.
l Embedded: Original Type and Original Packaging Type The default is TRUE other types to false. All elements may have an extension extended element, an array element and a collection element there is an Embedded-Element property that defines the type of internal elements of the elements or arguments.
l Key-type: Objects used for mapping, default is java.lang.Object
l Embedded-key: embedded key
l value-type: key value
l Embedded-value: built-in key value
Here is an example of containing all metadata file elements:
XML Version = "1.0"?>
field>
clas>
field>
clas>
clas>
package>
field>
clas>
package>
jdo>
JDO file location:
The JDO metadata file is a resource file, which is used in class enhancements and runtime. If this metadata is a description of a class, then his name is the name of the class, which is placed in the same directory with the class file. . If the JDO metadata file contains a description of all classes below the packet, it is placed in the path where the corresponding package is located, or the description of all classes in the entire package level, such as: metadata description for Human.class The file can be human.jdo or contain it in a package.jdo, then the location of this file can be: com / lgd / test / human.jdo
COM / LGD / PACKAGE.JDO
Com / package.jdo
Package.jdo
Since the JDO metadata file is a resource file, it can also be placed in the .jar file.
End
The above is the introduction of JDO metadata. These content are in line with the JDO1.0 specification. Since different JDO implementations have corresponding expansions for JDO metadata or other support (such as Kodo JDO requires extra maping Corresponding to files) So the specific implementation is a document that can be included with reference to the vendor.