You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@openjpa.apache.org by "Pinaki Poddar (JIRA)" <ji...@apache.org> on 2010/10/21 20:34:15 UTC

[jira] Created: (OPENJPA-1851) RESTful access to Persistence Unit runtime

RESTful access to Persistence Unit runtime 
-------------------------------------------

                 Key: OPENJPA-1851
                 URL: https://issues.apache.org/jira/browse/OPENJPA-1851
             Project: OpenJPA
          Issue Type: New Feature
          Components: competitive, jpa, usability
            Reporter: Pinaki Poddar
            Assignee: Pinaki Poddar


A persistence unit should provide access to a remote, non-Java client in a RESTful fashion.

The communication protocol should be HTTP.
The 'safe' operations (HTTP GET for find, query, properties, metamodel browsing etc) can be encoded in URI syntax itself. 
The state representation would start with schema-less  XML, followed by schema-compliant XML and JSON
The POST/PUT operations and transactions will be addressed in a separate task.
 

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (OPENJPA-1851) RESTful access to Persistence Unit runtime

Posted by "Pinaki Poddar (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/OPENJPA-1851?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12924746#action_12924746 ] 

Pinaki Poddar commented on OPENJPA-1851:
----------------------------------------

Proposed URI  Syntax for REST on OpenJPA
---------------------------------------------------------------
  * REST as a interaction paradigm
  * HTTP as communication protocol
  * JPA as a service
  
  A client having no Java, no access to persistent domain class definitions can be enabled to access
  JPA features e.g. querying a database with an object-oriented view and receive a XML or HTML document
  over HTTP. 
  
  This brief note proposes a protocol syntax to carry out such an interaction. 
  
   JEST (JPA-REST) URL Syntax
   --------------------------
   http://host[:port]/action/[option]*[?[param-key=param-value];*]
   
   action : denotes the JPA operation to be performed.
            must be the first path segment of a HTTP URI
            For example one of {find, query, insert, merge, remove, properties, domain}

   option : qualifies the action. 
            specific to the action.
            For example, a query action can qualify with query/single to get a single result.
            zero or more options can be specified. 
            options are separated by forward slash
            options may have value e.g. query/fecthplan=myPlan/ignoreCache/maxResult=20?select p from Person ... 
            options are not order dependent  
            
   param  : parameter for the action
            For example, JPQL string as well the query parameters are params for a query action
            zero or more param can be specified
            params are separated by semicolon
            params may have value     


Few examples
------------------------------------

01. Get name of the persistent unit
            
    http://www.jpa.com:6789/
           
02. List simple name of the domain classes
            
    http://www.jpa.com:6789/domain
   
        
03. List the key-value properties of the persistent unit

    http://www.jpa.com:6789/properties
        
        
        
04. Find an instance by key
 
    http://www.jpa.com:6789/find?Person;123456789
    
    Comment: simple name of the server-side Java types should suffice, unless ambiguous for the persistence unit
    
    
05. Find an instance by key
    
    http://www.jpa.com:6789/find?Person;ssn=123456789;name=Pinaki
    
    Comment: This form is required when compound keys are used

    
06. Get the result of the query with no parameter

    http://www.jpa.com:6789/query?select p from Person p


07. Get the result of the query with single parameter

    http://www.jpa.com:6789/query?select p from Person p where p.name=:name;name=Pinaki


08. Get the result of the query with multiple parameters

    http://www.jpa.com:6789/query?select p from Person p where p.name=:name and age > :age;name=Pinaki;age=20
    http://www.jpa.com:6789/query?select p from Person p where p.first=:first and p.last=:last;first=Pinaki;last=Poddar
    
    Comment: Notice that age is a numeric parameter and needs to be implicitly converted before JPA query is executed.
             Some changes in OpenJPA kernel is needed to handle/relax parameter type checking.
    
09. Get the single result of the query 
     
    http://www.jpa.com:6789/query/single?select p from Person p where p.name=:name;name=Pinaki

    
