01: /* Copyright (C) 2004 - 2007 db4objects Inc. http://www.db4o.com
02:
03: This file is part of the db4o open source object database.
04:
05: db4o is free software; you can redistribute it and/or modify it under
06: the terms of version 2 of the GNU General Public License as published
07: by the Free Software Foundation and as clarified by db4objects' GPL
08: interpretation policy, available at
09: http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
10: Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
11: Suite 350, San Mateo, CA 94403, USA.
12:
13: db4o is distributed in the hope that it will be useful, but WITHOUT ANY
14: WARRANTY; without even the implied warranty of MERCHANTABILITY or
15: FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16: for more details.
17:
18: You should have received a copy of the GNU General Public License along
19: with this program; if not, write to the Free Software Foundation, Inc.,
20: 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
21: package com.db4o.internal.fileheader;
22:
23: import com.db4o.*;
24: import com.db4o.ext.*;
25: import com.db4o.internal.*;
26:
27: /**
28: * @exclude
29: */
30: public class FileHeaderVariablePart1 extends PersistentBase {
31:
32: // The variable part format is:
33:
34: // (int) converter version
35: // (byte) freespace system used
36: // (int) freespace address
37: // (int) identity ID
38: // (long) versionGenerator
39: // (int) uuid index ID
40:
41: private static final int LENGTH = 1 + (Const4.INT_LENGTH * 4)
42: + Const4.LONG_LENGTH + Const4.ADDED_LENGTH;
43:
44: private final SystemData _systemData;
45:
46: public FileHeaderVariablePart1(int id, SystemData systemData) {
47: setID(id);
48: _systemData = systemData;
49: }
50:
51: SystemData systemData() {
52: return _systemData;
53: }
54:
55: public byte getIdentifier() {
56: return Const4.HEADER;
57: }
58:
59: public int ownLength() {
60: return LENGTH;
61: }
62:
63: public void readThis(Transaction trans, Buffer reader) {
64: _systemData.converterVersion(reader.readInt());
65: _systemData.freespaceSystem(reader.readByte());
66: _systemData.freespaceAddress(reader.readInt());
67: readIdentity((LocalTransaction) trans, reader.readInt());
68: _systemData.lastTimeStampID(reader.readLong());
69: _systemData.uuidIndexId(reader.readInt());
70: }
71:
72: public void writeThis(Transaction trans, Buffer writer) {
73: writer.writeInt(_systemData.converterVersion());
74: writer.writeByte(_systemData.freespaceSystem());
75: writer.writeInt(_systemData.freespaceAddress());
76: writer.writeInt(_systemData.identity().getID(trans));
77: writer.writeLong(_systemData.lastTimeStampID());
78: writer.writeInt(_systemData.uuidIndexId());
79: }
80:
81: private void readIdentity(LocalTransaction trans, int identityID) {
82: LocalObjectContainer file = trans.file();
83: Db4oDatabase identity = Debug.staticIdentity ? Db4oDatabase.STATIC_IDENTITY
84: : (Db4oDatabase) file.getByID(trans, identityID);
85: file.activate(trans, identity, 2);
86: _systemData.identity(identity);
87: }
88:
89: }
|