Main Page | Class Hierarchy | Data Structures | Directories | File List | Data Fields | Related Pages

RpcDbTxn.java

00001 /*-
00002  * See the file LICENSE for redistribution information.
00003  *
00004  * Copyright (c) 2001-2005
00005  *      Sleepycat Software.  All rights reserved.
00006  *
00007  * $Id: RpcDbTxn.java,v 12.2 2005/08/02 06:57:09 mjc Exp $
00008  */
00009 
00010 package com.sleepycat.db.rpcserver;
00011 
00012 import com.sleepycat.db.*;
00013 import com.sleepycat.db.internal.DbConstants;
00014 import java.io.*;
00015 import java.util.*;
00016 
00020 public class RpcDbTxn extends Timer {
00021     RpcDbEnv rdbenv;
00022     Transaction txn;
00023 
00024     public RpcDbTxn(RpcDbEnv rdbenv, Transaction txn) {
00025         this.rdbenv = rdbenv;
00026         this.txn = txn;
00027     }
00028 
00029     void dispose() {
00030         if (txn != null) {
00031             try {
00032                 txn.abort();
00033             } catch (DatabaseException e) {
00034                 e.printStackTrace(Server.err);
00035             }
00036             txn = null;
00037         }
00038     }
00039 
00040     public  void abort(Dispatcher server,
00041                        __txn_abort_msg args, __txn_abort_reply reply) {
00042         try {
00043             txn.abort();
00044             txn = null;
00045             reply.status = 0;
00046         } catch (Throwable t) {
00047             reply.status = Util.handleException(t);
00048         } finally {
00049             server.delTxn(this, false);
00050         }
00051     }
00052 
00053     public  void begin(Dispatcher server,
00054                        __env_txn_begin_msg args, __env_txn_begin_reply reply) {
00055         try {
00056             if (rdbenv == null) {
00057                 reply.status = DbConstants.DB_NOSERVER_ID;
00058                 return;
00059             }
00060             Environment dbenv = rdbenv.dbenv;
00061             RpcDbTxn rparent = server.getTxn(args.parentcl_id);
00062             Transaction parent = (rparent != null) ? rparent.txn : null;
00063 
00064             TransactionConfig config = new TransactionConfig();
00065             config.setReadCommitted((args.flags & DbConstants.DB_READ_COMMITTED) != 0);
00066             config.setReadUncommitted((args.flags & DbConstants.DB_READ_UNCOMMITTED) != 0);
00067             config.setNoSync((args.flags & DbConstants.DB_TXN_NOSYNC) != 0);
00068             config.setNoWait(true);
00069             config.setSync((args.flags & DbConstants.DB_TXN_SYNC) != 0);
00070 
00071             txn = dbenv.beginTransaction(parent, config);
00072 
00073             if (rparent != null)
00074                 timer = rparent.timer;
00075             reply.txnidcl_id = server.addTxn(this);
00076             reply.status = 0;
00077         } catch (Throwable t) {
00078             reply.status = Util.handleException(t);
00079         }
00080     }
00081 
00082     public  void commit(Dispatcher server,
00083                         __txn_commit_msg args, __txn_commit_reply reply) {
00084         try {
00085             switch(args.flags) {
00086             case 0:
00087                 txn.commit();
00088                 break;
00089 
00090             case DbConstants.DB_TXN_SYNC:
00091                 txn.commitSync();
00092                 break;
00093 
00094             case DbConstants.DB_TXN_NOSYNC:
00095                 txn.commitSync();
00096                 break;
00097 
00098             default:
00099                 throw new UnsupportedOperationException("Unknown flag: " + (args.flags & ~Server.DB_MODIFIER_MASK));
00100             }
00101             txn = null;
00102             reply.status = 0;
00103         } catch (Throwable t) {
00104             reply.status = Util.handleException(t);
00105         } finally {
00106             server.delTxn(this, false);
00107         }
00108     }
00109 
00110     public  void discard(Dispatcher server,
00111                          __txn_discard_msg args, __txn_discard_reply reply) {
00112         try {
00113             txn.discard(/* args.flags == 0 */);
00114             txn = null;
00115             reply.status = 0;
00116         } catch (Throwable t) {
00117             reply.status = Util.handleException(t);
00118         } finally {
00119             server.delTxn(this, false);
00120         }
00121     }
00122 
00123     public  void prepare(Dispatcher server,
00124                          __txn_prepare_msg args, __txn_prepare_reply reply) {
00125         try {
00126             txn.prepare(args.gid);
00127             reply.status = 0;
00128         } catch (Throwable t) {
00129             reply.status = Util.handleException(t);
00130         }
00131     }
00132 }

Generated on Sun Dec 25 12:14:49 2005 for Berkeley DB 4.4.16 by  doxygen 1.4.2