1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.store.legacy.store.internal

File XWikiHibernateTransaction.java

 

Coverage histogram

../../../../../../img/srcFileCovDistChart6.png
69% of files have more coverage

Code metrics

4
8
5
1
99
40
7
0.88
1.6
5
1.4

Classes

Class Line # Actions
XWikiHibernateTransaction 35 8 0% 7 7
0.588235358.8%
 

Contributing tests

This file is covered by 5 tests. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.store.legacy.store.internal;
21   
22    import com.xpn.xwiki.store.XWikiHibernateBaseStore;
23    import com.xpn.xwiki.XWikiContext;
24    import com.xpn.xwiki.XWikiException;
25    import org.xwiki.store.RootTransactionRunnable;
26   
27    /**
28    * A Transaction based on XWikiHibernateStore.
29    * SQL based TransactionRunnables MUST extend RootTransactionRunnable because
30    * SQL storage engines are incapable of rolling back after commit.
31    *
32    * @version $Id: 22a21511b4acce71ed8648d7a93556533b8e2033 $
33    * @since 3.0M2
34    */
 
35    public class XWikiHibernateTransaction extends RootTransactionRunnable implements HibernateTransaction
36    {
37    /**
38    * The storage engine.
39    */
40    private final XWikiHibernateBaseStore store;
41   
42    /**
43    * The XWikiContext associated with the request which started this Transaction.
44    */
45    private final XWikiContext context;
46   
47    /**
48    * True if the transaction should be ended when finished.
49    * This will only be false if the transaction could not be started because another transaction
50    * was already open and associated with the same XWikiContext.
51    */
52    private boolean shouldCloseTransaction;
53   
54    /**
55    * The Constructor.
56    *
57    * @param context the XWikiContext associated with the request which started this Transaction.
58    */
 
59  5 toggle public XWikiHibernateTransaction(final XWikiContext context)
60    {
61  5 this.store = context.getWiki().getHibernateStore();
62  5 this.context = context;
63    }
64   
 
65  5 toggle @Override
66    public void onPreRun() throws XWikiException
67    {
68  5 this.store.checkHibernate(this.context);
69    }
70   
71    /**
72    * {@inheritDoc}
73    * <p>
74    * onRun() is guaranteed to be run in the root runnable first.
75    * onPreRun should run before the transaction is opened.
76    * </p>
77    */
 
78  5 toggle @Override
79    public void onRun() throws XWikiException
80    {
81  5 this.shouldCloseTransaction = this.store.beginTransaction(this.context);
82    }
83   
 
84  5 toggle @Override
85    public void onCommit()
86    {
87  5 if (this.shouldCloseTransaction) {
88  0 this.store.endTransaction(this.context, true);
89    }
90    }
91   
 
92  0 toggle @Override
93    public void onRollback()
94    {
95  0 if (this.shouldCloseTransaction) {
96  0 this.store.endTransaction(this.context, false);
97    }
98    }
99    }