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

RpcDb.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: RpcDb.java,v 12.3 2005/08/02 06:57:08 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 RpcDb extends Timer {
00021     static final byte[] empty = new byte[0];
00022     DatabaseConfig config;
00023     Database db;
00024     RpcDbEnv rdbenv;
00025     int refcount = 0;
00026     String dbname, subdbname;
00027     int type, setflags, openflags;
00028 
00029     public RpcDb(RpcDbEnv rdbenv) {
00030         this.rdbenv = rdbenv;
00031     }
00032 
00033     void dispose() {
00034         if (db != null) {
00035             try {
00036                 db.close();
00037             } catch (Throwable t) {
00038                 Util.handleException(t);
00039             }
00040             db = null;
00041         }
00042     }
00043 
00044     public  void associate(Dispatcher server,
00045                            __db_associate_msg args, __db_associate_reply reply) {
00046         try {
00047             // The semantics of the new API are a little different.
00048             // The secondary database will already be open, here, so we first
00049             // have to close it and then call openSecondaryDatabase.
00050             RpcDb secondary = server.getDatabase(args.sdbpcl_id);
00051             try {
00052                 secondary.db.close();
00053             } finally {
00054                 secondary.db = null;
00055             }
00056 
00057             RpcDbTxn rtxn = server.getTxn(args.txnpcl_id);
00058             Transaction txn = (rtxn != null) ? rtxn.txn : null;
00059 
00060             args.flags &= ~AssociateCallbacks.DB_RPC2ND_MASK;
00061             SecondaryConfig secondaryConfig = new SecondaryConfig();
00062             // The secondary has already been opened once, so we don't
00063             // need all of the settings here, only a few:
00064             secondaryConfig.setReadOnly(secondary.config.getReadOnly());
00065             secondaryConfig.setTransactional(secondary.config.getTransactional());
00066             secondaryConfig.setKeyCreator(AssociateCallbacks.getCallback(args.flags));
00067             secondaryConfig.setAllowPopulate((args.flags & DbConstants.DB_CREATE) != 0);
00068             secondary.db = rdbenv.dbenv.openSecondaryDatabase(txn, secondary.dbname, secondary.subdbname, db, secondaryConfig);
00069             secondary.config = secondary.db.getConfig();
00070             reply.status = 0;
00071         } catch (Throwable t) {
00072             reply.status = Util.handleException(t);
00073         }
00074     }
00075 
00076     public void close(Dispatcher server,
00077                        __db_close_msg args, __db_close_reply reply) {
00078         if (refcount == 0 || --refcount > 0) {
00079             reply.status = 0;
00080             return;
00081         }
00082 
00083         try {
00084             server.delDatabase(this, false);
00085             if (db != null)
00086                 db.close((args.flags & DbConstants.DB_NOSYNC) != 0);
00087             reply.status = 0;
00088         } catch (Throwable t) {
00089             reply.status = Util.handleException(t);
00090         } finally {
00091             db = null;
00092         }
00093     }
00094 
00095     public  void create(Dispatcher server,
00096                         __db_create_msg args, __db_create_reply reply) {
00097         try {
00098             config = new DatabaseConfig();
00099             config.setXACreate((args.flags & DbConstants.DB_XA_CREATE) != 0);
00100             reply.dbcl_id = server.addDatabase(this);
00101             reply.status = 0;
00102         } catch (Throwable t) {
00103             reply.status = Util.handleException(t);
00104         }
00105     }
00106 
00107     public  void cursor(Dispatcher server,
00108                         __db_cursor_msg args, __db_cursor_reply reply) {
00109         try {
00110             RpcDbTxn rtxn = server.getTxn(args.txnpcl_id);
00111             Transaction txn = (rtxn != null) ? rtxn.txn : null;
00112 
00113             CursorConfig config = new CursorConfig();
00114             config.setReadUncommitted((args.flags & DbConstants.DB_READ_UNCOMMITTED) != 0);
00115             config.setReadCommitted((args.flags & DbConstants.DB_READ_COMMITTED) != 0);
00116             config.setWriteCursor((args.flags & DbConstants.DB_WRITECURSOR) != 0);
00117 
00118             Cursor dbc = db.openCursor(txn, config);
00119             RpcDbc rdbc = new RpcDbc(this, dbc, false);
00120             rdbc.timer = (rtxn != null) ? rtxn.timer : this;
00121             reply.dbcidcl_id = server.addCursor(rdbc);
00122             reply.status = 0;
00123         } catch (Throwable t) {
00124             reply.status = Util.handleException(t);
00125         }
00126     }
00127 
00128     public  void del(Dispatcher server,
00129                      __db_del_msg args, __db_del_reply reply) {
00130         try {
00131             RpcDbTxn rtxn = server.getTxn(args.txnpcl_id);
00132             Transaction txn = (rtxn != null) ? rtxn.txn : null;
00133             DatabaseEntry key = Util.makeDatabaseEntry(args.keydata, args.keydlen, args.keydoff, args.keyulen, args.keyflags);
00134 
00135             db.delete(txn, key /* args.flags == 0 */);
00136             reply.status = 0;
00137         } catch (Throwable t) {
00138             reply.status = Util.handleException(t);
00139         }
00140     }
00141 
00142     public  void get(Dispatcher server,
00143                      __db_get_msg args, __db_get_reply reply) {
00144         try {
00145             RpcDbTxn rtxn = server.getTxn(args.txnpcl_id);
00146             Transaction txn = (rtxn != null) ? rtxn.txn : null;
00147             DatabaseEntry key = Util.makeDatabaseEntry(args.keydata, args.keydlen, args.keydoff, args.keyulen, args.keyflags);
00148             DatabaseEntry data = Util.makeDatabaseEntry(args.datadata,
00149                 args.datadlen, args.datadoff, args.dataulen, args.dataflags,
00150                 args.flags & DbConstants.DB_MULTIPLE);
00151 
00152             OperationStatus status;
00153             switch(args.flags & ~Server.DB_MODIFIER_MASK) {
00154             case 0:
00155                 status = db.get(txn, key, data, Util.getLockMode(args.flags));
00156                 break;
00157 
00158             case DbConstants.DB_CONSUME:
00159                 status = db.consume(txn, key, data, false);
00160                 break;
00161 
00162             case DbConstants.DB_CONSUME_WAIT:
00163                 status = db.consume(txn, key, data, true);
00164                 break;
00165 
00166             case DbConstants.DB_GET_BOTH:
00167                 status = db.getSearchBoth(txn, key, data, Util.getLockMode(args.flags));
00168                 break;
00169 
00170             case DbConstants.DB_SET_RECNO:
00171                 status = db.getSearchRecordNumber(txn, key, data, Util.getLockMode(args.flags));
00172                 break;
00173 
00174             default:
00175                 throw new UnsupportedOperationException("Unknown flag: " + (args.flags & ~Server.DB_MODIFIER_MASK));
00176             }
00177             reply.status = Util.getStatus(status);
00178 
00179             reply.keydata = Util.returnDatabaseEntry(key);
00180             reply.datadata = Util.returnDatabaseEntry(data);
00181         } catch (Throwable t) {
00182             reply.status = Util.handleException(t);
00183             reply.keydata = reply.datadata = empty;
00184         }
00185     }
00186 
00187     public  void join(Dispatcher server,
00188                       __db_join_msg args, __db_join_reply reply) {
00189         try {
00190             Cursor[] cursors = new Cursor[args.curs.length + 1];
00191             for (int i = 0; i < args.curs.length; i++) {
00192                 RpcDbc rdbc = server.getCursor(args.curs[i]);
00193                 if (rdbc == null) {
00194                     reply.status = DbConstants.DB_NOSERVER_ID;
00195                     return;
00196                 }
00197                 cursors[i] = rdbc.dbc;
00198             }
00199             cursors[args.curs.length] = null;
00200 
00201             JoinConfig config = new JoinConfig();
00202             config.setNoSort(args.flags == DbConstants.DB_JOIN_NOSORT);
00203             JoinCursor jdbc = db.join(cursors, config);
00204 
00205             RpcDbc rjdbc = new RpcDbc(this, new JoinCursorAdapter(db, jdbc), true);
00206             /*
00207              * If our curslist has a parent txn, we need to use it too
00208              * for the activity timeout.  All cursors must be part of
00209              * the same transaction, so just check the first.
00210              */
00211             RpcDbc rdbc0 = server.getCursor(args.curs[0]);
00212             if (rdbc0.timer != rdbc0)
00213                 rjdbc.timer = rdbc0.timer;
00214 
00215             /*
00216              * All of the curslist cursors must point to the join
00217              * cursor's timeout so that we do not timeout any of the
00218              * curlist cursors while the join cursor is active.
00219              */
00220             for (int i = 0; i < args.curs.length; i++) {
00221                 RpcDbc rdbc = server.getCursor(args.curs[i]);
00222                 rdbc.orig_timer = rdbc.timer;
00223                 rdbc.timer = rjdbc;
00224             }
00225             reply.dbcidcl_id = server.addCursor(rjdbc);
00226             reply.status = 0;
00227         } catch (Throwable t) {
00228             reply.status = Util.handleException(t);
00229         }
00230     }
00231 
00232     public  void key_range(Dispatcher server,
00233                            __db_key_range_msg args, __db_key_range_reply reply) {
00234         try {
00235             RpcDbTxn rtxn = server.getTxn(args.txnpcl_id);
00236             Transaction txn = (rtxn != null) ? rtxn.txn : null;
00237             DatabaseEntry key = Util.makeDatabaseEntry(args.keydata, args.keydlen, args.keydoff, args.keyulen, args.keyflags);
00238 
00239             KeyRange range = db.getKeyRange(txn, key /*, args.flags == 0 */);
00240             reply.status = 0;
00241             reply.less = range.less;
00242             reply.equal = range.equal;
00243             reply.greater = range.greater;
00244         } catch (Throwable t) {
00245             reply.status = Util.handleException(t);
00246         }
00247     }
00248 
00249     private boolean findSharedDatabase(Dispatcher server, __db_open_reply reply)
00250         throws DatabaseException {
00251         RpcDb rdb = null;
00252         boolean matchFound = false;
00253         LocalIterator i = ((Server)server).db_list.iterator();
00254 
00255         while (!matchFound && i.hasNext()) {
00256             rdb = (RpcDb)i.next();
00257             if (rdb != null && rdb != this && rdb.rdbenv == rdbenv &&
00258                 (type == DbConstants.DB_UNKNOWN || rdb.type == type) &&
00259                 openflags == rdb.openflags &&
00260                 setflags == rdb.setflags &&
00261                 dbname != null && rdb.dbname != null &&
00262                 dbname.equals(rdb.dbname) &&
00263                 (subdbname == rdb.subdbname ||
00264                  (subdbname != null && rdb.subdbname != null &&
00265                   subdbname.equals(rdb.subdbname))))
00266                 matchFound = true;
00267         }
00268 
00269         if (matchFound) {
00270             ++rdb.refcount;
00271             reply.dbcl_id = ((FreeList.FreeListIterator)i).current;
00272             reply.type = Util.fromDatabaseType(rdb.config.getType());
00273             reply.lorder = rdb.config.getByteOrder();
00274             reply.status = 0;
00275 
00276             // Server.err.println("Sharing Database: " + reply.dbcl_id);
00277         }
00278 
00279         return matchFound;
00280     }
00281 
00282     public  void get_dbname(Dispatcher server,
00283                           __db_get_dbname_msg args, __db_get_dbname_reply reply) {
00284         reply.filename = dbname;
00285         reply.dbname = subdbname;
00286         reply.status = 0;
00287     }
00288 
00289     public  void get_open_flags(Dispatcher server,
00290                                 __db_get_open_flags_msg args, __db_get_open_flags_reply reply) {
00291         try {
00292             reply.flags = 0;
00293             if (config.getAllowCreate()) reply.flags |= DbConstants.DB_CREATE;
00294             if (config.getExclusiveCreate()) reply.flags |= DbConstants.DB_EXCL;
00295             if (config.getReadOnly()) reply.flags |= DbConstants.DB_RDONLY;
00296             reply.status = 0;
00297         } catch (Throwable t) {
00298             reply.status = Util.handleException(t);
00299         }
00300     }
00301 
00302     public  void open(Dispatcher server,
00303                       __db_open_msg args, __db_open_reply reply) {
00304         try {
00305             dbname = (args.name.length() > 0) ? args.name : null;
00306             subdbname = (args.subdb.length() > 0) ? args.subdb : null;
00307             type = args.type;
00308             openflags = args.flags & Server.DB_SERVER_DBFLAGS;
00309 
00310             if (findSharedDatabase(server, reply)) {
00311                 server.delDatabase(this, true);
00312             } else {
00313                 RpcDbTxn rtxn = server.getTxn(args.txnpcl_id);
00314                 Transaction txn = (rtxn != null) ? rtxn.txn : null;
00315 
00316                 // Server.err.println("Calling db.open(" + null + ", " + dbname + ", " + subdbname + ", " + args.type + ", " + Integer.toHexString(args.flags) + ", " + args.mode + ")");
00317 
00318                 config.setAllowCreate((args.flags & DbConstants.DB_CREATE) != 0);
00319                 config.setExclusiveCreate((args.flags & DbConstants.DB_EXCL) != 0);
00320                 config.setReadOnly((args.flags & DbConstants.DB_RDONLY) != 0);
00321                 config.setTransactional(txn != null || (args.flags & DbConstants.DB_AUTO_COMMIT) != 0);
00322                 config.setTruncate((args.flags & DbConstants.DB_TRUNCATE) != 0);
00323                 config.setType(Util.toDatabaseType(args.type));
00324                 config.setMode(args.mode);
00325 
00326                 db = rdbenv.dbenv.openDatabase(txn, dbname, subdbname, config);
00327                 ++refcount;
00328 
00329                 // Refresh config in case we didn't know the full story before opening
00330                 config = db.getConfig();
00331 
00332                 reply.dbcl_id = args.dbpcl_id;
00333                 type = reply.type = Util.fromDatabaseType(config.getType());
00334                 reply.lorder = config.getByteOrder();
00335                 reply.status = 0;
00336             }
00337         } catch (Throwable t) {
00338             reply.status = Util.handleException(t);
00339         }
00340 
00341         // System.err.println("Database.open: reply.status = " + reply.status + ", reply.dbcl_id = " + reply.dbcl_id);
00342     }
00343 
00344     public  void pget(Dispatcher server,
00345                       __db_pget_msg args, __db_pget_reply reply) {
00346         try {
00347             RpcDbTxn rtxn = server.getTxn(args.txnpcl_id);
00348             Transaction txn = (rtxn != null) ? rtxn.txn : null;
00349             DatabaseEntry skey = Util.makeDatabaseEntry(args.skeydata, args.skeydlen, args.skeydoff, args.skeyulen, args.skeyflags);
00350             DatabaseEntry pkey = Util.makeDatabaseEntry(args.pkeydata, args.pkeydlen, args.pkeydoff, args.pkeyulen, args.pkeyflags);
00351             DatabaseEntry data = Util.makeDatabaseEntry(args.datadata, args.datadlen, args.datadoff, args.dataulen, args.dataflags);
00352 
00353             OperationStatus status;
00354             switch(args.flags & ~Server.DB_MODIFIER_MASK) {
00355             case 0:
00356                 status = ((SecondaryDatabase)db).get(txn, skey, pkey, data, Util.getLockMode(args.flags));
00357                 break;
00358 
00359             case DbConstants.DB_GET_BOTH:
00360                 status = ((SecondaryDatabase)db).getSearchBoth(txn, skey, pkey, data, Util.getLockMode(args.flags));
00361                 break;
00362 
00363             case DbConstants.DB_SET_RECNO:
00364                 status = ((SecondaryDatabase)db).getSearchRecordNumber(txn, skey, pkey, data, Util.getLockMode(args.flags));
00365                 break;
00366 
00367             default:
00368                 throw new UnsupportedOperationException("Unknown flag: " + (args.flags & ~Server.DB_MODIFIER_MASK));
00369             }
00370             reply.status = Util.getStatus(status);
00371 
00372             reply.skeydata = Util.returnDatabaseEntry(skey);
00373             reply.pkeydata = Util.returnDatabaseEntry(pkey);
00374             reply.datadata = Util.returnDatabaseEntry(data);
00375         } catch (Throwable t) {
00376             reply.status = Util.handleException(t);
00377             reply.skeydata = reply.pkeydata = reply.datadata = empty;
00378         }
00379     }
00380 
00381     public  void put(Dispatcher server,
00382                      __db_put_msg args, __db_put_reply reply) {
00383         try {
00384             RpcDbTxn rtxn = server.getTxn(args.txnpcl_id);
00385             Transaction txn = (rtxn != null) ? rtxn.txn : null;
00386 
00387             DatabaseEntry key = Util.makeDatabaseEntry(args.keydata, args.keydlen, args.keydoff, args.keyulen, args.keyflags);
00388             DatabaseEntry data = Util.makeDatabaseEntry(args.datadata, args.datadlen, args.datadoff, args.dataulen, args.dataflags);
00389 
00390             reply.keydata = empty;
00391             OperationStatus status;
00392             switch(args.flags & ~Server.DB_MODIFIER_MASK) {
00393             case 0:
00394                 status = db.put(txn, key, data);
00395                 break;
00396 
00397             case DbConstants.DB_APPEND:
00398                 status = db.append(txn, key, data);
00399                 reply.keydata = Util.returnDatabaseEntry(key);
00400                 break;
00401 
00402             case DbConstants.DB_NODUPDATA:
00403                 status = db.putNoDupData(txn, key, data);
00404                 break;
00405 
00406             case DbConstants.DB_NOOVERWRITE:
00407                 status = db.putNoOverwrite(txn, key, data);
00408                 break;
00409 
00410             default:
00411                 throw new UnsupportedOperationException("Unknown flag: " + (args.flags & ~Server.DB_MODIFIER_MASK));
00412             }
00413             reply.status = Util.getStatus(status);
00414         } catch (Throwable t) {
00415             reply.status = Util.handleException(t);
00416             reply.keydata = empty;
00417         }
00418     }
00419 
00420     public  void remove(Dispatcher server,
00421                         __db_remove_msg args, __db_remove_reply reply) {
00422         try {
00423             args.name = (args.name.length() > 0) ? args.name : null;
00424             args.subdb = (args.subdb.length() > 0) ? args.subdb : null;
00425             Database.remove(args.name, args.subdb, config);
00426             reply.status = 0;
00427         } catch (Throwable t) {
00428             reply.status = Util.handleException(t);
00429         } finally {
00430             server.delDatabase(this, false);
00431         }
00432     }
00433 
00434     public  void rename(Dispatcher server,
00435                         __db_rename_msg args, __db_rename_reply reply) {
00436         try {
00437             args.name = (args.name.length() > 0) ? args.name : null;
00438             args.subdb = (args.subdb.length() > 0) ? args.subdb : null;
00439             args.newname = (args.newname.length() > 0) ? args.newname : null;
00440             Database.rename(args.name, args.subdb, args.newname, config);
00441             reply.status = 0;
00442         } catch (Throwable t) {
00443             reply.status = Util.handleException(t);
00444         } finally {
00445             server.delDatabase(this, false);
00446         }
00447     }
00448 
00449     public  void get_bt_minkey(Dispatcher server,
00450                                __db_get_bt_minkey_msg args, __db_get_bt_minkey_reply reply) {
00451         try {
00452             reply.minkey = config.getBtreeMinKey();
00453             reply.status = 0;
00454         } catch (Throwable t) {
00455             reply.status = Util.handleException(t);
00456         }
00457     }
00458 
00459     public  void set_bt_minkey(Dispatcher server,
00460                                __db_set_bt_minkey_msg args, __db_set_bt_minkey_reply reply) {
00461         try {
00462             config.setBtreeMinKey(args.minkey);
00463             reply.status = 0;
00464         } catch (Throwable t) {
00465             reply.status = Util.handleException(t);
00466         }
00467     }
00468 
00469     public  void get_encrypt_flags(Dispatcher server,
00470                                    __db_get_encrypt_flags_msg args, __db_get_encrypt_flags_reply reply) {
00471         try {
00472             reply.flags = config.getEncrypted() ? DbConstants.DB_ENCRYPT_AES : 0;
00473             reply.status = 0;
00474         } catch (Throwable t) {
00475             reply.status = Util.handleException(t);
00476         }
00477     }
00478 
00479     public  void set_encrypt(Dispatcher server,
00480                              __db_set_encrypt_msg args, __db_set_encrypt_reply reply) {
00481         try {
00482             config.setEncrypted(args.passwd /*, args.flags == 0 */);
00483             reply.status = 0;
00484         } catch (Throwable t) {
00485             reply.status = Util.handleException(t);
00486         }
00487     }
00488 
00489     public  void get_flags(Dispatcher server,
00490                            __db_get_flags_msg args, __db_get_flags_reply reply) {
00491         try {
00492             reply.flags = 0;
00493             if (config.getChecksum()) reply.flags |= DbConstants.DB_CHKSUM;
00494             if (config.getEncrypted()) reply.flags |= DbConstants.DB_ENCRYPT;
00495             if (config.getBtreeRecordNumbers()) reply.flags |= DbConstants.DB_RECNUM;
00496             if (config.getRenumbering()) reply.flags |= DbConstants.DB_RENUMBER;
00497             if (config.getReverseSplitOff()) reply.flags |= DbConstants.DB_REVSPLITOFF;
00498             if (config.getSortedDuplicates()) reply.flags |= DbConstants.DB_DUPSORT;
00499             if (config.getSnapshot()) reply.flags |= DbConstants.DB_SNAPSHOT;
00500             if (config.getUnsortedDuplicates()) reply.flags |= DbConstants.DB_DUP;
00501             if (config.getTransactionNotDurable()) reply.flags |= DbConstants.DB_TXN_NOT_DURABLE;
00502             reply.status = 0;
00503         } catch (Throwable t) {
00504             reply.status = Util.handleException(t);
00505         }
00506     }
00507 
00508     public  void set_flags(Dispatcher server,
00509                            __db_set_flags_msg args, __db_set_flags_reply reply) {
00510         try {
00511             // Server.err.println("Calling db.setflags(" + Integer.toHexString(args.flags) + ")");
00512             config.setChecksum((args.flags & DbConstants.DB_CHKSUM) != 0);
00513             config.setBtreeRecordNumbers((args.flags & DbConstants.DB_RECNUM) != 0);
00514             config.setRenumbering((args.flags & DbConstants.DB_RENUMBER) != 0);
00515             config.setReverseSplitOff((args.flags & DbConstants.DB_REVSPLITOFF) != 0);
00516             config.setSortedDuplicates((args.flags & DbConstants.DB_DUPSORT) != 0);
00517             config.setSnapshot((args.flags & DbConstants.DB_SNAPSHOT) != 0);
00518             config.setUnsortedDuplicates((args.flags & DbConstants.DB_DUP) != 0);
00519             config.setTransactionNotDurable((args.flags & DbConstants.DB_TXN_NOT_DURABLE) != 0);
00520 
00521             setflags |= args.flags;
00522             reply.status = 0;
00523         } catch (Throwable t) {
00524             reply.status = Util.handleException(t);
00525         }
00526     }
00527 
00528     public  void get_h_ffactor(Dispatcher server,
00529                                __db_get_h_ffactor_msg args, __db_get_h_ffactor_reply reply) {
00530         try {
00531             reply.ffactor = config.getHashFillFactor();
00532             reply.status = 0;
00533         } catch (Throwable t) {
00534             reply.status = Util.handleException(t);
00535         }
00536     }
00537 
00538     public  void set_h_ffactor(Dispatcher server,
00539                                __db_set_h_ffactor_msg args, __db_set_h_ffactor_reply reply) {
00540         try {
00541             config.setHashFillFactor(args.ffactor);
00542             reply.status = 0;
00543         } catch (Throwable t) {
00544             reply.status = Util.handleException(t);
00545         }
00546     }
00547 
00548     public  void get_h_nelem(Dispatcher server,
00549                              __db_get_h_nelem_msg args, __db_get_h_nelem_reply reply) {
00550         try {
00551             reply.nelem = config.getHashNumElements();
00552             reply.status = 0;
00553         } catch (Throwable t) {
00554             reply.status = Util.handleException(t);
00555         }
00556     }
00557 
00558     public  void set_h_nelem(Dispatcher server,
00559                              __db_set_h_nelem_msg args, __db_set_h_nelem_reply reply) {
00560         try {
00561             config.setHashNumElements(args.nelem);
00562             reply.status = 0;
00563         } catch (Throwable t) {
00564             reply.status = Util.handleException(t);
00565         }
00566     }
00567 
00568     public  void get_lorder(Dispatcher server,
00569                             __db_get_lorder_msg args, __db_get_lorder_reply reply) {
00570         try {
00571             reply.lorder = config.getByteOrder();
00572             reply.status = 0;
00573         } catch (Throwable t) {
00574             reply.status = Util.handleException(t);
00575         }
00576     }
00577 
00578     public  void set_lorder(Dispatcher server,
00579                             __db_set_lorder_msg args, __db_set_lorder_reply reply) {
00580         try {
00581             config.setByteOrder(args.lorder);
00582             reply.status = 0;
00583         } catch (Throwable t) {
00584             reply.status = Util.handleException(t);
00585         }
00586     }
00587 
00588     public  void get_pagesize(Dispatcher server,
00589                               __db_get_pagesize_msg args, __db_get_pagesize_reply reply) {
00590         try {
00591             reply.pagesize = config.getPageSize();
00592             reply.status = 0;
00593         } catch (Throwable t) {
00594             reply.status = Util.handleException(t);
00595         }
00596     }
00597 
00598     public  void set_pagesize(Dispatcher server,
00599                               __db_set_pagesize_msg args, __db_set_pagesize_reply reply) {
00600         try {
00601             config.setPageSize(args.pagesize);
00602             reply.status = 0;
00603         } catch (Throwable t) {
00604             reply.status = Util.handleException(t);
00605         }
00606     }
00607 
00608     public  void get_q_extentsize(Dispatcher server,
00609                                   __db_get_q_extentsize_msg args, __db_get_q_extentsize_reply reply) {
00610         try {
00611             reply.extentsize = config.getQueueExtentSize();
00612             reply.status = 0;
00613         } catch (Throwable t) {
00614             reply.status = Util.handleException(t);
00615         }
00616     }
00617 
00618     public  void set_q_extentsize(Dispatcher server,
00619                                   __db_set_q_extentsize_msg args, __db_set_q_extentsize_reply reply) {
00620         try {
00621             config.setQueueExtentSize(args.extentsize);
00622             reply.status = 0;
00623         } catch (Throwable t) {
00624             reply.status = Util.handleException(t);
00625         }
00626     }
00627 
00628     public  void get_re_delim(Dispatcher server,
00629                               __db_get_re_delim_msg args, __db_get_re_delim_reply reply) {
00630         try {
00631             reply.delim = config.getRecordDelimiter();
00632             reply.status = 0;
00633         } catch (Throwable t) {
00634             reply.status = Util.handleException(t);
00635         }
00636     }
00637 
00638     public  void set_re_delim(Dispatcher server,
00639                               __db_set_re_delim_msg args, __db_set_re_delim_reply reply) {
00640         try {
00641             config.setRecordDelimiter(args.delim);
00642             reply.status = 0;
00643         } catch (Throwable t) {
00644             reply.status = Util.handleException(t);
00645         }
00646     }
00647 
00648     public  void get_re_len(Dispatcher server,
00649                             __db_get_re_len_msg args, __db_get_re_len_reply reply) {
00650         try {
00651             reply.len = config.getRecordLength();
00652             reply.status = 0;
00653         } catch (Throwable t) {
00654             reply.status = Util.handleException(t);
00655         }
00656     }
00657 
00658     public  void set_re_len(Dispatcher server,
00659                             __db_set_re_len_msg args, __db_set_re_len_reply reply) {
00660         try {
00661             config.setRecordLength(args.len);
00662             reply.status = 0;
00663         } catch (Throwable t) {
00664             reply.status = Util.handleException(t);
00665         }
00666     }
00667 
00668     public  void get_re_pad(Dispatcher server,
00669                             __db_get_re_pad_msg args, __db_get_re_pad_reply reply) {
00670         try {
00671             reply.pad = config.getRecordPad();
00672             reply.status = 0;
00673         } catch (Throwable t) {
00674             reply.status = Util.handleException(t);
00675         }
00676     }
00677 
00678     public  void set_re_pad(Dispatcher server,
00679                             __db_set_re_pad_msg args, __db_set_re_pad_reply reply) {
00680         try {
00681             config.setRecordPad(args.pad);
00682             reply.status = 0;
00683         } catch (Throwable t) {
00684             reply.status = Util.handleException(t);
00685         }
00686     }
00687 
00688     public  void stat(Dispatcher server,
00689                       __db_stat_msg args, __db_stat_reply reply) {
00690         try {
00691             RpcDbTxn rtxn = server.getTxn(args.txnpcl_id);
00692             Transaction txn = (rtxn != null) ? rtxn.txn : null;
00693             StatsConfig config = new StatsConfig();
00694             config.setClear((args.flags & DbConstants.DB_STAT_CLEAR) != 0);
00695             config.setFast((args.flags & DbConstants.DB_FAST_STAT) != 0);
00696             DatabaseStats raw_stat = db.getStats(txn, config);
00697 
00698             if (raw_stat instanceof BtreeStats) {
00699                 BtreeStats bs = (BtreeStats)raw_stat;
00700                 int[] raw_stats = {
00701                     bs.getMagic(), bs.getVersion(),
00702                     bs.getMetaFlags(), bs.getNumKeys(),
00703                     bs.getNumData(), bs.getPageSize(),
00704                     bs.getMinKey(),
00705                     bs.getReLen(), bs.getRePad(),
00706                     bs.getLevels(), bs.getIntPages(),
00707                     bs.getLeafPages(), bs.getDupPages(),
00708                     bs.getOverPages(), bs.getFree(),
00709                     bs.getIntPagesFree(), bs.getLeafPagesFree(),
00710                     bs.getDupPagesFree(), bs.getOverPagesFree()
00711                 };
00712                 reply.stats = raw_stats;
00713             } else if (raw_stat instanceof HashStats) {
00714                 HashStats hs = (HashStats)raw_stat;
00715                 int[] raw_stats = {
00716                     hs.getMagic(), hs.getVersion(),
00717                     hs.getMetaFlags(), hs.getNumKeys(),
00718                     hs.getNumData(), hs.getPageSize(),
00719                     hs.getFfactor(), hs.getBuckets(),
00720                     hs.getFree(), hs.getBFree(),
00721                     hs.getBigPages(), hs.getBigBFree(),
00722                     hs.getOverflows(), hs.getOvflFree(),
00723                     hs.getDup(), hs.getDupFree()
00724                 };
00725                 reply.stats = raw_stats;
00726             } else if (raw_stat instanceof QueueStats) {
00727                 QueueStats qs = (QueueStats)raw_stat;
00728                 int[] raw_stats = {
00729                     qs.getMagic(), qs.getVersion(),
00730                     qs.getMetaFlags(), qs.getNumKeys(),
00731                     qs.getNumData(), qs.getPageSize(),
00732                     qs.getExtentSize(), qs.getPages(),
00733                     qs.getReLen(), qs.getRePad(),
00734                     qs.getPagesFree(), qs.getFirstRecno(),
00735                     qs.getCurRecno()
00736                 };
00737                 reply.stats = raw_stats;
00738             } else
00739                 throw new DatabaseException("Invalid return type from db.stat()", DbConstants.DB_NOTFOUND);
00740 
00741             reply.status = 0;
00742         } catch (Throwable t) {
00743             reply.status = Util.handleException(t);
00744             reply.stats = new int[0];
00745         }
00746     }
00747 
00748     public  void sync(Dispatcher server,
00749                       __db_sync_msg args, __db_sync_reply reply) {
00750         try {
00751             db.sync(/* args.flags == 0 */);
00752             reply.status = 0;
00753         } catch (Throwable t) {
00754             reply.status = Util.handleException(t);
00755         }
00756     }
00757 
00758     public  void truncate(Dispatcher server,
00759                           __db_truncate_msg args, __db_truncate_reply reply) {
00760         try {
00761             RpcDbTxn rtxn = server.getTxn(args.txnpcl_id);
00762             Transaction txn = (rtxn != null) ? rtxn.txn : null;
00763             reply.count = db.truncate(txn, true /*, args.flags == 0 */);
00764             reply.status = 0;
00765         } catch (Throwable t) {
00766             reply.status = Util.handleException(t);
00767             reply.count = 0;
00768         }
00769     }
00770 }

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