olingo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From build...@apache.org
Subject svn commit: r904857 - in /websites/staging/olingo/trunk/content: ./ doc/tutorials/jpafunctionimport.html
Date Fri, 04 Apr 2014 07:37:29 GMT
Author: buildbot
Date: Fri Apr  4 07:37:29 2014
New Revision: 904857

Log:
Staging update by buildbot for olingo

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

Propchange: websites/staging/olingo/trunk/content/
------------------------------------------------------------------------------
--- cms:source-revision (original)
+++ cms:source-revision Fri Apr  4 07:37:29 2014
@@ -1 +1 @@
-1584536
+1584545

Modified: websites/staging/olingo/trunk/content/doc/tutorials/jpafunctionimport.html
==============================================================================
--- websites/staging/olingo/trunk/content/doc/tutorials/jpafunctionimport.html (original)
+++ websites/staging/olingo/trunk/content/doc/tutorials/jpafunctionimport.html Fri Apr  4 07:37:29 2014
@@ -98,131 +98,127 @@
 </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>
-</li>
-</ol>
-<h5 id="sample-code">Sample Code</h5>
-<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>
+<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">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">EdmFacets</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">EdmFunctionImport</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">EdmFunctionImport</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">EdmFunctionImport</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">EdmFunctionImport</span><span class="p">.</span><span class="n">ReturnType</span><span class="p">.</span><span class="n">Type</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">EdmFunctionImportParameter</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="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">EdmFunctionImport</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="p">@</span><span class="n">ReturnType</span><span class="p">(</span>
-        <span class="n">type</span> <span class="p">=</span> <span class="n">Type</span><span class="p">.</span><span class="n">ENTITY</span><span class="p">,</span> <span class="n">isCollection</span> <span class="p">=</span> <span class="n">true</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">EdmFunctionImportParameter</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">EdmFacets</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;</span>
-<span class="s">               + 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">EdmFunctionImport</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="p">@</span><span class="n">ReturnType</span><span class="p">(</span><span class="n">type</span> <span class="p">=</span> <span class="n">Type</span><span class="p">.</span><span class="n">SIMPLE</span><span class="p">,</span> <span class="n">isCollection</span> <span class="p">=</span> <span class="n">false</span><span class="p">),</span>
-        <span class="n">httpMethod</span> <span class="p">=</span> <span class="n">HttpMethod</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">EdmFunctionImportParameter</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">EdmFacets</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">EdmFunctionImportParameter</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">EdmFacets</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">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">EdmFunctionImport</span><span class="p">(</span><span class="n">returnType</span> <span class="p">=</span> <span class="p">@</span><span class="n">ReturnType</span><span class="p">(</span><span class="n">type</span> <span class="p">=</span> <span class="n">Type</span><span class="p">.</span><span class="n">ENTITY</span><span class="p">,</span> <span class="n">isCollection</span> <span class="p">=</span> <span class="n">true</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">EdmFunctionImportParameter</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">EdmFacets</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">EdmFunctionImport</span><span class="p">(</span><span class="n">returnType</span> <span class="p">=</span> <span class="p">@</span><span class="n">ReturnType</span><span class="p">(</span><span class="n">type</span> <span class="p">=</span> <span class="n">Type</span><span class="p">.</span><span class="n">COMPLEX</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">EdmFunctionImportParameter</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">EdmFacets</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">getCustomer</span><span class="p">().</span><span class="n">getAddress</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">EdmFacets</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">EdmFunctionImport</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">EdmFunctionImport</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">EdmFunctionImport</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">EdmFunctionImport</span><span class="p">.</span><span class="n">ReturnType</span><span class="p">.</span><span class="n">Type</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">EdmFunctionImportParameter</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="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">EdmFunctionImport</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="p">@</span><span class="n">ReturnType</span><span class="p">(</span>
+    <span class="n">type</span> <span class="p">=</span> <span class="n">Type</span><span class="p">.</span><span class="n">ENTITY</span><span class="p">,</span> <span class="n">isCollection</span> <span class="p">=</span> <span class="n">true</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">EdmFunctionImportParameter</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">EdmFacets</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;</span>
+<span class="s">           + 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">EdmFunctionImport</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="p">@</span><span class="n">ReturnType</span><span class="p">(</span><span class="n">type</span> <span class="p">=</span> <span class="n">Type</span><span class="p">.</span><span class="n">SIMPLE</span><span class="p">,</span> <span class="n">isCollection</span> <span class="p">=</span> <span class="n">false</span><span class="p">),</span>
+    <span class="n">httpMethod</span> <span class="p">=</span> <span class="n">HttpMethod</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">EdmFunctionImportParameter</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">EdmFacets</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">EdmFunctionImportParameter</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">EdmFacets</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">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">null</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">EdmFunctionImport</span><span class="p">(</span><span class="n">returnType</span> <span class="p">=</span> <span class="p">@</span><span class="n">ReturnType</span><span class="p">(</span><span class="n">type</span> <span class="p">=</span> <span class="n">Type</span><span class="p">.</span><span class="n">COMPLEX</span><span class="p">))</span>
-    <span class="n">public</span> <span class="n">OrderValue</span> <span class="n">orderValue</span><span class="p">(</span>
-        <span class="p">@</span><span class="n">EdmFunctionImportParameter</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">EdmFacets</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="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">OrderValue</span> <span class="n">orderValue</span> <span class="p">=</span> <span class="n">new</span> <span class="n">OrderValue</span><span class="p">();</span>
-    <span class="n">orderValue</span><span class="p">.</span><span class="n">setAmount</span><span class="p">(</span><span class="n">amount</span><span class="p">);</span>
-    <span class="n">orderValue</span><span class="p">.</span><span class="n">setCurrency</span><span class="p">(</span><span class="n">so</span><span class="p">.</span><span class="n">getCurrencyCode</span><span class="p">());</span>
-    <span class="k">return</span> <span class="n">orderValue</span><span class="p">;</span>
-    <span class="p">}</span>
+<span class="p">}</span>
 
+<span class="p">@</span><span class="n">EdmFunctionImport</span><span class="p">(</span><span class="n">returnType</span> <span class="p">=</span> <span class="p">@</span><span class="n">ReturnType</span><span class="p">(</span><span class="n">type</span> <span class="p">=</span> <span class="n">Type</span><span class="p">.</span><span class="n">ENTITY</span><span class="p">,</span> <span class="n">isCollection</span> <span class="p">=</span> <span class="n">true</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">EdmFunctionImportParameter</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">EdmFacets</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">EdmFunctionImport</span><span class="p">(</span><span class="n">returnType</span> <span class="p">=</span> <span class="p">@</span><span class="n">ReturnType</span><span class="p">(</span><span class="n">type</span> <span class="p">=</span> <span class="n">Type</span><span class="p">.</span><span class="n">COMPLEX</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">EdmFunctionImportParameter</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">EdmFacets</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">getCustomer</span><span class="p">().</span><span class="n">getAddress</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="p">@</span><span class="n">EdmFunctionImport</span><span class="p">(</span><span class="n">returnType</span> <span class="p">=</span> <span class="p">@</span><span class="n">ReturnType</span><span class="p">(</span><span class="n">type</span> <span class="p">=</span> <span class="n">Type</span><span class="p">.</span><span class="n">COMPLEX</span><span class="p">))</span>
+<span class="n">public</span> <span class="n">OrderValue</span> <span class="n">orderValue</span><span class="p">(</span>
+    <span class="p">@</span><span class="n">EdmFunctionImportParameter</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">EdmFacets</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="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">OrderValue</span> <span class="n">orderValue</span> <span class="p">=</span> <span class="n">new</span> <span class="n">OrderValue</span><span class="p">();</span>
+<span class="n">orderValue</span><span class="p">.</span><span class="n">setAmount</span><span class="p">(</span><span class="n">amount</span><span class="p">);</span>
+<span class="n">orderValue</span><span class="p">.</span><span class="n">setCurrency</span><span class="p">(</span><span class="n">so</span><span class="p">.</span><span class="n">getCurrencyCode</span><span class="p">());</span>
+<span class="k">return</span> <span class="n">orderValue</span><span class="p">;</span>
+<span class="p">}</span>
 </pre></div>
 
 
-<ol>
+<p>}</p>
+</li>
 <li>
 <p>Create a Java class by implementing the interface <em>org.apache.olingo.odata2.jpa.processor.api.model</em> to register the annotated Java methods.</p>
 <div class="codehilite"><pre><span class="kd">public</span> <span class="kd">class</span> <span class="nc">SalesOrderProcessingExtension</span> <span class="kd">implements</span> <span class="n">JPAEdmExtension</span> <span class="o">{</span>
@@ -255,7 +251,7 @@
 <p>Add non JPA Entity Types as Complex Types to the EDM. See <a href="/doc/tutorials/ExtendingtheEDM.html">Extending the EDM Generated from the JPA Models</a> for more information.</p>
 <p><em>Note</em>: The Simple Name of the Java class used as the return type in a Function Import and the name of the EDM Complex Type should be same.</p>
 <p>Here is an example, you define the operations inside the <code>SalesOrderHeaderProcessor</code> class and then register this class inside <code>JPAEdmExtension</code> class <code>extendWithOperation</code>. </p>
-<h5 id="sample-code_1">Sample Code</h5>
+<h5 id="sample-code">Sample Code</h5>
 <div class="codehilite"><pre>     <span class="p">@</span><span class="n">EdmFunctionImport</span><span class="p">(</span><span class="n">returnType</span> <span class="p">=</span> <span class="p">@</span><span class="n">ReturnType</span><span class="p">(</span><span class="n">type</span> <span class="p">=</span> <span class="n">Type</span><span class="p">.</span><span class="n">COMPLEX</span><span class="p">))</span>
           <span class="n">public</span> <span class="n">OrderValue</span> <span class="n">orderValue</span><span class="p">(</span>
 



Mime
View raw message