openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] OpenJPA > JEST Representation
Date Mon, 01 Nov 2010 09:38:00 GMT
<html>
<head>
    <base href="https://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/1810/9/5/_/styles/combined.css?spaceKey=openjpa&amp;forWysiwyg=true"
type="text/css">
    </head>
<body style="background: white;" bgcolor="white" class="email-body">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
    <h2><a href="https://cwiki.apache.org/confluence/display/openjpa/JEST+Representation">JEST
Representation</a></h2>
    <h4>Page  <b>added</b> by             <a href="https://cwiki.apache.org/confluence/display/~ppoddar@apache.org">Pinaki
Poddar</a>
    </h4>
         <br/>
    <div class="notificationGreySide">
         <p>The content of a JEST response can be XML or JSON.</p>

<p>String-based representation of persistent Java object graphs in either XML or more
succinct JSON form has to address the critical issue of circular reference. Because a query
can result<br/>
in to an object graph that contains cycles. JSON, at this point of writing, does not address
circular reference. Hence JEST introduces special semantics within JSON format to refer to
<br/>
instances in a serialized graph.</p>

<h2><a name="JESTRepresentation-XMLRepresentation"></a>XML Representation</h2>

<p>JEST represents persistent Java object graph in a schema-compliant XML.</p>

<h3><a name="JESTRepresentation-Exampleofaserializedobjectgraph"></a>Example
of a serialized object graph</h3>
<p>The example shows a Person (primary key p1) who is her own partner.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
<span class="code-tag">&lt;?xml version=<span class="code-quote">"1.0"</span>
encoding=<span class="code-quote">"UTF-8"</span> standalone=<span class="code-quote">"no"</span>?&gt;</span>
<span class="code-tag">&lt;instances&gt;</span>
  <span class="code-tag">&lt;instance id=<span class="code-quote">"Person-p1"</span>&gt;</span>
    <span class="code-tag">&lt;basic name=<span class="code-quote">"id"</span>
type=<span class="code-quote">"String"</span>&gt;</span>p1<span class="code-tag">&lt;/basic&gt;</span>
    <span class="code-tag">&lt;basic name=<span class="code-quote">"dob"</span>
type=<span class="code-quote">"Date"</span>&gt;</span>Fri Sep 08 00:00:00
CDT 1989<span class="code-tag">&lt;/basic&gt;</span>
    <span class="code-tag">&lt;basic name=<span class="code-quote">"firstName"</span>
type=<span class="code-quote">"String"</span>&gt;</span>Mary<span
class="code-tag">&lt;/basic&gt;</span>
    <span class="code-tag">&lt;basic name=<span class="code-quote">"gender"</span>
type=<span class="code-quote">"Gender"</span>&gt;</span>Female<span
class="code-tag">&lt;/basic&gt;</span>

    <span class="code-tag">&lt;basic name=<span class="code-quote">"lastName"</span>
type=<span class="code-quote">"String"</span>&gt;</span>Smith<span
class="code-tag">&lt;/basic&gt;</span>
    <span class="code-tag">&lt;singular name=<span class="code-quote">"address"</span>
type=<span class="code-quote">"Address"</span>&gt;</span>
      <span class="code-tag">&lt;instance id=<span class="code-quote">"Address-101"</span>&gt;</span>
        <span class="code-tag">&lt;basic name=<span class="code-quote">"id"</span>
type=<span class="code-quote">"long"</span>&gt;</span>101<span class="code-tag">&lt;/basic&gt;</span>
        <span class="code-tag">&lt;basic name=<span class="code-quote">"country"</span>
type=<span class="code-quote">"String"</span>&gt;</span>C1<span class="code-tag">&lt;/basic&gt;</span>
        <span class="code-tag">&lt;basic name=<span class="code-quote">"state"</span>
type=<span class="code-quote">"String"</span>&gt;</span>State1<span
class="code-tag">&lt;/basic&gt;</span>
        <span class="code-tag">&lt;basic name=<span class="code-quote">"street"</span>
type=<span class="code-quote">"String"</span>&gt;</span>Street1<span
class="code-tag">&lt;/basic&gt;</span>

        <span class="code-tag">&lt;basic name=<span class="code-quote">"zip"</span>
