001: /*
002: $Header: /cvsroot/xorm/xorm/src/org/xorm/Options.java,v 1.1 2002/09/21 23:29:45 wbiggs Exp $
003:
004: This file is part of XORM.
005:
006: XORM is free software; you can redistribute it and/or modify
007: it under the terms of the GNU General Public License as published by
008: the Free Software Foundation; either version 2 of the License, or
009: (at your option) any later version.
010:
011: XORM is distributed in the hope that it will be useful,
012: but WITHOUT ANY WARRANTY; without even the implied warranty of
013: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: GNU General Public License for more details.
015:
016: You should have received a copy of the GNU General Public License
017: along with XORM; if not, write to the Free Software
018: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
019: */
020: package org.xorm;
021:
022: import java.io.Serializable;
023: import java.util.BitSet;
024:
025: import javax.jdo.JDOUnsupportedOptionException;
026:
027: /**
028: * This class encapsulates the JDO options associated with many
029: * JDO interfaces. It can be extended or used via a wrapper pattern.
030: *
031: * @author Wes Biggs
032: */
033: public class Options implements Cloneable, Serializable {
034: public static final int NONTRANSACTIONAL_READ = 0,
035: NONTRANSACTIONAL_WRITE = 1, RETAIN_VALUES = 2,
036: OPTIMISTIC = 3, RESTORE_VALUES = 4;
037:
038: protected BitSet optionsFlags = new BitSet(5);
039:
040: /**
041: * Returns a deep clone of this instance.
042: */
043: public Object clone() {
044: Options clone = null;
045: try {
046: clone = (Options) super .clone();
047: clone.optionsFlags = (BitSet) optionsFlags.clone();
048: } catch (CloneNotSupportedException ignored) {
049: }
050: return clone;
051: }
052:
053: public void setNontransactionalRead(boolean nontransactionalRead) {
054: optionsFlags.set(NONTRANSACTIONAL_READ, nontransactionalRead);
055: }
056:
057: public boolean getNontransactionalRead() {
058: return optionsFlags.get(NONTRANSACTIONAL_READ);
059: }
060:
061: public void setNontransactionalWrite(boolean nontransactionalWrite) {
062: if (nontransactionalWrite) {
063: throw new JDOUnsupportedOptionException();
064: }
065: optionsFlags.set(NONTRANSACTIONAL_WRITE, nontransactionalWrite);
066: }
067:
068: public boolean getNontransactionalWrite() {
069: return optionsFlags.get(NONTRANSACTIONAL_WRITE);
070: }
071:
072: public void setRetainValues(boolean retainValues) {
073: optionsFlags.set(RETAIN_VALUES, retainValues);
074: }
075:
076: public boolean getRetainValues() {
077: return optionsFlags.get(RETAIN_VALUES);
078: }
079:
080: public void setOptimistic(boolean optimistic) {
081: if (optimistic) {
082: throw new JDOUnsupportedOptionException();
083: }
084: optionsFlags.set(OPTIMISTIC, optimistic);
085: }
086:
087: public boolean getOptimistic() {
088: return optionsFlags.get(OPTIMISTIC);
089: }
090:
091: public void setRestoreValues(boolean restoreValues) {
092: if (restoreValues) {
093: throw new JDOUnsupportedOptionException();
094: }
095: optionsFlags.set(RESTORE_VALUES, restoreValues);
096: }
097:
098: public boolean getRestoreValues() {
099: return optionsFlags.get(RESTORE_VALUES);
100: }
101: }
|