You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by jh...@apache.org on 2013/09/23 08:44:10 UTC

svn commit: r1525511 - /incubator/olingo/site/trunk/content/doc/tutorials/jparedefinemetadata.mdtext

Author: jhuesken
Date: Mon Sep 23 06:44:10 2013
New Revision: 1525511

URL: http://svn.apache.org/r1525511
Log:
CMS commit to olingo by jhuesken

Added:
    incubator/olingo/site/trunk/content/doc/tutorials/jparedefinemetadata.mdtext   (with props)

Added: incubator/olingo/site/trunk/content/doc/tutorials/jparedefinemetadata.mdtext
URL: http://svn.apache.org/viewvc/incubator/olingo/site/trunk/content/doc/tutorials/jparedefinemetadata.mdtext?rev=1525511&view=auto
==============================================================================
--- incubator/olingo/site/trunk/content/doc/tutorials/jparedefinemetadata.mdtext (added)
+++ incubator/olingo/site/trunk/content/doc/tutorials/jparedefinemetadata.mdtext Mon Sep 23 06:44:10 2013
@@ -0,0 +1,231 @@
+Title:
+Notice:    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.
+
+## Redefining Metadata
+The OData services created from JPA models using OData JPA Processor Library derives the names for its elements from Java Persistence Entity elements. These derived (default) names can be redefined using JPA EDM mapping models. JPA EDM Mapping model can be used to redefine:
+* Schema Namespace Name
+* Entity Type Names
+* Entity Set Names	
+* Property Names
+* Navigation Property Names
+* Complex Type Names
+
+The OData JPA Processor Library applies certain naming rules to derive the names for the above OData elements by default. Here are the rules:
+
+1. Schema Namespace Name is derived from Java Persistence Unit Name.
+2. Entity Type Names are derived from Java Persistence Entity Type Names.
+3. Entity Set Names are derived from EDM Entity Type Names suffixed with character "s".
+4. Property Names are derived from Java Persistence Entity Attribute Names. The initial character in the property name is converted to an upper-case character.
+5. Navigation Property Names are derived from Java Persistence attribute name representing relationships. The navigation property name is suffixed with the word "Details".
+6. Complex Type Names are derived from Java Persistence Embeddable type names.
+
+*Note*: The names generated by applying the above rules can be overridden using JPA EDM Mapping models. JPA EDM mapping model can be maintained as an XML document according to the schema.
+
+### Steps to Redefine the Metadata
+
+1. Create a JPA EDM Mapping model XML according to the schema given below. In the XML, maintain the mapping only for those elements that needs to be redefined. For example, if JPA Entity Type A's name has to be redefined, then maintain an EDM name for the same.
+
+###### Schema
+
+		<?xml version="1.0" encoding="UTF-8"?>
+		<!--
+ 		  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 ANYKIND, either express or implied.  See the License for the specific language governing permissions and limitations under the License.
+		-->
+		<xs:schema attributeFormDefault="unqualified"
+	        elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema"
+			targetNamespace="http://www.apache.org/olingo/odata2/processor/api/jpa/model/mapping"
+			xmlns:tns="http://www.apache.org/olingo/odata2/processor/api/jpa/model/mapping">
+
+		  	<xs:element name="JPAEDMMappingModel">
+				<xs:annotation>
+					<xs:documentation xml:lang="en">
+						Java Persistence (JPA) -
+						Entity Data Model (EDM) Mapping schema. The schema defines a mapping model to describe EDM names for entity types, entity sets, entity properties, entity navigation properties. By default the names of Java Persistence entity types, entity attributes and entity relationships are transformed into their corresponding EDM names. To override the default names the mapping model is defined. Note:- Define the mapping model for only those default names that needs to be overridden.
+			        </xs:documentation>
+		        </xs:annotation>
+		        <xs:complexType>
+			        <xs:sequence>
+				        <xs:element name="PersistenceUnit" type="tns:JPAPersistenceUnitMapType"
+					        maxOccurs="1" minOccurs="1" />
+			        </xs:sequence>
+		        </xs:complexType>
+	        </xs:element>
+
+	        <xs:complexType name="JPAAttributeMapType">
+		        <xs:annotation>
+			        <xs:documentation xml:lang="en">
+				        The default name for EDM property is derived from JPA attribute name. This can be overridden using JPAAttributeMapType.
+			        </xs:documentation>
+		    	</xs:annotation>
+		        <xs:sequence>
+			        <xs:element name="JPAAttribute" maxOccurs="unbounded" 
+					    minOccurs="0">
+				        <xs:complexType>
+					        <xs:simpleContent>
+						        <xs:extension base="xs:string">
+							        <xs:attribute type="xs:string" name="name" use="required" />
+							        <xs:attribute type="xs:boolean" name="exclude" use="optional"
+								        default="false" />
+						        </xs:extension>
+							</xs:simpleContent>
+				        </xs:complexType>
+		            </xs:element>
+		        </xs:sequence>
+		    </xs:complexType>
+
+		    <xs:complexType name="JPARelationshipMapType">
+		        <xs:annotation>
+			        <xs:documentation xml:lang="en">
+				        The default name for EDM navigation property is derived from JPA relationship name. This can be overridden using JPARelationshipMapType.
+			        </xs:documentation>
+		        </xs:annotation>
+		        <xs:sequence>
+			        <xs:element name="JPARelationship" maxOccurs="unbounded" 
+					    minOccurs="0">
+				        <xs:complexType>
+					        <xs:simpleContent>
+						        <xs:extension base="xs:string">
+							        <xs:attribute type="xs:string" name="name" use="required" />
+						        </xs:extension>
+					        </xs:simpleContent>
+				        </xs:complexType>
+			        </xs:element>
+		        </xs:sequence>
+	        </xs:complexType>
+
+	        <xs:complexType name="JPAEntityTypeMapType">
+		        <xs:annotation>
+			        <xs:documentation xml:lang="en">
+				        The default name for EDM entity type is derived from JPA entity type name. This can be overridden using JPAEntityTypeMapType.
+			        </xs:documentation>
+		        </xs:annotation>
+		        <xs:sequence>
+			        <xs:element type="xs:string" name="EDMEntityType"
+				        maxOccurs="1" minOccurs="0" />
+			        <xs:element type="xs:string" name="EDMEntitySet"
+				        maxOccurs="1" minOccurs="0" />
+			        <xs:element name="JPAAttributes"    type="tns:JPAAttributeMapType" />
+			        <xs:element name="JPARelationships" type="tns:JPARelationshipMapType" />
+		        </xs:sequence>
+		        <xs:attribute type="xs:string" name="name" use="required" />
+		        <xs:attribute type="xs:boolean" name="exclude" use="optional" default="false" />
+	     	</xs:complexType>
+
+	        <xs:complexType name="JPAEntityTypesMapType">
+		        <xs:sequence>
+			        <xs:element name="JPAEntityType" type="tns:JPAEntityTypeMapType" 
+					    maxOccurs="unbounded" minOccurs="0" />
+		        </xs:sequence>
+	        </xs:complexType>
+	        <xs:complexType name="JPAEmbeddableTypeMapType">
+		        <xs:annotation>
+			        <xs:documentation xml:lang="en">
+				        The default name for EDM complex type is derived from JPA Embeddable type name. This can be	overridden using JPAEmbeddableTypeMapType.
+			        </xs:documentation>
+		        </xs:annotation>
+		        <xs:sequence>
+			        <xs:element type="xs:string" name="EDMComplexType" 
+					    maxOccurs="1" minOccurs="0" />
+			        <xs:element name="JPAAttributes" type="tns:JPAAttributeMapType" />
+		        </xs:sequence>
+		        <xs:attribute type="xs:string" name="name" use="required" />
+		        <xs:attribute type="xs:boolean" name="exclude" use="optional" 
+				    default="false" />
+	        </xs:complexType>
+
+	        <xs:complexType name="JPAEmbeddableTypesMapType">
+		        <xs:sequence>
+			        <xs:element name="JPAEmbeddableType" type="tns:JPAEmbeddableTypeMapType" 
+					    maxOccurs="unbounded" minOccurs="0" />
+		        </xs:sequence>
+	        </xs:complexType>
+
+	        <xs:complexType name="JPAPersistenceUnitMapType">
+		        <xs:annotation>
+			        <xs:documentation xml:lang="en">
+				        By default Java	Persistence Unit name is taken as EDM schema name. This can be overridden using JPAPersistenceUnitMapType.
+			        </xs:documentation>
+		        </xs:annotation>
+		        <xs:sequence>
+			        <xs:element type="xs:string" name="EDMSchemaNamespace" 
+					    maxOccurs="1" minOccurs="0" />
+			        <xs:element name="JPAEntityTypes" type="tns:JPAEntityTypesMapType" />
+			        <xs:element name="JPAEmbeddableTypes" type="tns:JPAEmbeddableTypesMapType" />
+		        </xs:sequence>
+		        <xs:attribute type="xs:string" name="name" use="required" />
+	        </xs:complexType>
+
+		</xs:schema
+		
+2. Store the JPA EDM Mapping model XML in *webapp* folder of Java web application. Make sure the file is placed under the applications root folder (relative to class path *../../WEB-INF/*classes) when the application is deployed on web server.
+3. Pass the XML name into *ODataJPAContext*. In the method *initializeODataJPAContext*, pass the name of the XML document as shown below:
+
+		oDataJPAContext.setJPAEdmNameMappingModel(<name of xml file>);
+		
+4. Compile, deploy and run the web application in a web server. A sample JPA EDM Mapping Model is provided as an example below:
+
+###### Sample JPA EDM Mapping Model
+
+		  <?xml version="1.0" encoding="UTF-8" ?> 
+		- <JPAEDMMappingModel xmlns="http://www.apache.org/olingo/odata2/processor/api/jpa/model/mapping">
+          - <PersistenceUnit name="salesorderprocessing">
+		      <EDMSchemaNamespace>SalesOrderProcessing</EDMSchemaNamespace> 
+			- <JPAEntityTypes>
+		      - <JPAEntityType name="SalesOrderHeader">
+		          <EDMEntityType>SalesOrder</EDMEntityType> 
+		          <EDMEntitySet>SalesOrders</EDMEntitySet> 
+		        - <JPAAttributes>
+		            <JPAAttribute name="soId">ID</JPAAttribute> 
+		            <JPAAttribute name="netAmount">NetAmount</JPAAttribute> 
+		            <JPAAttribute name="buyerAddress">BuyerAddressInfo</JPAAttribute> 
+		          </JPAAttributes>
+		        - <JPARelationships>
+		            <JPARelationship name="salesOrderItem">SalesOrderLineItemDetails</JPARelationship> 
+		            <JPARelationship name="notes">NotesDetails</JPARelationship> 
+		          </JPARelationships>
+		        </JPAEntityType>
+		      - <JPAEntityType name="SalesOrderItem">
+		          <EDMEntityType>SalesOrderLineItem</EDMEntityType> 
+		          <EDMEntitySet>SalesOrderLineItems</EDMEntitySet> 
+		        - <JPAAttributes>
+		            <JPAAttribute name="liId">ID</JPAAttribute> 
+		            <JPAAttribute name="soId">SalesOrderID</JPAAttribute> 
+		          </JPAAttributes>
+		        - <JPARelationships>
+		            <JPARelationship name="salesOrderHeader">SalesOrderHeaderDetails</JPARelationship> 
+		            <JPARelationship name="materials">MaterialDetails</JPARelationship> 
+		          </JPARelationships>
+		        </JPAEntityType>
+		      </JPAEntityTypes>
+		    - <JPAEmbeddableTypes>
+		      - <JPAEmbeddableType name="Address">
+		          <EDMComplexType>AddressInfo</EDMComplexType> 
+		        - <JPAAttributes>
+		            <JPAAttribute name="houseNumber">Number</JPAAttribute> 
+		            <JPAAttribute name="streetName">Street</JPAAttribute> 
+		          </JPAAttributes>
+		        </JPAEmbeddableType>
+		      </JPAEmbeddableTypes>
+		    </PersistenceUnit>
+		  </JPAEDMMappingModel>
+
+		 
\ No newline at end of file

Propchange: incubator/olingo/site/trunk/content/doc/tutorials/jparedefinemetadata.mdtext
------------------------------------------------------------------------------
    svn:eol-style = native