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

RpcDbc.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: RpcDbc.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 RpcDbc extends Timer {
00021     static final byte[] empty = new byte[0];
00022     RpcDbEnv rdbenv;
00023     RpcDb rdb;
00024     Cursor dbc;
00025     Timer orig_timer;
00026     boolean isJoin;
00027 
00028     public RpcDbc(RpcDb rdb, Cursor dbc, boolean isJoin) {
00029         this.rdb = rdb;
00030         this.rdbenv = rdb.rdbenv;
00031         this.dbc = dbc;
00032         this.isJoin = isJoin;
00033     }
00034 
00035     void dispose() {
00036         if (dbc != null) {
00037             try {
00038                 dbc.close();
00039             } catch (Throwable t) {
00040                 Util.handleException(t);
00041             }
00042             dbc = null;
00043         }
00044     }
00045 
00046     public  void close(Dispatcher server,
00047                        __dbc_c_close_msg args, __dbc_c_close_reply reply) {
00048         try {
00049             dbc.close();
00050             dbc = null;
00051 
00052             if (isJoin)
00053                 for (LocalIterator i = ((Server)server).cursor_list.iterator(); i.hasNext();) {
00054                     RpcDbc rdbc = (RpcDbc)i.next();
00055                     // Unjoin cursors that were joined to create this
00056                     if (rdbc != null && rdbc.timer == this)
00057                         rdbc.timer = rdbc.orig_timer;
00058                 }
00059 
00060             reply.status = 0;
00061         } catch (Throwable t) {
00062             reply.status = Util.handleException(t);
00063         } finally {
00064             server.delCursor(this, false);
00065         }
00066     }
00067 
00068     public  void count(Dispatcher server,
00069                        __dbc_c_count_msg args, __dbc_c_count_reply reply) {
00070         try {
00071             reply.dupcount = dbc.count(/* args.flags == 0 */);
00072             reply.status = 0;
00073         } catch (Throwable t) {
00074             reply.status = Util.handleException(t);
00075         }
00076     }
00077 
00078     public  void del(Dispatcher server,
00079                      __dbc_c_del_msg args, __dbc_c_del_reply reply) {
00080         try {
00081             reply.status = Util.getStatus(dbc.delete(/* args.flags == 0 */));
00082         } catch (Throwable t) {
00083             reply.status = Util.handleException(t);
00084         }
00085     }
00086 
00087     public  void dup(Dispatcher server,
00088                      __dbc_c_dup_msg args, __dbc_c_dup_reply reply) {
00089         try {
00090             Cursor newdbc = dbc.dup(args.flags == DbConstants.DB_POSITION);
00091             RpcDbc rdbc = new RpcDbc(rdb, newdbc, false);
00092             /* If this cursor has a parent txn, we need to use it too. */
00093             if (timer != this)
00094                 rdbc.timer = timer;
00095             reply.dbcidcl_id = server.addCursor(rdbc);
00096             reply.status = 0;
00097         } catch (Throwable t) {
00098             reply.status = Util.handleException(t);
00099         }
00100     }
00101 
00102     public  void get(Dispatcher server,
00103                      __dbc_c_get_msg args, __dbc_c_get_reply reply) {
00104         try {
00105             DatabaseEntry key = Util.makeDatabaseEntry(args.keydata, args.keydlen, args.keydoff, args.keyulen, args.keyflags);
00106             DatabaseEntry data = Util.makeDatabaseEntry(args.datadata,
00107                 args.datadlen, args.datadoff, args.dataulen, args.dataflags,
00108                 args.flags & (DbConstants.DB_MULTIPLE | DbConstants.DB_MULTIPLE_KEY));
00109 
00110             OperationStatus status;
00111             switch(args.flags & ~Server.DB_MODIFIER_MASK) {
00112             case DbConstants.DB_CURRENT:
00113                 status = dbc.getCurrent(key, data, Util.getLockMode(args.flags));
00114                 break;
00115 
00116             case DbConstants.DB_FIRST:
00117                 status = dbc.getFirst(key, data, Util.getLockMode(args.flags));
00118                 break;
00119 
00120             case DbConstants.DB_LAST:
00121                 status = dbc.getLast(key, data, Util.getLockMode(args.flags));
00122                 break;
00123 
00124             case DbConstants.DB_NEXT:
00125                 status = dbc.getNext(key, data, Util.getLockMode(args.flags));
00126                 break;
00127 
00128             case DbConstants.DB_NEXT_DUP:
00129                 status = dbc.getNextDup(key, data, Util.getLockMode(args.flags));
00130                 break;
00131 
00132             case DbConstants.DB_NEXT_NODUP:
00133                 status = dbc.getNextNoDup(key, data, Util.getLockMode(args.flags));
00134                 break;
00135 
00136             case DbConstants.DB_PREV:
00137                 status = dbc.getPrev(key, data, Util.getLockMode(args.flags));
00138                 break;
00139 
00140             case DbConstants.DB_PREV_NODUP:
00141                 status = dbc.getPrevNoDup(key, data, Util.getLockMode(args.flags));
00142                 break;
00143 
00144             case DbConstants.DB_GET_RECNO:
00145                 status = dbc.getRecordNumber(data, Util.getLockMode(args.flags));
00146                 break;
00147 
00148             case DbConstants.DB_SET:
00149                 status = dbc.getSearchKey(key, data, Util.getLockMode(args.flags));
00150                 break;
00151 
00152             case DbConstants.DB_SET_RANGE:
00153                 status = dbc.getSearchKeyRange(key, data, Util.getLockMode(args.flags));
00154                 break;
00155 
00156             case DbConstants.DB_GET_BOTH:
00157                 status = dbc.getSearchBoth(key, data, Util.getLockMode(args.flags));
00158                 break;
00159 
00160             case DbConstants.DB_GET_BOTH_RANGE:
00161                 status = dbc.getSearchBothRange(key, data, Util.getLockMode(args.flags));
00162                 break;
00163 
00164             case DbConstants.DB_SET_RECNO:
00165                 status = dbc.getSearchRecordNumber(key, data, Util.getLockMode(args.flags));
00166                 break;
00167 
00168                 /* Join cursors */
00169             case 0:
00170                 status = ((JoinCursorAdapter)dbc).jc.getNext(key, Util.getLockMode(args.flags));
00171                 break;
00172 
00173             case DbConstants.DB_JOIN_ITEM:
00174                 status = ((JoinCursorAdapter)dbc).jc.getNext(key, Util.getLockMode(args.flags));
00175                 break;
00176 
00177             default:
00178                 throw new UnsupportedOperationException("Unknown flag: " + (args.flags & ~Server.DB_MODIFIER_MASK));
00179             }
00180             reply.status = Util.getStatus(status);
00181             reply.keydata = Util.returnDatabaseEntry(key);
00182             reply.datadata = Util.returnDatabaseEntry(data);
00183         } catch (Throwable t) {
00184             reply.status = Util.handleException(t);
00185             reply.keydata = reply.datadata = empty;
00186         }
00187     }
00188 
00189     public  void pget(Dispatcher server,
00190                       __dbc_c_pget_msg args, __dbc_c_pget_reply reply) {
00191         try {
00192             DatabaseEntry skey = Util.makeDatabaseEntry(args.skeydata, args.skeydlen, args.skeydoff, args.skeyulen, args.skeyflags);
00193             DatabaseEntry pkey = Util.makeDatabaseEntry(args.pkeydata, args.pkeydlen, args.pkeydoff, args.pkeyulen, args.pkeyflags);
00194             DatabaseEntry data = Util.makeDatabaseEntry(args.datadata, args.datadlen, args.datadoff, args.dataulen, args.dataflags);
00195 
00196             OperationStatus status;
00197             switch(args.flags & ~Server.DB_MODIFIER_MASK) {
00198             case DbConstants.DB_CURRENT:
00199                 status = ((SecondaryCursor)dbc).getCurrent(skey, pkey, data, Util.getLockMode(args.flags));
00200                 break;
00201 
00202             case DbConstants.DB_FIRST:
00203                 status = ((SecondaryCursor)dbc).getFirst(skey, pkey, data, Util.getLockMode(args.flags));
00204                 break;
00205 
00206             case DbConstants.DB_LAST:
00207                 status = ((SecondaryCursor)dbc).getLast(skey, pkey, data, Util.getLockMode(args.flags));
00208                 break;
00209 
00210             case DbConstants.DB_NEXT:
00211                 status = ((SecondaryCursor)dbc).getNext(skey, pkey, data, Util.getLockMode(args.flags));
00212                 break;
00213 
00214             case DbConstants.DB_NEXT_DUP:
00215                 status = ((SecondaryCursor)dbc).getNextDup(skey, pkey, data, Util.getLockMode(args.flags));
00216                 break;
00217 
00218             case DbConstants.DB_NEXT_NODUP:
00219                 status = ((SecondaryCursor)dbc).getNextNoDup(skey, pkey, data, Util.getLockMode(args.flags));
00220                 break;
00221 
00222             case DbConstants.DB_PREV:
00223                 status = ((SecondaryCursor)dbc).getPrev(skey, pkey, data, Util.getLockMode(args.flags));
00224                 break;
00225 
00226             case DbConstants.DB_PREV_NODUP:
00227                 status = ((SecondaryCursor)dbc).getPrevNoDup(skey, pkey, data, Util.getLockMode(args.flags));
00228                 break;
00229 
00230             case DbConstants.DB_GET_RECNO:
00231                 status = ((SecondaryCursor)dbc).getRecordNumber(pkey, data, Util.getLockMode(args.flags));
00232                 break;
00233 
00234             case DbConstants.DB_SET:
00235                 status = ((SecondaryCursor)dbc).getSearchKey(skey, pkey, data, Util.getLockMode(args.flags));
00236                 break;
00237 
00238             case DbConstants.DB_SET_RANGE:
00239                 status = ((SecondaryCursor)dbc).getSearchKeyRange(skey, pkey, data, Util.getLockMode(args.flags));
00240                 break;
00241 
00242             case DbConstants.DB_GET_BOTH:
00243                 status = ((SecondaryCursor)dbc).getSearchBoth(skey, pkey, data, Util.getLockMode(args.flags));
00244                 break;
00245 
00246             case DbConstants.DB_GET_BOTH_RANGE:
00247                 status = ((SecondaryCursor)dbc).getSearchBothRange(skey, pkey, data, Util.getLockMode(args.flags));
00248                 break;
00249 
00250             case DbConstants.DB_SET_RECNO:
00251                 status = ((SecondaryCursor)dbc).getSearchRecordNumber(skey, pkey, data, Util.getLockMode(args.flags));
00252                 break;
00253 
00254             default:
00255                 throw new UnsupportedOperationException("Unknown flag: " + (args.flags & ~Server.DB_MODIFIER_MASK));
00256             }
00257             reply.status = Util.getStatus(status);
00258             reply.skeydata = Util.returnDatabaseEntry(skey);
00259             reply.pkeydata = Util.returnDatabaseEntry(pkey);
00260             reply.datadata = Util.returnDatabaseEntry(data);
00261         } catch (Throwable t) {
00262             reply.status = Util.handleException(t);
00263             reply.skeydata = reply.pkeydata = reply.datadata = empty;
00264         }
00265     }
00266 
00267     public  void put(Dispatcher server,
00268                      __dbc_c_put_msg args, __dbc_c_put_reply reply) {
00269         try {
00270             DatabaseEntry key = Util.makeDatabaseEntry(args.keydata, args.keydlen, args.keydoff, args.keyulen, args.keyflags);
00271             DatabaseEntry data = Util.makeDatabaseEntry(args.datadata, args.datadlen, args.datadoff, args.dataulen, args.dataflags);
00272 
00273             OperationStatus status;
00274             switch(args.flags & ~Server.DB_MODIFIER_MASK) {
00275             case 0:
00276                 status = dbc.put(key, data);
00277                 break;
00278 
00279             case DbConstants.DB_AFTER:
00280                 status = dbc.putAfter(key, data);
00281                 break;
00282 
00283             case DbConstants.DB_BEFORE:
00284                 status = dbc.putBefore(key, data);
00285                 break;
00286 
00287             case DbConstants.DB_NOOVERWRITE:
00288                 status = dbc.putNoOverwrite(key, data);
00289                 break;
00290 
00291             case DbConstants.DB_KEYFIRST:
00292                 status = dbc.putKeyFirst(key, data);
00293                 break;
00294 
00295             case DbConstants.DB_KEYLAST:
00296                 status = dbc.putKeyLast(key, data);
00297                 break;
00298 
00299             case DbConstants.DB_NODUPDATA:
00300                 status = dbc.putNoDupData(key, data);
00301                 break;
00302 
00303             case DbConstants.DB_CURRENT:
00304                 status = dbc.putCurrent(data);
00305                 break;
00306 
00307             default:
00308                 throw new UnsupportedOperationException("Unknown flag: " + (args.flags & ~Server.DB_MODIFIER_MASK));
00309             }
00310             reply.status = Util.getStatus(status);
00311             reply.keydata = Util.returnDatabaseEntry(key);
00312         } catch (Throwable t) {
00313             reply.status = Util.handleException(t);
00314             reply.keydata = empty;
00315         }
00316     }
00317 }

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