type=<span class="code-quote">"int"</span>&gt;</span>10001<span class="code-tag">&lt;/basic&gt;</span>
      <span class="code-tag">&lt;/instance&gt;</span>
    <span class="code-tag">&lt;/singular&gt;</span>
    <span class="code-tag">&lt;singular name=<span class="code-quote">"partner"</span>
type=<span class="code-quote">"Person"</span>&gt;</span>
      <span class="code-tag">&lt;ref id=<span class="code-quote">"Person-p1"</span>/&gt;</span>
    <span class="code-tag">&lt;/singular&gt;</span>
  <span class="code-tag">&lt;/instance&gt;</span>
<span class="code-tag">&lt;/instances&gt;</span>
</pre>
</div></div>


<p>The above XML document is compliant to a XML schema.<br/>
The <tt>jest-instance.xsd</tt>	schema is as follows:</p>

		<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
<span class="code-tag"><span class="code-comment">&lt;!-- =========================================================================
--&gt;</span></span>
<span class="code-tag"><span class="code-comment">&lt;!-- Schema for serialized
persistence instance graph                          --&gt;</span></span>
<span class="code-tag"><span class="code-comment">&lt;!-- =========================================================================
--&gt;</span></span>
&lt;xsd:schema <span class="code-keyword">xmlns:xsd</span>=<span class="code-quote">"http://www.w3.org/2001/XMLSchema"</span>
	attributeFormDefault=<span class="code-quote">"unqualified"</span> elementFormDefault=<span
class="code-quote">"qualified"</span>
	version=<span class="code-quote">"1.0"</span>&gt;

	<span class="code-tag">&lt;xsd:annotation&gt;</span>
		<span class="code-tag">&lt;xsd:documentation&gt;</span>&lt;![CDATA[
         Describes closure of managed persistence instance.
         Each instance is described by all its loaded persistent attribute.
         The related instances are resolved within the document root.
         Document root represents zero or more instances. 
          
         The file must be named <span class="code-quote">"jest-instance.xsd"</span>.
         ]]&gt;
		<span class="code-tag">&lt;/xsd:documentation&gt;</span>
	<span class="code-tag">&lt;/xsd:annotation&gt;</span>

    <span class="code-tag"><span class="code-comment">&lt;!-- The root element
of the document contains zero or more instances --&gt;</span></span>
	<span class="code-tag">&lt;xsd:element name=<span class="code-quote">"instances"</span>&gt;</span>
		<span class="code-tag">&lt;xsd:complexType&gt;</span>
			<span class="code-tag">&lt;xsd:sequence&gt;</span>
				<span class="code-tag">&lt;xsd:element name=<span class="code-quote">"instance"</span>
maxOccurs=<span class="code-quote">"unbounded"</span> type=<span class="code-quote">"instance-type"</span>
/&gt;</span>
			<span class="code-tag">&lt;/xsd:sequence&gt;</span>
			<span class="code-tag">&lt;xsd:attribute name=<span class="code-quote">"version"</span>
type=<span class="code-quote">"xsd:string"</span> /&gt;</span>
		<span class="code-tag">&lt;/xsd:complexType&gt;</span>
	<span class="code-tag">&lt;/xsd:element&gt;</span>

	<span class="code-tag"><span class="code-comment">&lt;!-- The root element
for a single instance --&gt;</span></span>
	<span class="code-tag">&lt;xsd:complexType name=<span class="code-quote">"instance-type"</span>&gt;</span>
		<span class="code-tag">&lt;xsd:sequence&gt;</span>
			<span class="code-tag">&lt;xsd:element name=<span class="code-quote">"basic"</span>
type=<span class="code-quote">"basic-attr-type"</span>  minOccurs=<span class="code-quote">"0"</span>
maxOccurs=<span class="code-quote">"unbounded"</span> /&gt;</span>
			<span class="code-tag">&lt;xsd:element name=<span class="code-quote">"lob"</span>
type=<span class="code-quote">"lob-attr-type"</span>      minOccurs=<span class="code-quote">"0"</span>
maxOccurs=<span class="code-quote">"unbounded"</span>/&gt;</span>
			<span class="code-tag">&lt;xsd:element name=<span class="code-quote">"embedded"</span>
type=<span class="code-quote">"instance-type"</span> minOccurs=<span class="code-quote">"0"</span>
maxOccurs=<span class="code-quote">"unbounded"</span> /&gt;</span>
			<span class="code-tag">&lt;xsd:element name=<span class="code-quote">"singular"</span>
