olingo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From build...@apache.org
Subject svn commit: r914530 - in /websites/staging/olingo/trunk/content: ./ doc/tutorials/DeltaQuerySupport.html
Date Tue, 01 Jul 2014 05:44:05 GMT
Author: buildbot
Date: Tue Jul  1 05:44:05 2014
New Revision: 914530

Log:
Staging update by buildbot for olingo

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

Propchange: websites/staging/olingo/trunk/content/
------------------------------------------------------------------------------
--- cms:source-revision (original)
+++ cms:source-revision Tue Jul  1 05:44:05 2014
@@ -1 +1 @@
-1599444
+1606981

Added: websites/staging/olingo/trunk/content/doc/tutorials/DeltaQuerySupport.html
==============================================================================
--- websites/staging/olingo/trunk/content/doc/tutorials/DeltaQuerySupport.html (added)
+++ websites/staging/olingo/trunk/content/doc/tutorials/DeltaQuerySupport.html Tue Jul  1
05:44:05 2014
@@ -0,0 +1,190 @@
+<!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="expires" content="0">
+            <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> 
+                <title></title>
+                <meta name="description" content="Apache Olingo 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="/js/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>
+                    <img class="brand" src="/img/OlingoOrangeTM.png" style="width:42px;"
/>
+                    <a class="brand" href="/">Apache Olingo&trade;</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><a href="/">Home</a></li>
+                            <li><a href="http://www.apache.org/licenses/">License</a></li>

+                            <li><a href="/download.html">Download</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.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="delta-query-support">Delta Query Support</h1>
+<p>Delta Query retrieves the changes done to a service. It is supported in OData JPA
Processor Library from version 1.4.0. The data returned by the feed for the query would look
exactly like any other dataset for an OData query but with delta link at the end. </p>
+<p>There are two approaches you can follow to generate delta token.</p>
+<h2 id="generating-delta-token">Generating Delta Token</h2>
+<h5 id="first-approach">First Approach</h5>
+<ol>
+<li>Create a Java class by extending 'ODataJPATombstoneEntityListener.java'.</li>
+<li>
+<p>Implement the abstract method 'getQuery'. In the method, implement the logic to
generate a 'javax.persistence.Query'. The Query object can be created as shown below in the
code snippet. </p>
+<div class="codehilite"><pre> <span class="k">if</span> <span
class="p">(</span>!<span class="n">resultsView</span><span class="p">.</span><span
class="n">getStartEntitySet</span><span class="p">().</span><span
class="n">getName</span><span class="p">().</span><span class="n">equals</span><span
class="p">(</span><span class="n">resultsView</span><span class="p">.</span><span
class="n">getTargetEntitySet</span><span class="p">().</span><span
class="n">getName</span><span class="p">()))</span> <span class="p">{</span>
   
+   <span class="n">contextType</span> <span class="p">=</span> <span
class="n">JPQLContextType</span><span class="p">.</span><span class="n">JOIN</span><span
class="p">;</span>
+ <span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
   
+   <span class="n">contextType</span> <span class="p">=</span> <span
class="n">JPQLContextType</span><span class="p">.</span><span class="n">SELECT</span><span
class="p">;</span>  
+ <span class="p">}</span>
+
+ <span class="n">JPQLContext</span> <span class="n">jpqlContext</span>
<span class="p">=</span> <span class="n">JPQLContext</span><span
class="p">.</span><span class="n">createBuilder</span><span class="p">(</span><span
class="n">contextType</span><span class="p">,</span> <span class="n">resultsView</span><span
class="p">).</span><span class="n">build</span><span class="p">();</span>
 
