Source Code Cross Referenced for FileHeader1.java in  » Database-DBMS » db4o-6.4 » com » db4o » internal » fileheader » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Database DBMS » db4o 6.4 » com.db4o.internal.fileheader 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* Copyright (C) 2004 - 2007  db4objects Inc.  http://www.db4o.com
002:
003:        This file is part of the db4o open source object database.
004:
005:        db4o is free software; you can redistribute it and/or modify it under
006:        the terms of version 2 of the GNU General Public License as published
007:        by the Free Software Foundation and as clarified by db4objects' GPL 
008:        interpretation policy, available at
009:        http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
010:        Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
011:        Suite 350, San Mateo, CA 94403, USA.
012:
013:        db4o is distributed in the hope that it will be useful, but WITHOUT ANY
014:        WARRANTY; without even the implied warranty of MERCHANTABILITY or
015:        FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
016:        for more details.
017:
018:        You should have received a copy of the GNU General Public License along
019:        with this program; if not, write to the Free Software Foundation, Inc.,
020:        59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. */
021:        package com.db4o.internal.fileheader;
022:
023:        import com.db4o.Db4oIOException;
024:        import com.db4o.internal.*;
025:
026:        /**
027:         * @exclude
028:         */
029:        public class FileHeader1 extends FileHeader {
030:
031:            // The header format is:
032:
033:            // (byte) 'd'
034:            // (byte) 'b'
035:            // (byte) '4'
036:            // (byte) 'o'
037:            // (byte) headerVersion
038:            // (int) headerLock
039:            // (long) openTime
040:            // (long) accessTime
041:            // (int) Transaction pointer 1
042:            // (int) Transaction pointer 2
043:            // (int) blockSize
044:            // (int) classCollectionID
045:            // (int) freespaceID
046:            // (int) variablePartID
047:
048:            private static final byte[] SIGNATURE = { (byte) 'd', (byte) 'b',
049:                    (byte) '4', (byte) 'o' };
050:
051:            private static byte VERSION = 1;
052:
053:            private static final int HEADER_LOCK_OFFSET = SIGNATURE.length + 1;
054:            private static final int OPEN_TIME_OFFSET = HEADER_LOCK_OFFSET
055:                    + Const4.INT_LENGTH;
056:            private static final int ACCESS_TIME_OFFSET = OPEN_TIME_OFFSET
057:                    + Const4.LONG_LENGTH;
058:            private static final int TRANSACTION_POINTER_OFFSET = ACCESS_TIME_OFFSET
059:                    + Const4.LONG_LENGTH;
060:
061:            public static final int LENGTH = TRANSACTION_POINTER_OFFSET
062:                    + (Const4.INT_LENGTH * 6);
063:
064:            private TimerFileLock _timerFileLock;
065:
066:            private Transaction _interruptedTransaction;
067:
068:            private FileHeaderVariablePart1 _variablePart;
069:
070:            public void close() throws Db4oIOException {
071:                _timerFileLock.close();
072:            }
073:
074:            public void initNew(LocalObjectContainer file)
075:                    throws Db4oIOException {
076:                commonTasksForNewAndRead(file);
077:                _variablePart = new FileHeaderVariablePart1(0, file
078:                        .systemData());
079:                writeVariablePart(file, 0);
080:            }
081:
082:            protected FileHeader newOnSignatureMatch(LocalObjectContainer file,
083:                    Buffer reader) {
084:                if (signatureMatches(reader, SIGNATURE, VERSION)) {
085:                    return new FileHeader1();
086:                }
087:                return null;
088:            }
089:
090:            private void newTimerFileLock(LocalObjectContainer file) {
091:                _timerFileLock = TimerFileLock.forFile(file);
092:                _timerFileLock.setAddresses(0, OPEN_TIME_OFFSET,
093:                        ACCESS_TIME_OFFSET);
094:            }
095:
096:            public Transaction interruptedTransaction() {
097:                return _interruptedTransaction;
098:            }
099:
100:            public int length() {
101:                return LENGTH;
102:            }
103:
104:            protected void readFixedPart(LocalObjectContainer file,
105:                    Buffer reader) {
106:                commonTasksForNewAndRead(file);
107:                checkThreadFileLock(file, reader);
108:                reader.seek(TRANSACTION_POINTER_OFFSET);
109:                _interruptedTransaction = LocalTransaction
110:                        .readInterruptedTransaction(file, reader);
111:                file.blockSizeReadFromFile(reader.readInt());
112:                readClassCollectionAndFreeSpace(file, reader);
113:                _variablePart = new FileHeaderVariablePart1(reader.readInt(),
114:                        file.systemData());
115:            }
116:
117:            private void checkThreadFileLock(LocalObjectContainer container,
118:                    Buffer reader) {
119:                reader.seek(ACCESS_TIME_OFFSET);
120:                long lastAccessTime = reader.readLong();
121:                if (FileHeader.lockedByOtherSession(container, lastAccessTime)) {
122:                    _timerFileLock.checkIfOtherSessionAlive(container, 0,
123:                            ACCESS_TIME_OFFSET, lastAccessTime);
124:                }
125:            }
126:
127:            private void commonTasksForNewAndRead(LocalObjectContainer file) {
128:                newTimerFileLock(file);
129:                file._handlers.oldEncryptionOff();
130:            }
131:
132:            public void readVariablePart(LocalObjectContainer file) {
133:                _variablePart.read(file.systemTransaction());
134:            }
135:
136:            public void writeFixedPart(LocalObjectContainer file,
137:                    boolean startFileLockingThread, boolean shuttingDown,
138:                    StatefulBuffer writer, int blockSize, int freespaceID) {
139:                writer.append(SIGNATURE);
140:                writer.writeByte(VERSION);
141:                writer.writeInt((int) timeToWrite(_timerFileLock.openTime(),
142:                        shuttingDown));
143:                writer.writeLong(timeToWrite(_timerFileLock.openTime(),
144:                        shuttingDown));
145:                writer.writeLong(timeToWrite(System.currentTimeMillis(),
146:                        shuttingDown));
147:                writer.writeInt(0); // transaction pointer 1 for "in-commit-mode"
148:                writer.writeInt(0); // transaction pointer 2
149:                writer.writeInt(blockSize);
150:                writer.writeInt(file.systemData().classCollectionID());
151:                writer.writeInt(freespaceID);
152:                writer.writeInt(_variablePart.getID());
153:                writer.noXByteCheck();
154:                writer.write();
155:                file.syncFiles();
156:                if (startFileLockingThread) {
157:                    _timerFileLock.start();
158:                }
159:            }
160:
161:            public void writeTransactionPointer(Transaction systemTransaction,
162:                    int transactionAddress) {
163:                writeTransactionPointer(systemTransaction, transactionAddress,
164:                        0, TRANSACTION_POINTER_OFFSET);
165:            }
166:
167:            public void writeVariablePart(LocalObjectContainer file, int part) {
168:                _variablePart.setStateDirty();
169:                _variablePart.write(file.systemTransaction());
170:            }
171:
172:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.