type=<span class="code-quote">"singular-attr-type"</span>  	minOccurs=<span
class="code-quote">"0"</span> maxOccurs=<span class="code-quote">"unbounded"</span>
/&gt;</span>
			<span class="code-tag">&lt;xsd:element name=<span class="code-quote">"collection"</span>
type=<span class="code-quote">"collection-attr-type"</span>	minOccurs=<span
class="code-quote">"0"</span> maxOccurs=<span class="code-quote">"unbounded"</span>
/&gt;</span>
			<span class="code-tag">&lt;xsd:element name=<span class="code-quote">"map"</span>
type=<span class="code-quote">"map-attr-type"</span>                minOccurs=<span
class="code-quote">"0"</span> maxOccurs=<span class="code-quote">"unbounded"</span>
/&gt;</span>
		<span class="code-tag">&lt;/xsd:sequence&gt;</span>
		<span class="code-tag">&lt;xsd:attribute name=<span class="code-quote">"id"</span>
type=<span class="code-quote">"xsd:ID"</span> use=<span class="code-quote">"required"</span>
/&gt;</span>
	<span class="code-tag">&lt;/xsd:complexType&gt;</span>

	<span class="code-tag"><span class="code-comment">&lt;!-- A reference to
another instance within the same(?) document --&gt;</span></span>
	<span class="code-tag">&lt;xsd:complexType name=<span class="code-quote">"ref-type"</span>&gt;</span>
		<span class="code-tag">&lt;xsd:attribute name=<span class="code-quote">"id"</span>
type=<span class="code-quote">"xsd:IDREF"</span> /&gt;</span>
	<span class="code-tag">&lt;/xsd:complexType&gt;</span>
	
	<span class="code-tag"><span class="code-comment">&lt;!-- A null reference
                                           --&gt;</span></span>
	<span class="code-tag">&lt;xsd:complexType name=<span class="code-quote">"ref-null"</span>&gt;</span>
	<span class="code-tag">&lt;/xsd:complexType&gt;</span>

	<span class="code-tag"><span class="code-comment">&lt;!-- Basic Attribute
has a name and its runtime type   --&gt;</span></span>
	<span class="code-tag"><span class="code-comment">&lt;!-- non-null value
appears as text content.           --&gt;</span></span>
	<span class="code-tag"><span class="code-comment">&lt;!-- null value appears
as attribute with empty text . --&gt;</span></span>
	<span class="code-tag">&lt;xsd:complexType name=<span class="code-quote">"basic-attr-type"</span>&gt;</span>
		<span class="code-tag">&lt;xsd:simpleContent&gt;</span>
			<span class="code-tag">&lt;xsd:extension base=<span class="code-quote">"xsd:string"</span>&gt;</span>
				<span class="code-tag">&lt;xsd:attribute name=<span class="code-quote">"name"</span>
type=<span class="code-quote">"xsd:string"</span> use=<span class="code-quote">"required"</span>
/&gt;</span>
				<span class="code-tag">&lt;xsd:attribute name=<span class="code-quote">"type"</span>
type=<span class="code-quote">"xsd:string"</span> use=<span class="code-quote">"required"</span>
/&gt;</span>
				<span class="code-tag">&lt;xsd:attribute name=<span class="code-quote">"null"</span>
type=<span class="code-quote">"xsd:boolean"</span> /&gt;</span>
			<span class="code-tag">&lt;/xsd:extension&gt;</span>
		<span class="code-tag">&lt;/xsd:simpleContent&gt;</span>
	<span class="code-tag">&lt;/xsd:complexType&gt;</span>
	
	<span class="code-tag"><span class="code-comment">&lt;!-- Large Binary Objects
(LOB) represented as hex array --&gt;</span></span>
	<span class="code-tag">&lt;xsd:complexType name=<span class="code-quote">"lob-attr-type"</span>&gt;</span>
		<span class="code-tag">&lt;xsd:simpleContent&gt;</span>
			<span class="code-tag">&lt;xsd:extension base=<span class="code-quote">"xsd:hexBinary"</span>&gt;</span>
				<span class="code-tag">&lt;xsd:attribute name=<span class="code-quote">"name"</span>
type=<span class="code-quote">"xsd:string"</span> use=<span class="code-quote">"required"</span>
/&gt;</span>
				<span class="code-tag">&lt;xsd:attribute name=<span class="code-quote">"type"</span>
