KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > db4o > defragment > SecondPassCommand


1 /* Copyright (C) 2004 - 2006 db4objects Inc. http://www.db4o.com
2
3 This file is part of the db4o open source object database.
4
5 db4o is free software; you can redistribute it and/or modify it under
6 the terms of version 2 of the GNU General Public License as published
7 by the Free Software Foundation and as clarified by db4objects' GPL
8 interpretation policy, available at
9 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.defragment;
22
23 import com.db4o.*;
24 import com.db4o.inside.btree.*;
25
26 /**
27  * Second step in the defragmenting process: Fills in target file pointer slots, copies
28  * content slots from source to target and triggers ID remapping therein by calling the
29  * appropriate yap/marshaller defrag() implementations. During the process, the actual address
30  * mappings for the content slots are registered for use with string indices.
31  *
32  * @exclude
33  */

34 final class SecondPassCommand implements PassCommand {
35
36     public void processClass(DefragContextImpl context, final YapClass yapClass, int id,final int classIndexID) throws CorruptionException {
37         if(context.mappedID(id,-1)==-1) {
38             System.err.println("MAPPING NOT FOUND: "+id);
39         }
40         ReaderPair.processCopy(context, id, new SlotCopyHandler() {
41             public void processCopy(ReaderPair readers) throws CorruptionException {
42                 yapClass.defragClass(readers, classIndexID);
43             }
44         });
45     }
46
47     public void processObjectSlot(DefragContextImpl context, final YapClass yapClass, int id, boolean registerAddresses) throws CorruptionException {
48         ReaderPair.processCopy(context, id, new SlotCopyHandler() {
49             public void processCopy(ReaderPair readers) {
50                 YapClass.defragObject(readers);
51             }
52         },registerAddresses);
53     }
54
55     public void processClassCollection(DefragContextImpl context) throws CorruptionException {
56         ReaderPair.processCopy(context, context.sourceClassCollectionID(), new SlotCopyHandler() {
57             public void processCopy(ReaderPair readers) {
58                 YapClassCollection.defrag(readers);
59             }
60         });
61     }
62
63     public void processBTree(final DefragContextImpl context, BTree btree) throws CorruptionException {
64         btree.defragBTree(context);
65     }
66
67     public void flush(DefragContextImpl context) {
68     }
69 }
Popular Tags