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

CursorConfig.java

00001 /*-
00002  * See the file LICENSE for redistribution information.
00003  *
00004  * Copyright (c) 2002-2005
00005  *      Sleepycat Software.  All rights reserved.
00006  *
00007  * $Id: CursorConfig.java,v 12.2 2005/06/16 20:22:59 bostic Exp $
00008  */
00009 
00010 package com.sleepycat.db;
00011 
00012 import com.sleepycat.db.internal.DbConstants;
00013 import com.sleepycat.db.internal.Db;
00014 import com.sleepycat.db.internal.Dbc;
00015 import com.sleepycat.db.internal.DbTxn;
00016 
00017 public class CursorConfig implements Cloneable {
00018     public static final CursorConfig DEFAULT = new CursorConfig();
00019 
00020     public static final CursorConfig READ_UNCOMMITTED = new CursorConfig();
00021     static { READ_UNCOMMITTED.setReadUncommitted(true); }
00022 
00023     public static final CursorConfig READ_COMMITTED = new CursorConfig();
00024     static { READ_COMMITTED.setReadCommitted(true); }
00025 
00026     public static final CursorConfig WRITECURSOR = new CursorConfig();
00027     static { WRITECURSOR.setWriteCursor(true); }
00028 
00030     public static final CursorConfig DIRTY_READ = READ_UNCOMMITTED;
00032     public static final CursorConfig DEGREE_2 = READ_COMMITTED;
00033 
00034     private boolean readUncommitted = false;
00035     private boolean readCommitted = false;
00036     private boolean writeCursor = false;
00037 
00038     public CursorConfig() {
00039     }
00040 
00041     /* package */
00042     static CursorConfig checkNull(CursorConfig config) {
00043         return (config == null) ? DEFAULT : config;
00044     }
00045 
00046     public void setReadCommitted(final boolean readCommitted) {
00047         this.readCommitted = readCommitted;
00048     }
00049     
00050     public boolean getReadCommitted() {
00051         return readCommitted;
00052     }
00053 
00055     public void setDegree2(final boolean degree2) {
00056         setReadCommitted(degree2);
00057     }
00058 
00060     public boolean getDegree2() {
00061         return getReadCommitted();
00062     }
00063 
00064     public void setReadUncommitted(final boolean readUncommitted) {
00065         this.readUncommitted = readUncommitted;
00066     }
00067 
00068     public boolean getReadUncommitted() {
00069         return readUncommitted;
00070     }
00071 
00073     public void setDirtyRead(final boolean dirtyRead) {
00074         setReadUncommitted(dirtyRead);
00075     }
00076 
00078     public boolean getDirtyRead() {
00079         return getReadUncommitted();
00080     }
00081 
00082     public void setWriteCursor(final boolean writeCursor) {
00083         this.writeCursor = writeCursor;
00084     }
00085 
00086     public boolean getWriteCursor() {
00087         return writeCursor;
00088     }
00089 
00090     /* package */
00091     Dbc openCursor(final Db db, final DbTxn txn)
00092         throws DatabaseException {
00093 
00094         int flags = 0;
00095         flags |= readUncommitted ? DbConstants.DB_READ_UNCOMMITTED : 0;
00096         flags |= readCommitted ? DbConstants.DB_READ_COMMITTED : 0;
00097         flags |= writeCursor ? DbConstants.DB_WRITECURSOR : 0;
00098         return db.cursor(txn, flags);
00099     }
00100 }

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