10. Get the result of the named query     
    
    http://www.jpa.com:6789/query/named?QueryPersonByName;name=Pinaki
    
11. Get the single result of the named query

    http://www.jpa.com:6789/query/single/named?QueryPersonByName;name=Pinaki
    http://www.jpa.com:6789/query/named/single?QueryPersonByName;name=Pinaki
     
   Comment: both forms are equivalent


Host syntax: http://www.jpa.com:6789

A OpenJPA runtime running at www.jpa.com with port 6789 listening for HTTP requests on the above syntax. 








> RESTful access to Persistence Unit runtime 
> -------------------------------------------
>
>                 Key: OPENJPA-1851
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-1851
>             Project: OpenJPA
>          Issue Type: New Feature
>          Components: competitive, jpa, usability
>            Reporter: Pinaki Poddar
>            Assignee: Pinaki Poddar
>
> A persistence unit should provide access to a remote, non-Java client in a RESTful fashion.
> The communication protocol should be HTTP.
> The 'safe' operations (HTTP GET for find, query, properties, metamodel browsing etc) can be encoded in URI syntax itself. 
> The state representation would start with schema-less  XML, followed by schema-compliant XML and JSON
> The POST/PUT operations and transactions will be addressed in a separate task.
>  

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (OPENJPA-1851) RESTful access to Persistence Unit runtime

Posted by "Pinaki Poddar (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/OPENJPA-1851?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12924743#action_12924743 ] 

Pinaki Poddar commented on OPENJPA-1851:
----------------------------------------

The proposed XML schema for Java instances serialized on-the-wire

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor 
	license agreements. See the NOTICE file distributed with this work for additional 
	information regarding copyright ownership. The ASF licenses this file to 
	you under the Apache License, Version 2.0 (the "License"); you may not use 
	this file except in compliance with the License. You may obtain a copy of 
	the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required 
	by applicable law or agreed to in writing, software distributed under the 
	License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS 
	OF ANY KIND, either express or implied. See the License for the specific 
	language governing permissions and limitations under the License. -->
<!-- ========================================================================= -->
<!-- Schema for serialized persistence instance.                                                                                          -->
<!-- ========================================================================= -->
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
	attributeFormDefault="unqualified" elementFormDefault="qualified"
	version="1.0">

	<xsd:annotation>
		<xsd:documentation><![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 "META-INF/jest-instance.xsd".
         ]]>
		</xsd:documentation>
	</xsd:annotation>

    <!-- The root element of the document contains zero or more instances -->
	<xsd:element name="instances">
		<xsd:complexType>
			<xsd:sequence>
				<xsd:element name="instance" maxOccurs="unbounded" type="instance-type" />
			</xsd:sequence>
			<xsd:attribute name="version" type="xsd:string" />
		</xsd:complexType>
	</xsd:element>

	<!-- The root element for a single instance -->
	<xsd:complexType name="instance-type">
		<xsd:sequence>
			<xsd:element name="basic"          type="basic-attr-type"       minOccurs="0" maxOccurs="unbounded" />
			<xsd:element name="lob"               type="lob-attr-type"           minOccurs="0" maxOccurs="unbounded"/>
			<xsd:element name="embedded" type="instance-type"         minOccurs="0" maxOccurs="unbounded" />
			<xsd:element name="singular"      type="singular-attr-type"  	minOccurs="0" maxOccurs="unbounded" />
			<xsd:element name="collection"   type="collection-attr-type"	minOccurs="0" maxOccurs="unbounded" />
			<xsd:element name="map"            type="map-attr-type"          minOccurs="0" maxOccurs="unbounded" />
		</xsd:sequence>
		<xsd:attribute name="id" type="xsd:ID" use="required" />
	</xsd:complexType>

	<!-- A reference to another instance within the same(?) document -->
	<xsd:complexType name="ref-type">
		<xsd:attribute name="id" type="xsd:IDREF" />
	</xsd:complexType>
	
	<!-- A null reference                                            -->
	<xsd:complexType name="ref-null">
	</xsd:complexType>

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

	<!-- Singular attribute can be a reference or another instance. -->
	<xsd:complexType name="singular-attr-type">
		<xsd:choice>
			<xsd:element name="null" type="ref-null" />
			<xsd:element name="ref"  type="ref-type" />
			<xsd:element name="instance" type="instance-type" />
		</xsd:choice>
		<xsd:attribute name="name" type="xsd:string" use="required" />
		<xsd:attribute name="type"    type="xsd:string" use="required" />
	</xsd:complexType>

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

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

	<!-- Value of a member of basic type. -->
	<xsd:complexType name="basic-value-type">
		<xsd:simpleContent>
			<xsd:extension base="xsd:string">
				<xsd:attribute name="null" type="xsd:boolean" />
			</xsd:extension>
		</xsd:simpleContent>
	</xsd:complexType>

	<!-- Value of a member of a collection/map -->
	<xsd:complexType name="member-type">
		<xsd:choice>
			<xsd:element name="basic" type="basic-value-type" />
			<xsd:element name="instance" type="instance-type" />
			<xsd:element name="null" type="ref-null" />
			<xsd:element name="ref" type="ref-type" />
		</xsd:choice>
	</xsd:complexType>

	<!-- Denotes entry of a map element -->
	<xsd:complexType name="entry-type">
		<xsd:sequence>
			<xsd:element name="key"   type="member-type" minOccurs="1" maxOccurs="1" />
			<xsd:element name="value" type="member-type" minOccurs="1" maxOccurs="1"  />
		</xsd:sequence>
	</xsd:complexType>
	