+ <span class="n">JPQLStatement</span> <span class="n">jpqlStatement</span>
<span class="p">=</span> <span class="n">JPQLStatement</span><span
class="p">.</span><span class="n">createBuilder</span><span class="p">(</span><span
class="n">jpqlContext</span><span class="p">).</span><span class="n">build</span><span
class="p">();</span>
+
+ <span class="n">Query</span> <span class="n">query</span> <span
class="p">=</span> <span class="n">em</span><span class="p">.</span><span
class="n">createQuery</span><span class="p">(</span><span class="n">jpqlStatement</span><span
class="p">);</span>
+</pre></div>
+
+
+</li>
+</ol>
+<p>The JPQLStatement is generated based on the OData request (resultsView). The generated
JPQLStatement can be enhanced to introduce conditions that filters and fetches delta JPA Entities.
To enhance the JPQLStatement and add a condition to the WHERE Clause, refer to the following
code snippet.</p>
+<p><em>Note</em>: It is up to the JPA application developers to come up
with a logic suitable for their use case.</p>
+<div class="codehilite"><pre>    <span class="n">String</span> <span
class="n">deltaToken</span> <span class="p">=</span> <span class="n">ODataJPATombstoneContext</span><span
class="p">.</span><span class="n">getDeltaToken</span><span class="p">();</span>
+
+    <span class="n">Query</span> <span class="n">query</span> <span
class="p">=</span> <span class="n">null</span><span class="p">;</span>
+    <span class="k">if</span> <span class="p">(</span><span class="n">deltaToken</span>
!<span class="p">=</span> <span class="n">null</span><span class="p">)</span>
<span class="p">{</span>  
+      <span class="n">String</span> <span class="n">statement</span>
<span class="p">=</span> <span class="n">jpqlStatement</span><span
class="p">.</span><span class="n">toString</span><span class="p">();</span>
 
+      <span class="n">String</span><span class="p">[]</span> <span
class="n">statementParts</span> <span class="p">=</span> <span class="n">statement</span><span
class="p">.</span><span class="n">split</span><span class="p">(</span><span
class="n">JPQLStatement</span><span class="p">.</span><span class="n">KEYWORD</span><span
class="p">.</span><span class="n">WHERE</span><span class="p">);</span>
 
+      <span class="n">String</span> <span class="n">deltaCondition</span>
<span class="p">=</span> <span class="n">jpqlContext</span><span
class="p">.</span><span class="n">getJPAEntityAlias</span><span class="p">()</span>
<span class="o">+</span> &quot;<span class="p">.</span><span
class="n">creationDate</span> <span class="o">&gt;</span><span
class="p">=</span> <span class="p">{</span><span class="n">ts</span>
<span class="s">&#39;&quot; + deltaToken + &quot;&#39;</span><span
class="p">}</span>&quot;<span class="p">;</span>  
+      <span class="k">if</span> <span class="p">(</span><span
class="n">statementParts</span><span class="p">.</span><span class="nb">length</span>
<span class="o">&gt;</span> 1<span class="p">)</span>  
+      <span class="p">{</span>    
+      <span class="n">statement</span> <span class="p">=</span> <span
class="n">statementParts</span><span class="p">[</span>0<span class="p">]</span>
<span class="o">+</span> <span class="n">JPQLStatement</span><span
class="p">.</span><span class="n">DELIMITER</span><span class="p">.</span><span
class="n">SPACE</span> <span class="o">+</span> <span class="n">JPQLStatement</span><span
class="p">.</span><span class="n">KEYWORD</span><span class="p">.</span><span
class="n">WHERE</span> <span class="o">+</span> <span class="n">JPQLStatement</span><span
class="p">.</span><span class="n">DELIMITER</span><span class="p">.</span><span
class="n">SPACE</span> <span class="o">+</span> <span class="n">deltaCondition</span>
<span class="o">+</span> <span class="n">JPQLStatement</span><span
class="p">.</span><span class="n">DELIMITER</span><span class="p">.</span><span
class="n">SPACE</span> <span class="o">+</span> <span class="n">JPQLStatement</span><span
class="p">.</span><span class="n">Oper
 ator</span><span class="p">.</span><span class="n">AND</span>
<span class="o">+</span> <span class="n">statementParts</span><span
class="p">[</span>1<span class="p">];</span>  
+      <span class="p">}</span>  
+      <span class="k">else</span> <span class="p">{</span>    
+        <span class="n">statement</span> <span class="p">=</span>
<span class="n">statementParts</span><span class="p">[</span>0<span
class="p">]</span> <span class="o">+</span> <span class="n">JPQLStatement</span><span
class="p">.</span><span class="n">DELIMITER</span><span class="p">.</span><span
class="n">SPACE</span> <span class="o">+</span> <span class="n">JPQLStatement</span><span
class="p">.</span><span class="n">KEYWORD</span><span class="p">.</span><span
class="n">WHERE</span> <span class="o">+</span> <span class="n">JPQLStatement</span><span
class="p">.</span><span class="n">DELIMITER</span><span class="p">.</span><span
class="n">SPACE</span> <span class="o">+</span> <span class="n">deltaCondition</span><span
class="p">;</span>  
+      <span class="p">}</span>
+
+      <span class="n">query</span> <span class="p">=</span> <span
class="n">em</span><span class="p">.</span><span class="n">createQuery</span><span
class="p">(</span><span class="n">statement</span><span class="p">);</span>
+     <span class="p">}</span>
+     <span class="k">else</span>  
+       <span class="n">query</span> <span class="p">=</span> <span
class="n">em</span><span class="p">.</span><span class="n">createQuery</span><span
class="p">(</span><span class="n">jpqlStatement</span><span class="p">.</span><span
class="n">toString</span><span class="p">());</span>
+</pre></div>
+
+
+<ol>
+<li>
+<p>Implement the method 'generateDeltaToken' to generate a string representation of
the delta token. The delta token generated shall be used by the client applications to fetch
delta in their subsequent OData requests.</p>
+<div class="codehilite"><pre>    <span class="n">SimpleDateFormat</span>
<span class="n">dateFormat</span> <span class="p">=</span> <span
class="n">new</span> <span class="n">SimpleDateFormat</span><span
class="p">(</span>&quot;<span class="n">yyyy</span><span class="o">-</span><span
class="n">MM</span><span class="o">-</span><span class="n">dd</span>
<span class="n">HH</span><span class="p">:</span><span class="n">mm</span><span
class="p">:</span><span class="n">ss</span><span class="p">.</span>000&quot;<span
class="p">);;</span>    
+    <span class="n">Date</span> <span class="n">date</span> <span
class="p">=</span> <span class="n">new</span> <span class="n">Date</span><span
class="p">(</span><span class="n">System</span><span class="p">.</span><span
class="n">currentTimeMillis</span><span class="p">());</span>    
+    <span class="n">dateFormat</span><span class="p">.</span><span
class="n">format</span><span class="p">(</span><span class="n">date</span><span
class="p">);</span>    
+    <span class="k">return</span> <span class="n">dateFormat</span><span
class="p">.</span><span class="n">format</span><span class="p">(</span><span
class="n">date</span><span class="p">);</span>
+</pre></div>
+
+
+<ol>
+<li>
+<p>Register the class (created above) as an Entity Listener in JPA Entity.</p>
+<p>@Entity
+@Table(name = "T_SALESORDERHEADER")
+@EntityListeners(com.sap.core.odata.processor.ref.jpa.listners.SalesOrderTombstoneListner.class)
+public class SalesOrderHeader { </p>
+</li>
+</ol>
+</li>
+</ol>
+<h5 id="second-approach">Second Approach</h5>
+<p>The OData JPA Processor Library also provides support so that the JPA application
developer can write a call back method in the Entity Listener class and annotate them with
'javax.persistence.PostLoad'. Such call back methods are executed by JPA providers in a stateless
manner for every record fetched from the database table. In the call back method, logic can
be provided to decide whether a JPA entity fetched from the database table is a delta or not
as shown below:</p>
+<div class="codehilite"><pre>    <span class="p">@</span><span
class="n">PostLoad</span>  
+    <span class="n">public</span> <span class="n">void</span> <span
class="n">handleDelta</span><span class="p">(</span><span class="n">Object</span>
<span class="n">entity</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">entity</span><span class="p">;</span>
   
+      <span class="k">if</span> <span class="p">(</span><span
class="n">so</span><span class="p">.</span><span class="n">getCreationDate</span><span
class="p">().</span><span class="n">getTime</span><span class="p">()</span>
<span class="o">&lt;</span> <span class="n">ODataJPATombstoneContext</span><span
class="p">.</span><span class="n">getDeltaTokenUTCTimeStamp</span><span
class="p">())</span>      
+        <span class="k">return</span><span class="p">;</span>   

+      <span class="k">else</span>      
+        <span class="n">addToDelta</span><span class="p">(</span><span
class="n">entity</span><span class="p">,</span><span class="n">ENTITY_NAME</span><span
class="p">);</span>  
+    <span class="p">}</span>
+</pre></div>
+            
+            
+            
+            
+            <hr>
+            
+            <footer>                 
+                <div align="center"><p>Copyright © 2013-2014, The Apache Software
Foundation<br>
+                Apache Olingo, Olingo, Apache, the Apache feather, and 
+the Apache Olingo project logo are trademarks of the Apache Software 
+Foundation.</p></div>
+        <hr>
+        <div align="center"><small><a href="http://olingo.staging.apache.org/doc/privacy.html">Privacy</a></small></div>
+            </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>
+  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
+  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
+  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
+  })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
+
+  ga('create', 'UA-44963757-1', 'apache.org');
+  ga('send', 'pageview');
+
+</script>    </body>
+</html>



Mime
View raw message