01: /*
02: Copyright (C) 2007 Mobixess Inc. http://www.java-objects-database.com
03:
04: This file is part of the JODB (Java Objects Database) open source project.
05:
06: JODB is free software; you can redistribute it and/or modify it under
07: the terms of version 2 of the GNU General Public License as published
08: by the Free Software Foundation.
09:
10: JODB is distributed in the hope that it will be useful, but WITHOUT ANY
11: WARRANTY; without even the implied warranty of MERCHANTABILITY or
12: FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13: for more details.
14:
15: You should have received a copy of the GNU General Public License along
16: with this program; if not, write to the Free Software Foundation, Inc.,
17: 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18: */
19: package com.mobixess.jodb.core.transaction;
20:
21: import com.mobixess.jodb.core.io.ObjectDataContainer;
22:
23: /**
24: * @author Mobixess
25: *
26: */
27: public class PersistentObjectHandle {
28:
29: private byte _dataMask;
30: private long _offset;
31: private ActiveObjectWeakRefHolder _reference;
32:
33: public PersistentObjectHandle() {
34: }
35:
36: /*package*/PersistentObjectHandle(
37: ActiveObjectWeakRefHolder reference, byte dataMask,
38: long offset) {
39: super ();
40: _reference = reference;
41: _dataMask = dataMask;
42: _offset = offset;
43: }
44:
45: public long getObjectEntryOffset() {
46: return _offset;
47: }
48:
49: public void setObjectEntryOffset(long offset) {
50: _offset = offset;
51: }
52:
53: public boolean isPersistent() {
54: return _offset >= 0;
55: }
56:
57: public long getDataMask() {
58: return _dataMask;
59: }
60:
61: public boolean hasCreationTSField() {
62: return ObjectDataContainer.hasCreationTSBit(_dataMask & 0xFF);
63: }
64:
65: public boolean hasModificationTSField() {
66: return ObjectDataContainer
67: .hasModificationTSBit(_dataMask & 0xFF);
68: }
69:
70: @Override
71: public int hashCode() {
72: return (int) (_offset ^ (_offset >>> 32));
73: }
74:
75: @Override
76: public boolean equals(Object obj) {
77: if (obj == this ) {
78: return true;
79: }
80: if (obj == null || !(obj instanceof PersistentObjectHandle)) {
81: return false;
82: }
83: return ((PersistentObjectHandle) obj)._offset == _offset;
84: }
85:
86: public Object getObject() {
87: if (_reference == null) {
88: return null;
89: }
90: return _reference.get();
91: }
92:
93: public ActiveObjectWeakRefHolder getReference() {
94: return _reference;
95: }
96: }
|