type=<span class="code-quote">"xsd:string"</span> use=<span class="code-quote">"required"</span>
/&gt;</span>
				<span class="code-tag">&lt;xsd:attribute name=<span class="code-quote">"null"</span>
type=<span class="code-quote">"xsd:boolean"</span> /&gt;</span>
			<span class="code-tag">&lt;/xsd:extension&gt;</span>
		<span class="code-tag">&lt;/xsd:simpleContent&gt;</span>
	<span class="code-tag">&lt;/xsd:complexType&gt;</span>

	<span class="code-tag"><span class="code-comment">&lt;!-- Singular attribute
can be a reference or another instance. --&gt;</span></span>
	<span class="code-tag">&lt;xsd:complexType name=<span class="code-quote">"singular-attr-type"</span>&gt;</span>
		<span class="code-tag">&lt;xsd:choice&gt;</span>
			<span class="code-tag">&lt;xsd:element name=<span class="code-quote">"null"</span>
type=<span class="code-quote">"ref-null"</span> /&gt;</span>
			<span class="code-tag">&lt;xsd:element name=<span class="code-quote">"ref"</span>
type=<span class="code-quote">"ref-type"</span> /&gt;</span>
			<span class="code-tag">&lt;xsd:element name=<span class="code-quote">"instance"</span>
type=<span class="code-quote">"instance-type"</span> /&gt;</span>
		<span class="code-tag">&lt;/xsd:choice&gt;</span>
		<span class="code-tag">&lt;xsd:attribute name=<span class="code-quote">"name"</span>
type=<span class="code-quote">"xsd:string"</span> use=<span class="code-quote">"required"</span>
/&gt;</span>
		<span class="code-tag">&lt;xsd:attribute name=<span class="code-quote">"type"</span>
type=<span class="code-quote">"xsd:string"</span> use=<span class="code-quote">"required"</span>
/&gt;</span>
	<span class="code-tag">&lt;/xsd:complexType&gt;</span>

	<span class="code-tag"><span class="code-comment">&lt;!-- Collection attributes
list their members with their runtime type --&gt;</span></span>
	<span class="code-tag"><span class="code-comment">&lt;!-- Members can be
basic or other managed instance                   --&gt;</span></span>
	<span class="code-tag">&lt;xsd:complexType name=<span class="code-quote">"collection-attr-type"</span>&gt;</span>
		<span class="code-tag">&lt;xsd:sequence&gt;</span>
			&lt;xsd:element name=<span class="code-quote">"member"</span> type=<span
class="code-quote">"member-type"</span> minOccurs=<span class="code-quote">"0"</span>
				maxOccurs=<span class="code-quote">"unbounded"</span> /&gt;
		<span class="code-tag">&lt;/xsd:sequence&gt;</span>
		<span class="code-tag">&lt;xsd:attribute name=<span class="code-quote">"name"</span>
type=<span class="code-quote">"xsd:string"</span> use=<span class="code-quote">"required"</span>
/&gt;</span>
		<span class="code-tag">&lt;xsd:attribute name=<span class="code-quote">"type"</span>
type=<span class="code-quote">"xsd:string"</span> use=<span class="code-quote">"required"</span>
/&gt;</span>
		<span class="code-tag">&lt;xsd:attribute name=<span class="code-quote">"member-type"</span>
type=<span class="code-quote">"xsd:string"</span> use=<span class="code-quote">"required"</span>
/&gt;</span>
	<span class="code-tag">&lt;/xsd:complexType&gt;</span>

	<span class="code-tag"><span class="code-comment">&lt;!-- Map attributes
list their entries with runtime type of key and value    --&gt;</span></span>
	<span class="code-tag"><span class="code-comment">&lt;!-- Both key and value
can be independently basic or other managed instance --&gt;</span></span>
	<span class="code-tag">&lt;xsd:complexType name=<span class="code-quote">"map-attr-type"</span>&gt;</span>
		<span class="code-tag">&lt;xsd:sequence&gt;</span>
			<span class="code-tag">&lt;xsd:element name=<span class="code-quote">"entry"</span>
type=<span class="code-quote">"entry-type"</span> /&gt;</span>
		<span class="code-tag">&lt;/xsd:sequence&gt;</span>
		<span class="code-tag">&lt;xsd:attribute name=<span class="code-quote">"name"</span>
