001: /*
002: Copyright (C) 2007 Mobixess Inc. http://www.java-objects-database.com
003:
004: This file is part of the JODB (Java Objects Database) open source project.
005:
006: JODB is free software; you can redistribute it and/or modify it under
007: the terms of version 2 of the GNU General Public License as published
008: by the Free Software Foundation.
009:
010: JODB is distributed in the hope that it will be useful, but WITHOUT ANY
011: WARRANTY; without even the implied warranty of MERCHANTABILITY or
012: FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
013: for more details.
014:
015: You should have received a copy of the GNU General Public License along
016: with this program; if not, write to the Free Software Foundation, Inc.,
017: 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
018: */
019: package com.mobixess.jodb.core.transaction;
020:
021: import java.util.Vector;
022:
023: import com.mobixess.jodb.core.index.IndexingRecord;
024:
025: public class TransactionHandle {
026:
027: private final static byte SET_TRANSACTION = 1 << 0;
028: private final static byte DELETE_TRANSACTION = 1 << 1;
029: private final static byte MARKED_AS_UNCHANGED = 1 << 2;
030:
031: private final static byte GENERATE_CREATION_TS = 1 << 3;
032: private final static byte GENERATE_MODIFICATION_TS = 1 << 4;
033:
034: private final static byte AGENT_OBJECT_BIT = 1 << 5;
035:
036: private byte _transactionStateMask;
037: private byte _translatedObjectDataMask;
038: private long _transactionOffset = -1;
039: private Vector<IndexingRecord> _indexes;
040: private PersistentObjectHandle _handle;
041:
042: public TransactionHandle(PersistentObjectHandle handle) {
043: this (handle.hasCreationTSField(), handle
044: .hasModificationTSField());
045: _handle = handle;
046: }
047:
048: public TransactionHandle(boolean creationTS, boolean modificationTS) {
049: super ();
050: if (creationTS) {
051: setCreationTSBit();
052: }
053: if (modificationTS) {
054: setModificationTSBit();
055: }
056: }
057:
058: private void setCreationTSBit() {
059: _transactionStateMask = (byte) ((_transactionStateMask & 0xFF) | GENERATE_CREATION_TS);
060: }
061:
062: private void setModificationTSBit() {
063: _transactionStateMask = (byte) ((_transactionStateMask & 0xFF) | GENERATE_MODIFICATION_TS);
064: }
065:
066: public boolean generateCreationTS() {
067: return ((_transactionStateMask & 0xFF) & GENERATE_CREATION_TS) != 0;
068: }
069:
070: public boolean generateModificationTS() {
071: return ((_transactionStateMask & 0xFF) & GENERATE_MODIFICATION_TS) != 0;
072: }
073:
074: public void enable_SET_TransactionState() {
075: _transactionStateMask &= ~DELETE_TRANSACTION;
076: _transactionStateMask |= SET_TRANSACTION;
077: }
078:
079: public void enable_DELETE_TransactionState() {
080: _transactionStateMask &= ~SET_TRANSACTION;
081: _transactionStateMask |= DELETE_TRANSACTION;
082: }
083:
084: public void disableTransactionStates() {
085: _transactionStateMask |= ~SET_TRANSACTION;
086: _transactionStateMask |= ~DELETE_TRANSACTION;
087: }
088:
089: public void markAsUnchanged() {
090: _transactionStateMask |= MARKED_AS_UNCHANGED;
091: }
092:
093: public boolean isUnchanged() {
094: return (_transactionStateMask & MARKED_AS_UNCHANGED) != 0;
095: }
096:
097: public boolean is_SET_Transaction() {
098: return (_transactionStateMask & SET_TRANSACTION) != 0;
099: }
100:
101: public boolean is_DELETE_Transaction() {
102: return (_transactionStateMask & DELETE_TRANSACTION) != 0;
103: }
104:
105: public PersistentObjectHandle getHandle() {
106: return _handle;
107: }
108:
109: public boolean generateUID() {
110: return false;
111: }
112:
113: public boolean isNewObject() {
114: return _handle == null;
115: }
116:
117: public void setTransactionOffset(long transactionOffset) {
118: _transactionOffset = transactionOffset;
119: }
120:
121: public long getTransactionOffset() {
122: return _transactionOffset;
123: }
124:
125: public boolean isTranslated() {
126: return _transactionOffset != -1;
127: }
128:
129: public void setTranslatedObjectDataMask(
130: byte translatedObjectDataMask) {
131: _translatedObjectDataMask = translatedObjectDataMask;
132: }
133:
134: public byte getTranslatedObjectDataMask() {
135: return _translatedObjectDataMask;
136: }
137:
138: public Vector<IndexingRecord> getIndexes() {
139: return _indexes;
140: }
141:
142: public void setIndexes(Vector<IndexingRecord> indexes) {
143: _indexes = indexes;
144: }
145:
146: public void setAgentObjectMode(boolean isAgent) {
147: if (isAgent) {
148: _transactionStateMask |= AGENT_OBJECT_BIT;
149: } else {
150: _transactionStateMask &= ~AGENT_OBJECT_BIT;
151: }
152: }
153:
154: public boolean isAgent() {
155: return (_transactionStateMask & AGENT_OBJECT_BIT) != 0;
156: }
157:
158: }
|