Source Code Cross Referenced for TTreeMetaData.java in  » Database-DBMS » axion » org » axiondb » ext » indexes » ttree » 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 » axion » org.axiondb.ext.indexes.ttree 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $Id: TTreeMetaData.java,v 1.1 2005/06/30 01:14:44 ahimanikya Exp $
003:         * =======================================================================
004:         * Copyright (c) 2005 Axion Development Team.  All rights reserved.
005:         *  
006:         * Redistribution and use in source and binary forms, with or without 
007:         * modification, are permitted provided that the following conditions 
008:         * are met:
009:         * 
010:         * 1. Redistributions of source code must retain the above 
011:         *    copyright notice, this list of conditions and the following 
012:         *    disclaimer. 
013:         *   
014:         * 2. Redistributions in binary form must reproduce the above copyright 
015:         *    notice, this list of conditions and the following disclaimer in 
016:         *    the documentation and/or other materials provided with the 
017:         *    distribution. 
018:         *   
019:         * 3. The names "Tigris", "Axion", nor the names of its contributors may 
020:         *    not be used to endorse or promote products derived from this 
021:         *    software without specific prior written permission. 
022:         *  
023:         * 4. Products derived from this software may not be called "Axion", nor 
024:         *    may "Tigris" or "Axion" appear in their names without specific prior
025:         *    written permission.
026:         *   
027:         * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
028:         * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
029:         * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
030:         * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
031:         * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
032:         * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
033:         * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
034:         * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
035:         * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
036:         * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
037:         * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
038:         * =======================================================================
039:         */
040:
041:        package org.axiondb.ext.indexes.ttree;
042:
043:        import java.io.File;
044:        import java.io.FileInputStream;
045:        import java.io.FileOutputStream;
046:        import java.io.IOException;
047:        import java.io.ObjectInputStream;
048:        import java.io.ObjectOutputStream;
049:        import java.util.HashMap;
050:        import java.util.Iterator;
051:        import java.util.Map;
052:
053:        import org.axiondb.AxionException;
054:
055:        /**
056:         * Metadata for {@link TTree}.
057:         * 
058:         * @author Pavels Andrejevs
059:         */
060:        public final class TTreeMetaData {
061:
062:            private static class TTreeMetaDataFile {
063:
064:                public static TTreeMetaDataFile load(File file)
065:                        throws IOException {
066:                    ObjectInputStream in = null;
067:                    try {
068:                        in = new ObjectInputStream(new FileInputStream(file));
069:                        int value = in.readInt();
070:                        int rootFileId = in.readInt();
071:                        return new TTreeMetaDataFile(value, rootFileId);
072:                    } finally {
073:                        try {
074:                            in.close();
075:                        } catch (Exception e) {
076:                        }
077:                    }
078:                }
079:
080:                private int _rootFileId = 1;
081:
082:                private int _treeSize = 0;
083:
084:                private int _value = 0;
085:
086:                public TTreeMetaDataFile() {
087:                }
088:
089:                private TTreeMetaDataFile(int value, int rootFileId) {
090:                    setValue(value);
091:                    setRootFileId(rootFileId);
092:                }
093:
094:                public int current() {
095:                    return _value;
096:                }
097:
098:                public int getRootFileId() {
099:                    return _rootFileId;
100:                }
101:
102:                public int getTreeSize() {
103:                    return _treeSize;
104:                }
105:
106:                public int increment() {
107:                    return _value++;
108:                }
109:
110:                public void save(File file) throws IOException {
111:                    ObjectOutputStream out = null;
112:                    try {
113:                        out = new ObjectOutputStream(new FileOutputStream(file));
114:                        out.writeInt(_value);
115:                        out.writeInt(_rootFileId);
116:                    } finally {
117:                        try {
118:                            out.close();
119:                        } catch (Exception e) {
120:                        }
121:                    }
122:                }
123:
124:                public void setRootFileId(int rootFileId) {
125:                    _rootFileId = rootFileId;
126:                }
127:
128:                public void setTreeSize(int treeSize) {
129:                    _treeSize = treeSize;
130:                }
131:
132:                private void setValue(int value) {
133:                    _value = value;
134:                }
135:            }
136:
137:            private File _dataDirectory = null;
138:            private Map _dirtyNodes = null;
139:            private TTreeMetaDataFile _file;
140:            private boolean _memoryOnly = true;
141:            private TTreeMetaDataFile _metaDataFile = null;
142:            private String _name = null;
143:
144:            public TTreeMetaData(String name, File dataDir, boolean memoryOnly)
145:                    throws AxionException {
146:                _name = name.toUpperCase();
147:                _dataDirectory = dataDir;
148:                _memoryOnly = memoryOnly;
149:                _dirtyNodes = new HashMap();
150:                loadMetaDataFile();
151:            }
152:
153:            public void clearDirty(AbstractTTreeNode node) {
154:                clearDirty(node.getFileId());
155:            }
156:
157:            public File getDataDirectory() {
158:                return _dataDirectory;
159:            }
160:
161:            public int getDirtyNodeCount() {
162:                return _dirtyNodes.size();
163:            }
164:
165:            public Iterator getDirtyNodes() {
166:                return _dirtyNodes.values().iterator();
167:            }
168:
169:            public TTreeMetaDataFile getFile() {
170:                return _file;
171:            }
172:
173:            public final File getFileById(int fileid) {
174:                return new File(getDataDirectory(), getName() + "." + fileid);
175:            }
176:
177:            public File getMetaDataFile() {
178:                return new File(getDataDirectory(), getName() + ".CTR");
179:            }
180:
181:            public String getName() {
182:                return _name;
183:            }
184:
185:            public int getRootFileId() {
186:                return _metaDataFile.getRootFileId();
187:            }
188:
189:            public int getTreeSize() {
190:                return _metaDataFile.getTreeSize();
191:            }
192:
193:            public boolean hasDirtyNodes() {
194:                return !_dirtyNodes.isEmpty();
195:            }
196:
197:            public int incrementCounter() {
198:                return _metaDataFile.increment();
199:            }
200:
201:            public boolean isMemoryOnly() {
202:                return _memoryOnly;
203:            }
204:
205:            public void saveMetaDataFile() throws AxionException {
206:                try {
207:                    _metaDataFile.save(getMetaDataFile());
208:                } catch (IOException e) {
209:                    throw new AxionException(e);
210:                }
211:            }
212:
213:            public void setAllClean() {
214:                // Clear dirty nodes
215:                _dirtyNodes.clear();
216:                // Delete each node file
217:                for (int i = 1; i < _metaDataFile.current(); i++) {
218:                    File file = getFileById(i);
219:                    if (file.exists()) {
220:                        file.delete();
221:                    }
222:                }
223:                // Delete metadata file
224:                File file = getMetaDataFile();
225:                if (file.exists()) {
226:                    file.delete();
227:                }
228:                newMetaDataFile();
229:            }
230:
231:            public void setDataDirectory(File dir) {
232:                _dataDirectory = dir;
233:            }
234:
235:            public void setDirty(AbstractTTreeNode node) {
236:                setDirty(node.getFileId(), node);
237:            }
238:
239:            public void setFile(TTreeMetaDataFile file) {
240:                _file = file;
241:            }
242:
243:            public void setMemoryOnly(boolean memoryOnly) {
244:                _memoryOnly = memoryOnly;
245:            }
246:
247:            public void setRootFileId(int rootFileId) {
248:                _metaDataFile.setRootFileId(rootFileId);
249:            }
250:
251:            public void setTreeSize(int treeSize) {
252:                _metaDataFile.setTreeSize(treeSize);
253:            }
254:
255:            private void clearDirty(int fileId) {
256:                clearDirty(new Integer(fileId));
257:            }
258:
259:            private void clearDirty(Integer fileId) {
260:                _dirtyNodes.remove(fileId);
261:            }
262:
263:            private void loadMetaDataFile() throws AxionException {
264:                File file = getMetaDataFile();
265:                if (file.exists()) {
266:                    try {
267:                        _metaDataFile = TTreeMetaDataFile.load(file);
268:                    } catch (IOException e) {
269:                        throw new AxionException(e);
270:                    }
271:                } else {
272:                    newMetaDataFile();
273:                }
274:            }
275:
276:            private void newMetaDataFile() {
277:                _metaDataFile = new TTreeMetaDataFile();
278:                _metaDataFile.increment(); // start from 1
279:            }
280:
281:            private void setDirty(int fileId, AbstractTTreeNode node) {
282:                setDirty(new Integer(fileId), node);
283:            }
284:
285:            private void setDirty(Integer fileId, AbstractTTreeNode node) {
286:                _dirtyNodes.put(fileId, node);
287:            }
288:
289:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.