00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 package org.openmobileis.database.fastobjectdb.db.transaction;
00030
00031 import java.util.HashMap;
00032
00033 import org.openmobileis.database.fastobjectdb.db.exception.FODBException;
00034
00040 public final class TransactionManager {
00041 private HashMap transactionListbythread;
00042 private HashMap transactionFileListbyCollection;
00046 public TransactionManager() {
00047 super();
00048 transactionListbythread = new HashMap(10);
00049 transactionFileListbyCollection = new HashMap(20);
00050 }
00051
00052 private Transaction getTransaction() {
00053 Thread th = Thread.currentThread();
00054 Transaction ret = (Transaction)transactionListbythread.get(th);
00055 if (ret==null) {
00056 ret = new Transaction();
00057 transactionListbythread.put(th, ret);
00058 }
00059 return ret;
00060 }
00061
00062 public synchronized void registerTransactionFile(TransactionFile file, String collectionName) {
00063 transactionFileListbyCollection.put(collectionName, file);
00064 }
00065
00066 public synchronized void enterTransaction(String collectionName) throws FODBException {
00067 TransactionFile file = (TransactionFile)transactionFileListbyCollection.get(collectionName);
00068 if (file != null) {
00069 this.getTransaction().addTransactionFile(file);
00070 } else {
00071 throw new FODBException("ERROR TransactionManager Unregistered Collection :"+collectionName+" try to enter transaction.");
00072 }
00073 }
00074
00075 public void begin() throws FODBException {
00076 this.getTransaction().begin();
00077 }
00078
00079 public void commit() throws FODBException {
00080 boolean effective = this.getTransaction().commit();
00081 if (effective) {
00082 transactionListbythread.remove(Thread.currentThread());
00083 }
00084 }
00085
00086 public void rollback() throws FODBException {
00087 boolean effective = this.getTransaction().rollback();
00088 if (effective) {
00089 transactionListbythread.remove(Thread.currentThread());
00090 }
00091 }
00092
00093 }