JDO extension for the Castor XML code generator
Documentation Author(s): Werner Guttmann
Introduction Prerequisite Sample XML schemas Prerequisite: Sample DDL statements The schema elements <column> element <one-to-one> element <one-to-many> element
Introduction
In this section we illustrate the use of the JDO extensions for the XML code
generator.
Prerequisite
To facilitate the detailed explanations in the following
sections, we now define a few <complexType> definitions
that we want to map against an existing database schema, and the
corresponding SQL statements to create the required tables.
Sample XML schemas
<complexType name="bookType">
<sequence>
<element name="isbn" type="xs:string" />
<element name="pages" type="xs:integer" />
<element name="lector" type="lectorType" />
<element name="authors" type="authorType" maxOccurs="unbounded" />
</sequence>
</complexType>
<complexType name="lectorType">
<sequence>
<element name="siNumber" type="xs:integer" />
<element name="name" type="xs:string" />
</sequence>
</complexType>
<complexType name="authorType">
<sequence>
<element name="siNumber" type="xs:integer" />
<element name="name" type="xs:string" />
</sequence>
</complexType> |
|
Prerequisite: Sample DDL statements
CREATE TABLE author_table (
);
CREATE TABLE lector_table (
);
CREATE TABLE book_table (
); |
|
The schema elements
The following XML artifacts are available to annotate an existing XML schema
with JDO extension-specific information.
<table> element
The <table> element allows you to map an <complexType>
definition to a table within a database, and to specify the
identity (frequently referred to as primary key).
<complexType name="authorType">
<xs:annotation>
<xs:appinfo>
<jdo:table name="author_table">
<jdo:primary-key>
<jdo:key>siNumber</jdo:key>
</jdo:primary-key>
</jdo:table>
</xs:appinfo>
</xs:annotation>
<sequence>
<element name="siNumber" type="xs:integer" />
<element name="name" type="xs:string" />
</sequence>
</complexType> |
|
This maps the <complexType> authorType to
the table author_table, and specifies that the
member siNumber be used as object identity (aka primary
key).
The <table> element is defined as follows:
<xs:element name="table">
<xs:complexType>
<xs:sequence>
<xs:element name="primaryKey" type="jdo:pkType"/>
</xs:sequence>
<xs:attribute name="name" type="xs:string" use="required"/>
<xs:attribute name="accessMode" use="optional" default="shared">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="read-only"/>
<xs:enumeration value="shared"/>
<xs:enumeration value="exclusive"/>
<xs:enumeration value="db-locked"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
<xs:attribute name="detachable" type="xs:boolean" default="false"/>
</xs:complexType>
</xs:element> |
|
<column> element
The <column> element allows you to map a member of content model
of a <complexType> definition to a column within a database.
<complexType name="authorType">
<xs:annotation>
<xs:appinfo>
<jdo:table name="author_table">
<jdo:primary-key>
<jdo:key>siNumber</jdo:key>
</jdo:primary-key>
</jdo:table>
</xs:appinfo>
</xs:annotation>
<sequence>
<element name="siNumber" type="xs:integer" >
<xs:annotation>
<xs:appinfo>
<jdo:column name="sin" type="integer" />
</xs:appinfo>
</xs:annotation>
</element>
<element name="name" type="xs:string" />
</sequence>
</complexType> |
|
This maps the <element> isNUmber to
the column sin, and specifies the database type
to be used for persistence.
The <column> element is defined as follows:
<xs:element name="column">
<xs:complexType>
<xs:complexContent>
<xs:extension base="jdo:readonlyDirtyType">
<xs:attribute name="name" type="xs:string" use="required" />
<xs:attribute name="type" type="xs:string" use="required" />
<xs:attribute name="acceptNull" type="xs:boolean" use="optional"
default="true" />
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:element> |
|
<one-to-one> element
The <one-to-one> element allows you to map a member of content model
of a <complexType> definition to a 1:1 relation to another
<complexType>.
<complexType name="bookType">
<xs:annotation>
<xs:appinfo>
<jdo:table name="book_type_table">
<jdo:primary-key>
<jdo:key>isbn</jdo:key>
</jdo:primary-key>
</jdo:table>
</xs:appinfo>
</xs:annotation>
<sequence>
<element name="isbn" type="xs:string" >
<xs:annotation>
<xs:appinfo>
<jdo:column name="isbn" type="varchar" />
</xs:appinfo>
</xs:annotation>
</element>
<element name="pages" type="xs:integer" >
<xs:annotation>
<xs:appinfo>
<jdo:column name="pages" type="integer" />
</xs:appinfo>
</xs:annotation>
</element>
<element name="lector" type="lectorType" >
<xs:annotation>
<xs:appinfo>
<jdo:one-to-one name="lector_id" />
</xs:appinfo>
</xs:annotation>
</element>
<element name="authors" type="authorType" maxOccurs="unbounded" >
...
</element>
</sequence>
</complexType> |
|
This maps the <element> lector to
1:1 relation to the lectorType <complexType>, and specifies
the (column name of the) foreign key to be used.
The <one-to-one> element is defined as follows:
<xs:element name="one-to-one">
<xs:complexType>
<xs:complexContent>
<xs:extension base="jdo:readonlyDirtyType">
<xs:attribute name="name" type="xs:string"/>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:element> |
|
where the content is described as follows:
<one-to-one> - Definitions
name |
Specifies the name of the column that represents the foreign
key of this relation.
|
|
<one-to-many> element
TBD
|