KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > objectserver > persistence > sleepycat > SleepycatPersistenceTransactionProvider


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tc.objectserver.persistence.sleepycat;
5
6 import com.sleepycat.je.DatabaseException;
7 import com.sleepycat.je.Environment;
8 import com.sleepycat.je.Transaction;
9 import com.tc.objectserver.persistence.api.PersistenceTransaction;
10 import com.tc.objectserver.persistence.api.PersistenceTransactionProvider;
11
12 final class SleepycatPersistenceTransactionProvider implements PersistenceTransactionProvider {
13   private static final PersistenceTransaction NULL_TRANSACTION = new TransactionWrapper(null);
14   private final Environment env;
15
16   public SleepycatPersistenceTransactionProvider(Environment env) {
17     this.env = env;
18   }
19
20   public PersistenceTransaction newTransaction() {
21     try {
22       return new TransactionWrapper(newNativeTransaction());
23     } catch (DatabaseException e) {
24       throw new DBException(e);
25     }
26   }
27
28   public PersistenceTransaction nullTransaction() {
29     return NULL_TRANSACTION;
30   }
31
32   Transaction newNativeTransaction() throws DatabaseException {
33     return this.env.beginTransaction(null, null);
34   }
35 }
Popular Tags