deltaspike-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject svn commit: r902564 - in /websites/staging/deltaspike/trunk/content: ./ data.html
Date Thu, 20 Mar 2014 17:35:47 GMT
Author: buildbot
Date: Thu Mar 20 17:35:47 2014
New Revision: 902564

Staging update by buildbot for deltaspike

    websites/staging/deltaspike/trunk/content/   (props changed)

Propchange: websites/staging/deltaspike/trunk/content/
--- cms:source-revision (original)
+++ cms:source-revision Thu Mar 20 17:35:47 2014
@@ -1 +1 @@

Modified: websites/staging/deltaspike/trunk/content/data.html
--- websites/staging/deltaspike/trunk/content/data.html (original)
+++ websites/staging/deltaspike/trunk/content/data.html Thu Mar 20 17:35:47 2014
@@ -115,6 +115,7 @@
 <li><a href="#any-result">Any Result</a></li>
+<li><a href="#transactions">Transactions</a></li>
 <li><a href="#extensions">Extensions</a><ul>
 <li><a href="#query-delegates">Query Delegates</a></li>
 <li><a href="#implementing-the-query-delegate">Implementing the Query Delegate</a></li>
@@ -221,13 +222,13 @@ inadvertantly depending on an implementa
 <h2 id="setup-your-application">Setup your application</h2>
 <p>DeltaSpike data requires an <code>EntityManager</code> exposed via a
CDI producer - which is common practice
 in Java EE 6 applications.</p>
-<div class="codehilite"><pre><span class="kd">public</span> <span
class="kd">class</span> <span class="nc">DataSourceProducer</span>
+<div class="codehilite"><pre><span class="kd">public</span> <span
class="kd">class</span> <span class="nc">EntityManagerProducer</span>
 <span class="o">{</span>
     <span class="nd">@PersistenceUnit</span>
     <span class="kd">private</span> <span class="n">EntityManagerFactory</span>
<span class="n">emf</span><span class="o">;</span>
-    <span class="nd">@Produces</span>
+    <span class="nd">@Produces</span> <span class="c1">// you can also
make this @RequestScoped</span>
     <span class="kd">public</span> <span class="n">EntityManager</span>
<span class="nf">create</span><span class="o">()</span>
     <span class="o">{</span>
         <span class="k">return</span> <span class="n">emf</span><span
class="o">.</span><span class="na">createEntityManager</span><span
@@ -248,6 +249,16 @@ in Java EE 6 applications.</p>
 <p>This allows the <code>EntityManager</code> to be injected over CDI instead
of only being used with a
 <code>@PersistenceContext</code> annotation. Using multiple <code>EntityManager</code>
is explored in more detail
 in a following section.</p>
+<p>If you use a JTA DataSource with your <code>EntityManager</code>, you
also have to configure the
+<code>TransactionStrategy</code> your repositories use. Adapt your <code>beans.xml</code>
for this:</p>
+<div class="codehilite"><pre><span class="nt">&lt;beans&gt;</span>
+    <span class="nt">&lt;alternatives&gt;</span>
+        <span class="nt">&lt;class&gt;</span>org.apache.deltaspike.jpa.impl.transaction.BeanManagedUserTransactionStrategy<span
+    <span class="nt">&lt;/alternatives&gt;</span>
+<span class="nt">&lt;/beans&gt;</span>
 <p>You're now ready to use repositories in your application!</p>
 <h1 id="core-concepts">Core Concepts</h1>
 <h2 id="repositories">Repositories</h2>
@@ -715,6 +726,40 @@ result list.</p>
 <p>For method expressions, the <code>findAnyBy</code> prefix can be used.
For <code>@Query</code> annotations, the <code>singleResult</code>
 attribute can be overridden with the <code>SingleResultType.ANY</code> enum.</p>
 <p>This option will not throw an exception.</p>
+<h1 id="transactions">Transactions</h1>
+<p>If you call any method expression, <code>@Query</code>-annotated method
or a method from the <code>EntityRepository</code>, the 
+repository will figure out if a transaction is needed or not, and if so, if there is already
one ongoing.
+The Data module uses the <code>TransactionStrategy</code> provided by the <a
href="" title="JPA module">JPA Module</a> for this.
See the JPA module
+documentation for more details.</p>
+<p>Some containers do not support <code>BeanManagedUserTransactionStrategy</code>!
As JTA has still some portability
+issues even in Java EE 7, it might be required that you implement your own <code>TransactionStrategy</code>.
+We will think about providing an acceptable solution for this.</p>
+<p>Annotating Repository methods with <code>@Transactional</code> is not
yet supported, but will follow.</p>
+<p>If you need to open a transaction on a concrete repository method, we currently
recommend creating an extension
+(see next chapter) which uses <code>@Transactional</code> and might look like
the following sample. </p>
+<div class="codehilite"><pre><span class="kd">public</span> <span
class="kd">class</span> <span class="nc">TxExtension</span><span class="o">&lt;</span><span
class="n">E</span><span class="o">&gt;</span> <span class="kd">implements</span>
<span class="n">TxRepository</span> <span class="c1">// this is your extension
+<span class="o">{</span>
+    <span class="nd">@Inject</span>
+    <span class="kd">private</span> <span class="n">EntityManager</span>
<span class="n">em</span><span class="o">;</span>
+    <span class="nd">@Override</span> <span class="nd">@Transactional</span>
+    <span class="kd">public</span> <span class="n">List</span><span
class="o">&lt;</span><span class="n">E</span><span class="o">&gt;</span>
<span class="n">transactional</span><span class="o">(</span><span
class="n">ListResultCallback</span> <span class="n">callback</span><span
+    <span class="o">{</span>
+        <span class="k">return</span> <span class="n">callback</span><span
class="o">.</span><span class="na">execute</span><span class="o">();</span>
+    <span class="o">}</span>
+<span class="o">}</span>
+<p>Repositories can then implement the <code>TxRepository</code> interface
and call their queries in the
+<code>transactional</code> method (where the callback implementation can be e.g.
in an anonymous class).</p>
 <h1 id="extensions">Extensions</h1>
 <h2 id="query-delegates">Query Delegates</h2>
 <p>While repositories defines several base interfaces, there might still be the odd

View raw message