Source Code Cross Referenced for FirstPassCommand.java in  » Database-DBMS » db4o-6.4 » com » db4o » defragment » 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.defragment 
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.defragment;
022:
023:        import com.db4o.*;
024:        import com.db4o.foundation.*;
025:        import com.db4o.internal.*;
026:        import com.db4o.internal.btree.*;
027:        import com.db4o.internal.slots.*;
028:
029:        /**
030:         * First step in the defragmenting process: Allocates pointer slots in the target file for
031:         * each ID (but doesn't fill them in, yet) and registers the mapping from source pointer address
032:         * to target pointer address.
033:         * 
034:         * @exclude
035:         */
036:        final class FirstPassCommand implements  PassCommand {
037:            private final static int ID_BATCH_SIZE = 4096;
038:
039:            private TreeInt _ids;
040:
041:            void process(DefragContextImpl context, int objectID,
042:                    boolean isClassID) {
043:                if (batchFull()) {
044:                    flush(context);
045:                }
046:                _ids = TreeInt.add(_ids, (isClassID ? -objectID : objectID));
047:            }
048:
049:            private boolean batchFull() {
050:                return _ids != null && _ids.size() == ID_BATCH_SIZE;
051:            }
052:
053:            public void processClass(DefragContextImpl context,
054:                    ClassMetadata yapClass, int id, int classIndexID) {
055:                process(context, id, true);
056:                for (int fieldIdx = 0; fieldIdx < yapClass.i_fields.length; fieldIdx++) {
057:                    FieldMetadata field = yapClass.i_fields[fieldIdx];
058:                    if (!field.isVirtual() && field.hasIndex()) {
059:                        processBTree(context, field.getIndex(context
060:                                .systemTrans()));
061:                    }
062:                }
063:            }
064:
065:            public void processObjectSlot(DefragContextImpl context,
066:                    ClassMetadata yapClass, int sourceID) {
067:                process(context, sourceID, false);
068:            }
069:
070:            public void processClassCollection(DefragContextImpl context)
071:                    throws CorruptionException {
072:                process(context, context.sourceClassCollectionID(), false);
073:            }
074:
075:            public void processBTree(final DefragContextImpl context,
076:                    final BTree btree) {
077:                process(context, btree.getID(), false);
078:                context.traverseAllIndexSlots(btree, new Visitor4() {
079:                    public void visit(Object obj) {
080:                        int id = ((Integer) obj).intValue();
081:                        process(context, id, false);
082:                    }
083:                });
084:            }
085:
086:            public void flush(DefragContextImpl context) {
087:                if (_ids == null) {
088:                    return;
089:                }
090:                int blockSize = context.blockSize();
091:                int blockLength = Math.max(Const4.POINTER_LENGTH, blockSize);
092:                boolean overlapping = (Const4.POINTER_LENGTH % blockSize > 0);
093:                int blocksPerPointer = Const4.POINTER_LENGTH / blockSize;
094:                if (overlapping) {
095:                    blocksPerPointer++;
096:                }
097:                int batchSize = _ids.size() * blockLength;
098:                Slot pointerSlot = context.allocateTargetSlot(batchSize);
099:                int pointerAddress = pointerSlot.address();
100:                Iterator4 idIter = new TreeKeyIterator(_ids);
101:                while (idIter.moveNext()) {
102:                    int objectID = ((Integer) idIter.current()).intValue();
103:                    boolean isClassID = false;
104:                    if (objectID < 0) {
105:                        objectID = -objectID;
106:                        isClassID = true;
107:                    }
108:
109:                    if (DefragmentConfig.DEBUG) {
110:                        int mappedID = context.mappedID(objectID, -1);
111:                        // seen object ids don't come by here anymore - any other candidates?
112:                        if (mappedID >= 0) {
113:                            throw new IllegalStateException();
114:                        }
115:                    }
116:
117:                    context.mapIDs(objectID, pointerAddress, isClassID);
118:                    pointerAddress += blocksPerPointer;
119:                }
120:                _ids = null;
121:            }
122:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.