EMMA Coverage Report (generated Sun May 02 20:42:29 CEST 2010)
[all classes][hu.netmind.beankeeper.transaction.impl]

COVERAGE SUMMARY FOR SOURCE FILE [InternalTransactionTrackerImpl.java]

nameclass, %method, %block, %line, %
InternalTransactionTrackerImpl.java100% (2/2)75%  (12/16)56%  (81/144)63%  (24.4/39)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class InternalTransactionTrackerImpl$TransactionImpl100% (1/1)60%  (6/10)48%  (57/120)55%  (17.4/32)
getEndSerial (): Long 0%   (0/1)0%   (0/2)0%   (0/1)
getSerial (): Long 0%   (0/1)0%   (0/2)0%   (0/1)
markRollbackOnly (): void 0%   (0/1)0%   (0/4)0%   (0/2)
rollback (): void 0%   (0/1)0%   (0/29)0%   (0/6)
commit (): void 100% (1/1)42%  (15/36)56%  (4.4/8)
begin (): void 100% (1/1)67%  (10/15)75%  (3/4)
InternalTransactionTrackerImpl$TransactionImpl (InternalTransactionTrackerImp... 100% (1/1)100% (23/23)100% (7/7)
getConnection (): Connection 100% (1/1)100% (3/3)100% (1/1)
getStats (): TransactionStatistics 100% (1/1)100% (3/3)100% (1/1)
isRollbackOnly (): boolean 100% (1/1)100% (3/3)100% (1/1)
     
class InternalTransactionTrackerImpl100% (1/1)100% (6/6)100% (24/24)100% (7/7)
<static initializer> 100% (1/1)100% (4/4)100% (1/1)
InternalTransactionTrackerImpl (): void 100% (1/1)100% (6/6)100% (3/3)
access$000 (InternalTransactionTrackerImpl): Database 100% (1/1)100% (3/3)100% (1/1)
getTransaction (): Transaction 100% (1/1)100% (9/9)100% (1/1)
init (Map): void 100% (1/1)100% (1/1)100% (1/1)
release (): void 100% (1/1)100% (1/1)100% (1/1)

1/**
2 * Copyright (C) 2006 NetMind Consulting Bt.
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 3 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17 */
18 
19package hu.netmind.beankeeper.transaction.impl;
20 
21import java.util.*;
22import java.sql.Connection;
23import java.sql.SQLException;
24import org.apache.log4j.Logger;
25import hu.netmind.beankeeper.common.StoreException;
26import hu.netmind.beankeeper.transaction.*;
27import hu.netmind.beankeeper.db.Database;
28 
29/**
30 * This class supplies the services with lightweight transactions.
31 * @author Brautigam Robert
32 * @version Revision: $Revision$
33 */
34public class InternalTransactionTrackerImpl implements InternalTransactionTracker
35{
36   private static Logger logger = Logger.getLogger(InternalTransactionTrackerImpl.class);
37   
38   private Database database = null; // Injected
39 
40   public void init(Map parameters)
41   {
42   }
43 
44   public void release()
45   {
46   }
47 
48   /**
49    * Get a lightweight transaction.
50    */
51   public Transaction getTransaction()
52   {
53      return new TransactionImpl(database.getConnectionSource().getConnection());
54   }
55 
56   public class TransactionImpl extends HashMap implements Transaction
57   {
58      private Connection connection = null;
59      private boolean rollbackOnly = false;
60      private TransactionStatistics stats = new TransactionStatistics();
61      private int depth = 0;
62 
63      public TransactionImpl(Connection connection)
64      {
65         this.connection=connection;
66      }
67 
68      /**
69       * Begin the transaction, but for safety don't support embedding transactions.
70       */
71      public void begin()
72      {
73         if ( depth != 0 )
74            throw new StoreException("direct transaction does not support embedded blocks, transaction already begun");
75         depth++;
76      }
77 
78      /**
79       * Commit a transaction.
80       */
81      public void commit()
82      {
83         try
84         {
85            if ( isRollbackOnly() )
86               connection.rollback();
87            else
88               connection.commit();
89         } catch ( SQLException e ) {
90            throw new StoreException("exception while commit",e);
91         } finally {
92            database.getConnectionSource().releaseConnection(connection);
93         }
94      }
95 
96      /**
97       * Rollback this transaction.
98       */
99      public void rollback()
100      {
101         try
102         {
103            connection.rollback();
104         } catch ( SQLException e ) {
105            throw new StoreException("exception while rollback",e);
106         } finally {
107            database.getConnectionSource().releaseConnection(connection);
108         }
109      }
110 
111      /**
112       * Mark this transaction as rollback only.
113       */
114      public void markRollbackOnly()
115      {
116         rollbackOnly = true;
117      }
118 
119      /**
120       * Returns whether this transaction was marked "rollback only".
121       */
122      public boolean isRollbackOnly()
123      {
124         return rollbackOnly;
125      }
126 
127      /**
128       * No used.
129       * @return Always null.
130       */
131      public Long getSerial()
132      {
133         return null;
134      }
135 
136      /**
137       * Not used.
138       * @return Always null.
139       */
140      public Long getEndSerial()
141      {
142         return null;
143      }
144 
145      /**
146       * Get statistics from this transaction.
147       */
148      public TransactionStatistics getStats()
149      {
150         return stats;
151      }
152 
153      /**
154       * Get the connection to the database from this transaction.
155       */
156      public Connection getConnection()
157      {
158         return connection;
159      }
160   }
161 
162 
163}
164 
165 

[all classes][hu.netmind.beankeeper.transaction.impl]
EMMA 2.0.5312debian (C) Vladimir Roubtsov