</xsd:schema>

and here is a typical example of a Person with a singular reference to another Person (spouse) and multi-valued relation to Persons (friends)


<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<instances xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0" xsi:noNamespaceSchemaLocation="jest-instance.xsd">
  <instance id="Person-1288026511796">
    <basic name="ssn" type="long">1288026511796</basic>
    <basic name="age" type="int">20</basic>
    <basic name="name" type="String">P1</basic>
    <singular name="spouse" type="Person">
      <instance id="Person-1288026511797">
        <basic name="ssn" type="long">1288026511797</basic>
        <basic name="age" type="int">20</basic>
        <basic name="name" type="String">P2</basic>
        <singular name="spouse" type="Person">
          <ref id="Person-1288026511796"/>
        </singular>
        <collection member-type="Person" name="friends" type="List">
          <member>
            <ref id="Person-1288026511796"/>
          </member>
        </collection>
      </instance>
    </singular>
    <collection member-type="Person" name="friends" type="List">
      <member>
        <ref id="Person-1288026511797"/>
      </member>
      <member>
        <instance id="Person-1288026511798">
          <basic name="ssn" type="long">1288026511798</basic>
          <basic name="age" type="int">20</basic>
          <basic name="name" type="String">P3</basic>
          <singular name="spouse" type="Person">
            <null/>
          </singular>
          <collection member-type="Person" name="friends" type="List">
            <member>
              <ref id="Person-1288026511798"/>
            </member>
          </collection>
        </instance>
      </member>
    </collection>
  </instance>
</instances>

1. The object references are of the format <type>-<ior>
    where <type> is the simple name of the type and ior is a string representation of its primary key (we need a syntax for complex identity)
2. The type names are simple name (if unambiguous in the given persistence unit)

> RESTful access to Persistence Unit runtime 
> -------------------------------------------
>
>                 Key: OPENJPA-1851
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-1851
>             Project: OpenJPA
>          Issue Type: New Feature
>          Components: competitive, jpa, usability
>            Reporter: Pinaki Poddar
>            Assignee: Pinaki Poddar
>
> A persistence unit should provide access to a remote, non-Java client in a RESTful fashion.
> The communication protocol should be HTTP.
> The 'safe' operations (HTTP GET for find, query, properties, metamodel browsing etc) can be encoded in URI syntax itself. 
> The state representation would start with schema-less  XML, followed by schema-compliant XML and JSON
> The POST/PUT operations and transactions will be addressed in a separate task.
>  

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.