olingo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From build...@apache.org
Subject svn commit: r878622 - in /websites/staging/olingo/trunk/content: ./ doc/tutorials/jpafunctionimport.html
Date Mon, 16 Sep 2013 14:06:55 GMT
Author: buildbot
Date: Mon Sep 16 14:06:55 2013
New Revision: 878622

Log:
Staging update by buildbot for olingo

Added:
    websites/staging/olingo/trunk/content/doc/tutorials/jpafunctionimport.html
Modified:
    websites/staging/olingo/trunk/content/   (props changed)

Propchange: websites/staging/olingo/trunk/content/
------------------------------------------------------------------------------
--- cms:source-revision (original)
+++ cms:source-revision Mon Sep 16 14:06:55 2013
@@ -1 +1 @@
-1523591
+1523655

Added: websites/staging/olingo/trunk/content/doc/tutorials/jpafunctionimport.html
==============================================================================
--- websites/staging/olingo/trunk/content/doc/tutorials/jpafunctionimport.html (added)
+++ websites/staging/olingo/trunk/content/doc/tutorials/jpafunctionimport.html Mon Sep 16
14:06:55 2013
@@ -0,0 +1,244 @@
+<!DOCTYPE html>
+<!--[if lt IE 7]>      <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
+<!--[if IE 7]>         <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
+<!--[if IE 8]>         <html class="no-js lt-ie9"> <![endif]-->
+<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
+    <head>
+        <meta charset="utf-8">
+            <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
+                <title></title>
+                <meta name="description" content="Apache Olingo (incubating) provides
libraries which enable developers to implement OData producers and OData consumers. The available
OData Java library implements OData version 2.0. In future on goal is to provide an OData
4.0 compliant library once the OData standard is published at OASIS. The focus within the
community is currently on the Java technology but it is up to the community to discuss if
other environments find interest.">
+                    <meta name="viewport" content="width=device-width">
+                        
+		<link rel="stylesheet" href="/css/bootstrap.min.css">
+                            <style>
+                                body {
+                                    padding-top: 60px;
+                                    padding-bottom: 40px;
+                                }
+                                </style>
+		<link rel="stylesheet" href="/css/bootstrap-responsive.min.css">
+		<link rel="stylesheet" href="/css/main.css">
+                                    
+		<script src="j/s/vendor/modernizr-2.6.2-respond-1.1.0.min.js"></script>
+                                    </head>
+    <body>
+        <!--[if lt IE 7]>
+         <p class="chromeframe">You are using an <strong>outdated</strong>
browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> or
<a href="http://www.google.com/chromeframe/?redirect=true">activate Google Chrome Frame</a>
to improve your experience.</p>
+         <![endif]-->
+        
+        <!-- This code is taken from http://twitter.github.com/bootstrap/examples/hero.html
-->
+        <div class="navbar navbar-inverse  navbar-fixed-top">
+            <div class="navbar-inner">
+                <div class="container">
+                    <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
+                        <span class="icon-bar"></span>
+                        <span class="icon-bar"></span>
+                        <span class="icon-bar"></span>
+                    </a>
+                    <a class="brand" href="#">Apache Olingo™</a>
+                    <div class="nav-collapse collapse">
+                        <ul class="nav">
+                            <li class="dropdown">
+                                <a href="#" class="dropdown-toggle" data-toggle="dropdown">ASF
<b class="caret"></b></a>
+                                <ul class="dropdown-menu">
+                                    <li><a href="http://www.apache.org/foundation/">ASF
Home</a></li>
+                                    <li><a href="http://projects.apache.org/">Projects</a></li>
+                                    <li><a href="http://people.apache.org/">People</a></li>
+                                    <li><a href="http://www.apache.org/foundation/getinvolved.html">Get
Involved</a></li>
+                                    <li><a href="http://www.apache.org/dyn/closer.cgi">Download</a></li>
+									<li><a href="http://www.apache.org/security/">Security</a></li>
+                                    <li><a href="http://www.apache.org/foundation/sponsorship.html">Support
Apache</a></li>
+                                </ul>
+                            </li>
+                            <li class="active"><a href="/">Home</a></li>
+                            <li><a href="/documentation.html">Documentation</a></li>
+                            <li><a href="/support.html">Support</a></li>
+                        </ul>
+                        <form class="navbar-form pull-right" name="search" id="search"
action="http://www.google.com/search" method="get">
+                            <input value="olingo.incubator.apache.org" name="sitesearch"
type="hidden"/>
+                            <input class="span2" type="text" name="q" id="query">
+                                <input class="btn"type="submit" id="submit" value="Search">
+                                    </form>
+                    </div><!--/.nav-collapse -->
+                </div>
+            </div>
+        </div>
+        
+        <div class="container">
+            
+            
+            
+            <h1 id="adding-function-imports-to-odata-services">Adding Function Imports
to OData Services</h1>
+<p>This section explains how to enable custom operations as function imports. Function
imports are used to perform custom operations on a JPA entity in addition to CRUD operations.
For example, consider a scenario where you would like to check the availability of an item
to promise on the sales order line items. ATP check is a custom operation that can be exposed
as a function import in the schema of OData service.</p>
+<ol>
+<li>
+<p>Create a dependency to EDM Annotation Project. This is required to use the annotations
that are defined in the project.</p>
+<div class="codehilite"><pre><span class="nt">&lt;dependency&gt;</span>
+   <span class="nt">&lt;groupId&gt;</span>org.apache.olingo.odata2<span
class="nt">&lt;/groupId&gt;</span>
+   <span class="nt">&lt;artifactId&gt;</span>org.apache.olingo.odata2.api.annotation<span
class="nt">&lt;/artifactId&gt;</span>
+   <span class="nt">&lt;version&gt;</span>x.x.x<span class="nt">&lt;/version&gt;</span>
+   <span class="nt">&lt;scope&gt;</span>provided<span class="nt">&lt;/scope&gt;</span>
+<span class="nt">&lt;/dependency&gt;</span>
+</pre></div>
+
+
+</li>
+<li>
+<p>Create a Java class and annotate the Java methods implementing custom operations
with Function Import and Parameter Java annotations as shown below. Java methods can be created
in JPA entity types and these methods can be annotated with EDM annotations for function import.</p>
+<div class="codehilite"><pre><span class="n">package</span> <span
class="n">org</span><span class="p">.</span><span class="n">apache</span><span
class="p">.</span><span class="n">olingo</span><span class="p">.</span><span
class="n">odata2</span><span class="p">.</span><span class="n">jpa</span><span
class="p">.</span><span class="n">processor</span><span class="p">.</span><span
class="n">ref</span><span class="p">.</span><span class="n">extension</span><span
class="p">;</span>
+
+<span class="n">import</span> <span class="n">java</span><span
class="p">.</span><span class="n">util</span><span class="p">.</span><span
class="n">List</span><span class="p">;</span>
+
+<span class="n">import</span> <span class="n">javax</span><span
class="p">.</span><span class="n">persistence</span><span class="p">.</span><span
class="n">EntityManager</span><span class="p">;</span>
+<span class="n">import</span> <span class="n">javax</span><span
class="p">.</span><span class="n">persistence</span><span class="p">.</span><span
class="n">Persistence</span><span class="p">;</span>
+<span class="n">import</span> <span class="n">javax</span><span
class="p">.</span><span class="n">persistence</span><span class="p">.</span><span
class="n">Query</span><span class="p">;</span>
+
+<span class="n">import</span> <span class="n">org</span><span
class="p">.</span><span class="n">apache</span><span class="p">.</span><span
class="n">olingo</span><span class="p">.</span><span class="n">odata2</span><span
class="p">.</span><span class="n">api</span><span class="p">.</span><span
class="n">annotation</span><span class="p">.</span><span class="n">edm</span><span
class="p">.</span><span class="n">Facets</span><span class="p">;</span>
+<span class="n">import</span> <span class="n">org</span><span
class="p">.</span><span class="n">apache</span><span class="p">.</span><span
class="n">olingo</span><span class="p">.</span><span class="n">odata2</span><span
class="p">.</span><span class="n">api</span><span class="p">.</span><span
class="n">annotation</span><span class="p">.</span><span class="n">edm</span><span
class="p">.</span><span class="n">FunctionImport</span><span class="p">;</span>
+<span class="n">import</span> <span class="n">org</span><span
class="p">.</span><span class="n">apache</span><span class="p">.</span><span
class="n">olingo</span><span class="p">.</span><span class="n">odata2</span><span
class="p">.</span><span class="n">api</span><span class="p">.</span><span
class="n">annotation</span><span class="p">.</span><span class="n">edm</span><span
class="p">.</span><span class="n">Parameter</span><span class="p">;</span>
+<span class="n">import</span> <span class="n">org</span><span
class="p">.</span><span class="n">apache</span><span class="p">.</span><span
class="n">olingo</span><span class="p">.</span><span class="n">odata2</span><span
class="p">.</span><span class="n">api</span><span class="p">.</span><span
class="n">annotation</span><span class="p">.</span><span class="n">edm</span><span
class="p">.</span><span class="n">Parameter</span><span class="p">.</span><span
class="n">Mode</span><span class="p">;</span>
+<span class="n">import</span> <span class="n">org</span><span
class="p">.</span><span class="n">apache</span><span class="p">.</span><span
class="n">olingo</span><span class="p">.</span><span class="n">odata2</span><span
class="p">.</span><span class="n">api</span><span class="p">.</span><span
class="n">annotation</span><span class="p">.</span><span class="n">edmx</span><span
class="p">.</span><span class="n">HttpMethod</span><span class="p">.</span><span
class="n">Name</span><span class="p">;</span>
+<span class="n">import</span> <span class="n">org</span><span
class="p">.</span><span class="n">apache</span><span class="p">.</span><span
class="n">olingo</span><span class="p">.</span><span class="n">odata2</span><span
class="p">.</span><span class="n">api</span><span class="p">.</span><span
class="n">annotation</span><span class="p">.</span><span class="n">edmx</span><span
class="p">.</span><span class="n">HttpMethod</span><span class="p">;</span>
+<span class="n">import</span> <span class="n">org</span><span
class="p">.</span><span class="n">apache</span><span class="p">.</span><span
class="n">olingo</span><span class="p">.</span><span class="n">odata2</span><span
class="p">.</span><span class="n">api</span><span class="p">.</span><span
class="n">annotation</span><span class="p">.</span><span class="n">edm</span><span
class="p">.</span><span class="n">FunctionImport</span><span class="p">.</span><span
class="n">ReturnType</span><span class="p">;</span>
+<span class="n">import</span> <span class="n">org</span><span
class="p">.</span><span class="n">apache</span><span class="p">.</span><span
class="n">olingo</span><span class="p">.</span><span class="n">odata2</span><span
class="p">.</span><span class="n">api</span><span class="p">.</span><span
class="n">annotation</span><span class="p">.</span><span class="n">edm</span><span
class="p">.</span><span class="n">FunctionImport</span><span class="p">.</span><span
class="n">Multiplicity</span><span class="p">;</span>
+<span class="n">import</span> <span class="n">org</span><span
class="p">.</span><span class="n">apache</span><span class="p">.</span><span
class="n">olingo</span><span class="p">.</span><span class="n">odata2</span><span
class="p">.</span><span class="n">api</span><span class="p">.</span><span
class="n">exception</span><span class="p">.</span><span class="n">ODataException</span><span
class="p">;</span>
+<span class="n">import</span> <span class="n">org</span><span
class="p">.</span><span class="n">apache</span><span class="p">.</span><span
class="n">olingo</span><span class="p">.</span><span class="n">odata2</span><span
class="p">.</span><span class="n">jpa</span><span class="p">.</span><span
class="n">processor</span><span class="p">.</span><span class="n">ref</span><span
class="p">.</span><span class="n">model</span><span class="p">.</span><span
class="n">Address</span><span class="p">;</span>
+<span class="n">import</span> <span class="n">org</span><span
class="p">.</span><span class="n">apache</span><span class="p">.</span><span
class="n">olingo</span><span class="p">.</span><span class="n">odata2</span><span
class="p">.</span><span class="n">jpa</span><span class="p">.</span><span
class="n">processor</span><span class="p">.</span><span class="n">ref</span><span
class="p">.</span><span class="n">model</span><span class="p">.</span><span
class="n">SalesOrderHeader</span><span class="p">;</span>
+<span class="n">import</span> <span class="n">org</span><span
class="p">.</span><span class="n">apache</span><span class="p">.</span><span
class="n">olingo</span><span class="p">.</span><span class="n">odata2</span><span
class="p">.</span><span class="n">jpa</span><span class="p">.</span><span
class="n">processor</span><span class="p">.</span><span class="n">ref</span><span
class="p">.</span><span class="n">model</span><span class="p">.</span><span
class="n">SalesOrderItem</span><span class="p">;</span>
+
+<span class="n">public</span> <span class="n">class</span> <span
class="n">SalesOrderHeaderProcessor</span> <span class="p">{</span>
+
+  <span class="n">private</span> <span class="n">EntityManager</span>
<span class="n">em</span><span class="p">;</span>
+
+   <span class="n">public</span> <span class="n">SalesOrderHeaderProcessor</span><span
class="p">()</span> 
+    <span class="n">em</span> <span class="p">=</span> <span class="n">Persistence</span><span
class="p">.</span><span class="n">createEntityManagerFactory</span><span
class="p">(</span>&quot;<span class="n">salesorderprocessing</span>&quot;<span
class="p">)</span>
+      <span class="p">.</span><span class="n">createEntityManager</span><span
class="p">();</span>
+  <span class="p">}</span>
+
+  <span class="p">@</span><span class="n">SuppressWarnings</span><span
class="p">(</span>&quot;<span class="n">unchecked</span>&quot;<span
class="p">)</span>
+  <span class="p">@</span><span class="n">FunctionImport</span><span
class="p">(</span><span class="n">name</span> <span class="p">=</span>
&quot;<span class="n">FindAllSalesOrders</span>&quot;<span class="p">,</span>
<span class="n">entitySet</span> <span class="p">=</span> &quot;<span
class="n">SalesOrders</span>&quot;<span class="p">,</span> <span
class="n">returnType</span> <span class="p">=</span> <span class="n">ReturnType</span><span
class="p">.</span><span class="n">ENTITY_TYPE</span><span class="p">,</span>
<span class="n">multiplicity</span> <span class="p">=</span> <span
class="n">Multiplicity</span><span class="p">.</span><span class="n">MANY</span><span
class="p">)</span>
+  <span class="n">public</span> <span class="n">List</span><span
class="o">&lt;</span><span class="n">SalesOrderHeader</span><span
class="o">&gt;</span> <span class="n">findAllSalesOrders</span><span
class="p">(</span>
+    <span class="p">@</span><span class="n">Parameter</span><span
class="p">(</span><span class="n">name</span> <span class="p">=</span>
&quot;<span class="n">DeliveryStatusCode</span>&quot;<span class="p">,</span>
<span class="n">facets</span> <span class="p">=</span> <span class="p">@</span><span
class="n">Facets</span><span class="p">(</span><span class="n">maxLength</span>
<span class="p">=</span> 2<span class="p">))</span> <span class="n">final</span>
<span class="n">String</span> <span class="n">status</span><span
class="p">)</span> <span class="p">{</span>
+
+        <span class="n">Query</span> <span class="n">q</span> <span
class="p">=</span> <span class="n">em</span><span class="p">.</span><span
class="n">createQuery</span><span class="p">(</span>&quot;<span
class="n">SELECT</span> <span class="n">E1</span> <span class="n">from</span>
<span class="n">SalesOrderHeader</span> <span class="n">E1</span>
<span class="n">WHERE</span> <span class="n">E1</span><span class="p">.</span><span
class="n">deliveryStatus</span> <span class="p">=</span> <span class="s">&#39;&quot;+
status + &quot;&#39;</span>&quot;<span class="p">);</span>
+        <span class="n">List</span><span class="o">&lt;</span><span
class="n">SalesOrderHeader</span><span class="o">&gt;</span> <span
class="n">soList</span> <span class="p">=</span> <span class="p">(</span><span
class="n">List</span><span class="o">&lt;</span><span class="n">SalesOrderHeader</span><span
class="o">&gt;</span><span class="p">)</span> <span class="n">q</span><span
class="p">.</span><span class="n">getResultList</span><span class="p">();</span>
+        <span class="k">return</span> <span class="n">soList</span><span
class="p">;</span>
+  <span class="p">}</span>
+
+  <span class="p">@</span><span class="n">FunctionImport</span><span
class="p">(</span><span class="n">name</span> <span class="p">=</span>
&quot;<span class="n">CheckATP</span>&quot;<span class="p">,</span>
<span class="n">returnType</span> <span class="p">=</span> <span
class="n">ReturnType</span><span class="p">.</span><span class="n">SCALAR</span><span
class="p">,</span> <span class="n">multiplicity</span> <span class="p">=</span>
<span class="n">Multiplicity</span><span class="p">.</span><span
class="n">ONE</span><span class="p">,</span> <span class="n">httpMethod</span>
<span class="p">=</span> <span class="p">@</span><span class="n">HttpMethod</span><span
class="p">(</span><span class="n">name</span> <span class="p">=</span>
<span class="n">Name</span><span class="p">.</span><span class="n">GET</span><span
class="p">))</span>
+  <span class="n">public</span> <span class="n">boolean</span> <span
class="n">checkATP</span><span class="p">(</span>
+    <span class="p">@</span><span class="n">Parameter</span><span
class="p">(</span><span class="n">name</span> <span class="p">=</span>
&quot;<span class="n">SoID</span>&quot;<span class="p">,</span>
<span class="n">facets</span> <span class="p">=</span> <span class="p">@</span><span
class="n">Facets</span><span class="p">(</span><span class="n">nullable</span>
<span class="p">=</span> <span class="n">false</span><span class="p">),</span>
<span class="n">mode</span> <span class="p">=</span> <span class="n">Mode</span><span
class="p">.</span><span class="n">IN</span><span class="p">)</span>
<span class="n">final</span> <span class="n">Long</span> <span
class="n">soID</span><span class="p">,</span>
+    <span class="p">@</span><span class="n">Parameter</span><span
class="p">(</span><span class="n">name</span> <span class="p">=</span>
&quot;<span class="n">LiId</span>&quot;<span class="p">,</span>
<span class="n">facets</span> <span class="p">=</span> <span class="p">@</span><span
class="n">Facets</span><span class="p">(</span><span class="n">nullable</span>
<span class="p">=</span> <span class="n">false</span><span class="p">),</span>
<span class="n">mode</span> <span class="p">=</span> <span class="n">Mode</span><span
class="p">.</span><span class="n">IN</span><span class="p">)</span>
<span class="n">final</span> <span class="n">Long</span> <span
class="n">lineItemID</span><span class="p">)</span> <span class="p">{</span>
+    <span class="k">if</span> <span class="p">(</span><span class="n">soID</span>
<span class="o">==</span> 2<span class="n">L</span><span class="p">)</span>
<span class="p">{</span>
+      <span class="k">return</span> <span class="n">false</span><span
class="p">;</span>
+    <span class="p">}</span> <span class="k">else</span> <span
class="p">{</span>
+      <span class="k">return</span> <span class="n">true</span><span
class="p">;</span>
+    <span class="p">}</span>
+  <span class="p">}</span>
+
+  <span class="p">@</span><span class="n">FunctionImport</span><span
class="p">(</span><span class="n">returnType</span> <span class="p">=</span>
<span class="n">ReturnType</span><span class="p">.</span><span
class="n">ENTITY_TYPE</span><span class="p">,</span> <span class="n">entitySet</span>
<span class="p">=</span> &quot;<span class="n">SalesOrders</span>&quot;<span
class="p">)</span>
+  <span class="n">public</span> <span class="n">SalesOrderHeader</span>
<span class="n">calculateNetAmount</span><span class="p">(</span>
+    <span class="p">@</span><span class="n">Parameter</span><span
class="p">(</span><span class="n">name</span> <span class="p">=</span>
&quot;<span class="n">SoID</span>&quot;<span class="p">,</span>
<span class="n">facets</span> <span class="p">=</span> <span class="p">@</span><span
class="n">Facets</span><span class="p">(</span><span class="n">nullable</span>
<span class="p">=</span> <span class="n">false</span><span class="p">))</span>
<span class="n">final</span> <span class="n">Long</span> <span
class="n">soID</span><span class="p">)</span>
+    <span class="n">throws</span> <span class="n">ODataException</span>
<span class="p">{</span>
+
+          <span class="k">if</span> <span class="p">(</span><span
class="n">soID</span> <span class="o">&lt;</span><span class="p">=</span>
0<span class="n">L</span><span class="p">)</span> <span class="p">{</span>
+            <span class="n">throw</span> <span class="n">new</span>
<span class="n">ODataException</span><span class="p">(</span>&quot;<span
class="n">Invalid</span> <span class="n">SoID</span>&quot;<span
class="p">);</span>
+          <span class="p">}</span>
+
+          <span class="n">Query</span> <span class="n">q</span> <span
class="p">=</span> <span class="n">em</span><span class="p">.</span><span
class="n">createQuery</span><span class="p">(</span>&quot;<span
class="n">SELECT</span> <span class="n">E1</span> <span class="n">from</span>
<span class="n">SalesOrderHeader</span> <span class="n">E1</span>
<span class="n">WHERE</span> <span class="n">E1</span><span class="p">.</span><span
class="n">soId</span> <span class="p">=</span> &quot;<span class="o">+</span>
<span class="n">soID</span> <span class="o">+</span> &quot;<span
class="n">l</span>&quot;<span class="p">);</span>
+          <span class="k">if</span> <span class="p">(</span><span
class="n">q</span><span class="p">.</span><span class="n">getResultList</span><span
class="p">().</span><span class="n">isEmpty</span><span class="p">())</span>
<span class="p">{</span>
+            <span class="k">return</span> <span class="n">null</span><span
class="p">;</span>
+          <span class="p">}</span>
+          <span class="n">SalesOrderHeader</span> <span class="n">so</span>
<span class="p">=</span> <span class="p">(</span><span class="n">SalesOrderHeader</span><span
class="p">)</span> <span class="n">q</span><span class="p">.</span><span
class="n">getResultList</span><span class="p">().</span><span class="n">get</span><span
class="p">(</span>0<span class="p">);</span>
+          <span class="n">double</span> <span class="n">amount</span>
<span class="p">=</span> 0<span class="p">;</span>
+          <span class="k">for</span> <span class="p">(</span><span
class="n">SalesOrderItem</span> <span class="n">soi</span> <span class="p">:</span>
<span class="n">so</span><span class="p">.</span><span class="n">getSalesOrderItem</span><span
class="p">())</span> <span class="p">{</span>
+            <span class="n">amount</span> <span class="p">=</span>
<span class="n">amount</span> <span class="o">+</span> <span class="p">(</span><span
class="n">soi</span><span class="p">.</span><span class="n">getAmount</span><span
class="p">()</span> <span class="o">*</span> <span class="n">soi</span><span
class="p">.</span><span class="n">getDiscount</span><span class="p">()</span>
<span class="o">*</span> <span class="n">soi</span><span class="p">.</span><span
class="n">getQuantity</span><span class="p">());</span>
+          <span class="p">}</span>
+          <span class="n">so</span><span class="p">.</span><span
class="n">setNetAmount</span><span class="p">(</span><span class="n">amount</span><span
class="p">);</span>
+          <span class="k">return</span> <span class="n">so</span><span
class="p">;</span>
+      <span class="p">}</span>
+
+  <span class="p">@</span><span class="n">SuppressWarnings</span><span
class="p">(</span>&quot;<span class="n">unchecked</span>&quot;<span
class="p">)</span>
+  <span class="p">@</span><span class="n">FunctionImport</span><span
class="p">(</span><span class="n">returnType</span> <span class="p">=</span>
<span class="n">ReturnType</span><span class="p">.</span><span
class="n">COMPLEX_TYPE</span><span class="p">)</span>
+  <span class="n">public</span> <span class="n">Address</span> <span
class="n">getAddress</span><span class="p">(</span>        
+    <span class="p">@</span><span class="n">Parameter</span><span
class="p">(</span><span class="n">name</span> <span class="p">=</span>
&quot;<span class="n">SoID</span>&quot;<span class="p">,</span>
<span class="n">facets</span> <span class="p">=</span> <span class="p">@</span><span
class="n">Facets</span><span class="p">(</span><span class="n">nullable</span>
<span class="p">=</span> <span class="n">false</span><span class="p">))</span>
<span class="n">final</span> <span class="n">Long</span> <span
class="n">soID</span><span class="p">)</span> <span class="p">{</span>
+    <span class="n">Query</span> <span class="n">q</span> <span
class="p">=</span> <span class="n">em</span><span class="p">.</span><span
class="n">createQuery</span><span class="p">(</span>&quot;<span
class="n">SELECT</span> <span class="n">E1</span> <span class="n">from</span>
<span class="n">SalesOrderHeader</span> <span class="n">E1</span>
<span class="n">WHERE</span> <span class="n">E1</span><span class="p">.</span><span
class="n">soId</span> <span class="p">=</span> &quot; <span class="o">+</span>
<span class="n">soID</span> <span class="o">+</span> &quot;<span
class="n">l</span>&quot;<span class="p">);</span>
+    <span class="n">List</span><span class="o">&lt;</span><span
class="n">SalesOrderHeader</span><span class="o">&gt;</span> <span
class="n">soList</span> <span class="p">=</span> <span class="p">(</span><span
class="n">List</span><span class="o">&lt;</span><span class="n">SalesOrderHeader</span><span
class="o">&gt;</span><span class="p">)</span> <span class="n">q</span><span
class="p">.</span><span class="n">getResultList</span><span class="p">();</span>
+    <span class="k">if</span> <span class="p">(</span>!<span class="n">soList</span><span
class="p">.</span><span class="n">isEmpty</span><span class="p">())</span>
<span class="p">{</span>
+      <span class="k">return</span> <span class="n">soList</span><span
class="p">.</span><span class="n">get</span><span class="p">(</span>0<span
class="p">).</span><span class="n">getBuyerAddress</span><span class="p">();</span>
+    <span class="p">}</span> <span class="k">else</span> <span
class="p">{</span>
+      <span class="k">return</span> <span class="n">null</span><span
class="p">;</span>
+    <span class="p">}</span>
+  <span class="p">}</span>
+
+  <span class="o">/*</span>
+   <span class="o">*</span> <span class="n">This</span> <span
class="n">method</span> <span class="n">will</span> <span class="n">not</span>
<span class="n">be</span> <span class="n">transformed</span> <span
class="n">into</span> <span class="n">Function</span>
+   <span class="o">*</span> <span class="n">Import</span><span
class="p">.</span> <span class="n">Function</span> <span class="n">Import</span>
<span class="n">with</span> <span class="k">return</span> <span
class="n">type</span> <span class="n">as</span> <span class="n">void</span>
<span class="n">is</span> <span class="n">not</span>
+   <span class="o">*</span> <span class="n">supported</span> <span
class="n">yet</span><span class="p">.</span>
+   <span class="o">*/</span>
+  <span class="p">@</span><span class="n">FunctionImport</span><span
class="p">(</span><span class="n">returnType</span> <span class="p">=</span>
<span class="n">ReturnType</span><span class="p">.</span><span
class="n">NONE</span><span class="p">)</span>
+  <span class="n">public</span> <span class="n">void</span> <span
class="n">process</span><span class="p">(</span>
+    <span class="p">@</span><span class="n">Parameter</span><span
class="p">(</span><span class="n">name</span> <span class="p">=</span>
&quot;<span class="n">SoID</span>&quot;<span class="p">,</span>
<span class="n">facets</span> <span class="p">=</span> <span class="p">@</span><span
class="n">Facets</span><span class="p">(</span><span class="n">nullable</span>
<span class="p">=</span> <span class="n">false</span><span class="p">))</span>
<span class="n">final</span> <span class="n">Long</span> <span
class="n">soID</span><span class="p">)</span> <span class="p">{</span>
+    <span class="k">return</span><span class="p">;</span>
+  <span class="p">}</span>
+<span class="p">}</span>
+</pre></div>
+
+
+</li>
+<li>
+<p>Create a Java class by implementing the interface <em>org.apache.olingo.odata2.processor.api.jpa.model</em>
to register the annotated Java methods.</p>
+<div class="codehilite"><pre><span class="n">public</span> <span
class="n">class</span> <span class="n">SalesOrderProcessingExtension</span>
<span class="n">implements</span> <span class="n">JPAEdmExtension</span>
<span class="p">{</span>
+  <span class="p">@</span><span class="n">Override</span>
+  <span class="n">public</span> <span class="n">void</span> <span
class="n">extendJPAEdmSchema</span><span class="p">(</span><span class="n">final</span>
<span class="n">JPAEdmSchemaView</span> <span class="n">arg0</span>
<span class="p">{</span>
+    <span class="o">//</span> <span class="n">TODO</span> <span
class="n">Auto</span><span class="o">-</span><span class="n">generated</span>
<span class="n">method</span> <span class="n">stub</span>
+  <span class="p">}</span>
+
+  <span class="p">@</span><span class="n">Override</span>
+  <span class="n">public</span> <span class="n">void</span> <span
class="n">extendWithOperation</span><span class="p">(</span><span
class="n">final</span> <span class="n">JPAEdmSchemaView</span> <span
class="n">view</span><span class="p">)</span> <span class="p">{</span>
+    <span class="n">view</span><span class="p">.</span><span class="n">registerOperations</span><span
class="p">(</span><span class="n">SalesOrderHeaderProcessor</span><span
class="p">.</span><span class="n">class</span><span class="p">,</span>
<span class="n">null</span><span class="p">);</span>
+  <span class="p">}</span>
+</pre></div>
+
+
+<p>}</p>
+<p><em>Note</em>: Use the method <em>extendWithOperation</em>
to register the list of classes and the methods within the class that needs to be exposed
as Function Imports. If the second parameter is passed null, then the OData JPA Processor
Library would consider all the annotated methods within the class for Function Import. However,
you could also restrict the list of methods that needs to be transformed into function imports
within a Java class by passing an array of Java method names as the second parameter.</p>
+</li>
+<li>
+<p>Register the class created in step 3 with <em>ODataJPAContext</em> as
shown below. The registration can be done during the initialization of <em>ODataJPAContext</em>
in OData JPA Service Factory along with initializing persistence unit name, entity manager
factory instance and optional mapping model.</p>
+<p>oDataJPAContext.setJPAEdmExtension((JPAEdmExtension) new SalesOrderProcessingExtension());</p>
+<p><em>Note</em>: You must register the class because the OData JPA Processor
Library should be informed about the list of Java methods that it needs to process in a project.
If we do not register, then OData JPA Processor Library should scan all the classes and the
methods in the Java project looking for EDM annotations. In order to avoid such overload,
it is mandatory to specify the list of Java methods that shall be transformed into function
imports in a class.</p>
+</li>
+</ol>
+            
+            
+            
+            
+            <hr>
+            
+            <footer>
+                <h5>Disclaimer</h5>
+                
+                <p>Apache Olingo™ is an effort undergoing incubation at The Apache
Software Foundation (ASF) sponsored by the Apache Incubator PMC. Incubation is required of
all newly accepted projects until a further review indicates that the infrastructure, communications,
and decision making process have stabilized in a manner consistent with other successful ASF
projects. While incubation status is not necessarily a reflection of the completeness or stability
of the code, it does indicate that the project has yet to be fully endorsed by the ASF.</p>
+                
+                <p>&copy; Copyright © 2013 The Apache Software Foundation, Licensed
under the Apache License, Version 2.0. Apache and the Apache feather logo are trademarks of
The Apache Software Foundation.</p>
+            </footer>
+            
+        </div> <!-- /container -->
+        
+        <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
+        <script>window.jQuery || document.write('<script src="js/vendor/jquery-1.10.1.min.js"><\/script>')</script>
+        
+        <script src="js/vendor/bootstrap.min.js"></script>
+        
+        <script src="js/main.js"></script>
+        
+        <script>
+            var _gaq=[['_setAccount','UA-XXXXX-X'],['_trackPageview']];
+            (function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];
+             g.src='//www.google-analytics.com/ga.js';
+             s.parentNode.insertBefore(g,s)}(document,'script'));
+            </script>
+    </body>
+</html>



Mime
View raw message