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.index;
20:
21: import java.nio.ByteBuffer;
22: import java.util.Vector;
23:
24: /**
25: * Simple class to hold index field and data correspondence
26: *
27: * @author Mobixess
28: *
29: */
30: public class IndexingRecord {
31: private ByteBuffer _persistedDataBuffer = ByteBuffer.allocate(8);
32: private ByteBuffer _pendingDataBuffer = ByteBuffer.allocate(8);
33: private JODBIndexingAgent _indexingAgent;
34:
35: public ByteBuffer getPersistedDataBuffer() {
36: return _persistedDataBuffer;
37: }
38:
39: public ByteBuffer getPendingDataBuffer() {
40: return _pendingDataBuffer;
41: }
42:
43: public JODBIndexingAgent getIndexingAgent() {
44: return _indexingAgent;
45: }
46:
47: public void setIndexingAgent(JODBIndexingAgent indexingAgent) {
48: _indexingAgent = indexingAgent;
49: }
50:
51: public void reset() {
52: _indexingAgent = null;
53: _persistedDataBuffer.clear();
54: _persistedDataBuffer.limit(0);
55: _pendingDataBuffer.clear();
56: _pendingDataBuffer.limit(0);
57: }
58:
59: public void setPersistedDataBufferValue(ByteBuffer value) {
60: _persistedDataBuffer.clear();
61: _persistedDataBuffer.limit(value.limit());
62: _persistedDataBuffer.put(value);
63: _persistedDataBuffer.flip();
64: }
65:
66: public void setPendingDataBufferValue(ByteBuffer value) {
67: _pendingDataBuffer.put(value.array(), 0, value.limit());
68: _pendingDataBuffer.limit(value.limit());
69: }
70:
71: public static IndexingRecord findIndexingRecord(int fieldId,
72: Vector<IndexingRecord> indexes) {
73: if (indexes == null) {
74: return null;
75: }
76: for (int i = 0; i < indexes.size(); i++) {
77: IndexingRecord record = indexes.elementAt(i);
78: if (record.getIndexingAgent().getFieldId() == fieldId) {
79: return record;
80: }
81: }
82: return null;
83: }
84:
85: @Override
86: public boolean equals(Object obj) {
87: return _indexingAgent == ((IndexingRecord) obj)._indexingAgent;
88: }
89: }
|