type=<span class="code-quote">"xsd:string"</span> use=<span class="code-quote">"required"</span>
/&gt;</span>
		<span class="code-tag">&lt;xsd:attribute name=<span class="code-quote">"type"</span>
type=<span class="code-quote">"xsd:string"</span> use=<span class="code-quote">"required"</span>
/&gt;</span>
		<span class="code-tag">&lt;xsd:attribute name=<span class="code-quote">"key-type"</span>
type=<span class="code-quote">"xsd:string"</span> use=<span class="code-quote">"required"</span>
/&gt;</span>
		<span class="code-tag">&lt;xsd:attribute name=<span class="code-quote">"value-type"</span>
type=<span class="code-quote">"xsd:string"</span> use=<span class="code-quote">"required"</span>
/&gt;</span>
	<span class="code-tag">&lt;/xsd:complexType&gt;</span>

	<span class="code-tag"><span class="code-comment">&lt;!-- Value of a member
of basic type. --&gt;</span></span>
	<span class="code-tag">&lt;xsd:complexType name=<span class="code-quote">"basic-value-type"</span>&gt;</span>
		<span class="code-tag">&lt;xsd:simpleContent&gt;</span>
			<span class="code-tag">&lt;xsd:extension base=<span class="code-quote">"xsd:string"</span>&gt;</span>
				<span class="code-tag">&lt;xsd:attribute name=<span class="code-quote">"null"</span>
type=<span class="code-quote">"xsd:boolean"</span> /&gt;</span>
			<span class="code-tag">&lt;/xsd:extension&gt;</span>
		<span class="code-tag">&lt;/xsd:simpleContent&gt;</span>
	<span class="code-tag">&lt;/xsd:complexType&gt;</span>

	<span class="code-tag"><span class="code-comment">&lt;!-- Value of a member
of a collection/map --&gt;</span></span>
	<span class="code-tag">&lt;xsd:complexType name=<span class="code-quote">"member-type"</span>&gt;</span>
		<span class="code-tag">&lt;xsd:choice&gt;</span>
			<span class="code-tag">&lt;xsd:element name=<span class="code-quote">"basic"</span>
type=<span class="code-quote">"basic-value-type"</span> /&gt;</span>
			<span class="code-tag">&lt;xsd:element name=<span class="code-quote">"instance"</span>
type=<span class="code-quote">"instance-type"</span> /&gt;</span>
			<span class="code-tag">&lt;xsd:element name=<span class="code-quote">"null"</span>
type=<span class="code-quote">"ref-null"</span> /&gt;</span>
			<span class="code-tag">&lt;xsd:element name=<span class="code-quote">"ref"</span>
type=<span class="code-quote">"ref-type"</span> /&gt;</span>
		<span class="code-tag">&lt;/xsd:choice&gt;</span>
	<span class="code-tag">&lt;/xsd:complexType&gt;</span>

	<span class="code-tag"><span class="code-comment">&lt;!-- Denotes entry of
a map element --&gt;</span></span>
	<span class="code-tag">&lt;xsd:complexType name=<span class="code-quote">"entry-type"</span>&gt;</span>
		<span class="code-tag">&lt;xsd:sequence&gt;</span>
			<span class="code-tag">&lt;xsd:element name=<span class="code-quote">"key"</span>
  type=<span class="code-quote">"member-type"</span> minOccurs=<span class="code-quote">"1"</span>
maxOccurs=<span class="code-quote">"1"</span> /&gt;</span>
			<span class="code-tag">&lt;xsd:element name=<span class="code-quote">"value"</span>
type=<span class="code-quote">"member-type"</span> minOccurs=<span class="code-quote">"1"</span>
maxOccurs=<span class="code-quote">"1"</span>  /&gt;</span>
		<span class="code-tag">&lt;/xsd:sequence&gt;</span>
	<span class="code-tag">&lt;/xsd:complexType&gt;</span>
	
<span class="code-tag">&lt;/xsd:schema&gt;</span>
</pre>
</div></div>
    </div>
    <div id="commentsSection" class="wiki-content pageSection">
       <div style="float: right;">
            <a href="https://cwiki.apache.org/confluence/users/viewnotifications.action"
class="grey">Change Notification Preferences</a>
       </div>
       <a href="https://cwiki.apache.org/confluence/display/openjpa/JEST+Representation">View
Online</a>
              |
       <a href="https://cwiki.apache.org/confluence/display/openjpa/JEST+Representation?showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
           </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message