| <html><head> |
| <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> |
| <title>14. XML Schema Format</title><link rel="stylesheet" href="css/docbook.css" type="text/css"><meta name="generator" content="DocBook XSL Stylesheets V1.72.0"><link rel="start" href="manual.html" title="Apache OpenJPA User's Guide"><link rel="up" href="ref_guide_dbsetup.html" title="Chapter 4. JDBC"><link rel="prev" href="ref_guide_schema_schematool.html" title="13. Schema Tool"><link rel="next" href="ref_guide_pc.html" title="Chapter 5. Persistent Classes"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">14. |
| XML Schema Format |
| </th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ref_guide_schema_schematool.html">Prev</a> </td><th width="60%" align="center">Chapter 4. |
| JDBC |
| </th><td width="20%" align="right"> <a accesskey="n" href="ref_guide_pc.html">Next</a></td></tr></table><hr></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="ref_guide_schema_xml"></a>14. |
| XML Schema Format |
| </h2></div></div></div><a class="indexterm" name="d0e21824"></a><p> |
| The <a href="ref_guide_schema_schematool.html" title="13. Schema Tool">schema tool</a> and |
| <a href="ref_guide_schema_info.html#ref_guide_schema_info_factory" title="12.2. Schema Factory"> schema factories</a> all use |
| the same XML format to represent database schema. The Document Type Definition |
| (DTD) for schema information is presented below, followed by examples of schema |
| definitions in XML. |
| </p><pre class="programlisting"> |
| <!ELEMENT schemas (schema)+> |
| <!ELEMENT schema (table|sequence)+> |
| <!ATTLIST schema name CDATA #IMPLIED> |
| |
| <!ELEMENT sequence EMPTY> |
| <!ATTLIST sequence name CDATA #REQUIRED> |
| <!ATTLIST sequence initial-value CDATA #IMPLIED> |
| <!ATTLIST sequence increment CDATA #IMPLIED> |
| <!ATTLIST sequence allocate CDATA #IMPLIED> |
| |
| <!ELEMENT table (column|index|pk|fk|unique)+> |
| <!ATTLIST table name CDATA #REQUIRED> |
| |
| <!ELEMENT column EMPTY> |
| <!ATTLIST column name CDATA #REQUIRED> |
| <!ATTLIST column type (array | bigint | binary | bit | blob | char | clob |
| | date | decimal | distinct | double | float | integer | java_object |
| | longvarbinary | longvarchar | null | numeric | other | real | ref |
| | smallint | struct | time | timestamp | tinyint | varbinary | varchar) |
| #REQUIRED> |
| <!ATTLIST column not-null (true|false) "false"> |
| <!ATTLIST column auto-assign (true|false) "false"> |
| <!ATTLIST column default CDATA #IMPLIED> |
| <!ATTLIST column size CDATA #IMPLIED> |
| <!ATTLIST column decimal-digits CDATA #IMPLIED> |
| |
| <!-- the type-name attribute can be used when you want OpenJPA to --> |
| <!-- use a particular SQL type declaration when creating the --> |
| <!-- column. It is up to you to ensure that this type is --> |
| <!-- compatible with the JDBC type used in the type attribute. --> |
| <!ATTLIST column type-name CDATA #IMPLIED> |
| |
| <!-- the 'column' attribute of indexes, pks, and fks can be used --> |
| <!-- when the element has only one column (or for foreign keys, --> |
| <!-- only one local column); in these cases the on/join child --> |
| <!-- elements can be omitted --> |
| <!ELEMENT index (on)*> |
| <!ATTLIST index name CDATA #REQUIRED> |
| <!ATTLIST index column CDATA #IMPLIED> |
| <!ATTLIST index unique (true|false) "false"> |
| |
| <!-- the 'logical' attribute of pks should be set to 'true' if --> |
| <!-- the primary key does not actually exist in the database, --> |
| <!-- but the given column should be used as a primary key for --> |
| <!-- O-R purposes --> |
| <!ELEMENT pk (on)*> |
| <!ATTLIST pk name CDATA #IMPLIED> |
| <!ATTLIST pk column CDATA #IMPLIED> |
| <!ATTLIST pk logical (true|false) "false"> |
| |
| <!ELEMENT on EMPTY> |
| <!ATTLIST on column CDATA #REQUIRED> |
| |
| <!-- fks with a delete-action of 'none' are similar to logical --> |
| <!-- pks; they do not actually exist in the database, but --> |
| <!-- represent a logical relation between tables (or their --> |
| <!-- corresponding Java classes) --> |
| <!ELEMENT fk (join)*> |
| <!ATTLIST fk name CDATA #IMPLIED> |
| <!ATTLIST fk deferred (true|false) "false"> |
| <!ATTLIST fk to-table CDATA #REQUIRED> |
| <!ATTLIST fk column CDATA #IMPLIED> |
| <!ATTLIST fk delete-action (cascade|default|exception|none|null) "none"> |
| |
| <!ELEMENT join EMPTY> |
| <!ATTLIST join column CDATA #REQUIRED> |
| <!ATTLIST join to-column CDATA #REQUIRED> |
| <!ATTLIST join value CDATA #IMPLIED> |
| |
| <!-- unique constraint --> |
| <!ELEMENT unique (on)*> |
| <!ATTLIST unique name CDATA #IMPLIED> |
| <!ATTLIST unique column CDATA #IMPLIED> |
| <!ATTLIST unique deferred (true|false) "false"> |
| </pre><div class="example"><a name="ref_guide_schema_xml_basic"></a><p class="title"><b>Example 4.22. |
| Basic Schema |
| </b></p><div class="example-contents"><p> |
| A very basic schema definition. |
| </p><pre class="programlisting"> |
| <schemas> |
| <schema> |
| <sequence name="S_ARTS"/> |
| <table name="ARTICLE"> |
| <column name="TITLE" type="varchar" size="255" not-null="true"/> |
| <column name="AUTHOR_FNAME" type="varchar" size="28"> |
| <column name="AUTHOR_LNAME" type="varchar" size="28"> |
| <column name="CONTENT" type="clob"> |
| </table> |
| <table name="AUTHOR"> |
| <column name="FIRST_NAME" type="varchar" size="28" not-null="true"> |
| <column name="LAST_NAME" type="varchar" size="28" not-null="true"> |
| </table> |
| </schema> |
| </schemas> |
| </pre></div></div><br class="example-break"><div class="example"><a name="ref_guide_schema_xml_full"></a><p class="title"><b>Example 4.23. |
| Full Schema |
| </b></p><div class="example-contents"><p> |
| Expansion of the above schema with primary keys, constraints, and indexes, some |
| of which span multiple columns. |
| </p><pre class="programlisting"> |
| <schemas> |
| <schema> |
| <sequence name="S_ARTS"/> |
| <table name="ARTICLE"> |
| <column name="TITLE" type="varchar" size="255" not-null="true"/> |
| <column name="AUTHOR_FNAME" type="varchar" size="28"> |
| <column name="AUTHOR_LNAME" type="varchar" size="28"> |
| <column name="CONTENT" type="clob"> |
| <pk column="TITLE"/> |
| <fk to-table="AUTHOR" delete-action="exception"> |
| <join column="AUTHOR_FNAME" to-column="FIRST_NAME"/> |
| <join column="AUTHOR_LNAME" to-column="LAST_NAME"/> |
| </fk> |
| <index name="ARTICLE_AUTHOR"> |
| <on column="AUTHOR_FNAME"/> |
| <on column="AUTHOR_LNAME"/> |
| </index> |
| </table> |
| <table name="AUTHOR"> |
| <column name="FIRST_NAME" type="varchar" size="28" not-null="true"> |
| <column name="LAST_NAME" type="varchar" size="28" not-null="true"> |
| <pk> |
| <on column="FIRST_NAME"/> |
| <on column="LAST_NAME"/> |
| </pk> |
| </table> |
| </schema> |
| </schemas> |
| </pre></div></div><br class="example-break"></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ref_guide_schema_schematool.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="ref_guide_dbsetup.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="ref_guide_pc.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">13. |
| Schema Tool |
| </td><td width="20%" align="center"><a accesskey="h" href="manual.html">Home</a></td><td width="40%" align="right" valign="top"> Chapter 5. |
| Persistent Classes |
| </td></tr></table></div></body></html> |