KickJava   Java API By Example, From Geeks To Geeks.

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


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.config.*;
25 import com.db4o.ext.*;
26
27 /**
28  * Configuration for a defragmentation run.
29  *
30  * @see Defragment
31  */

32 public class DefragmentConfig {
33     
34     public static final boolean DEBUG = false;
35     
36     public final static String JavaDoc BACKUP_SUFFIX="backup";
37     
38     private String JavaDoc _origPath;
39     private String JavaDoc _backupPath;
40     private ContextIDMapping _mapping;
41     private Configuration _config;
42     
43     private StoredClassFilter _storedClassFilter=null;
44     private boolean _forceBackupDelete=false;
45
46     /**
47      * Creates a configuration for a defragmentation run. The backup and mapping
48      * file paths are generated from the original path by appending the default
49      * suffixes. All properties other than the provided paths are set to FALSE
50      * by default.
51      *
52      * @param origPath The path to the file to be defragmented. Must exist and must be
53      * a valid yap file.
54      */

55     public DefragmentConfig(String JavaDoc origPath) {
56         this(origPath,origPath+"."+BACKUP_SUFFIX);
57     }
58
59     /**
60      * Creates a configuration for a defragmentation run with in-memory mapping.
61      * All properties other than the provided paths are set to FALSE by default.
62      *
63      * @param origPath The path to the file to be defragmented. Must exist and must be
64      * a valid yap file.
65      * @param backupPath The path to the backup of the original file. No file should
66      * exist at this position, otherwise it will be OVERWRITTEN if forceBackupDelete()
67      * is set to true!
68      */

69     public DefragmentConfig(String JavaDoc origPath, String JavaDoc backupPath) {
70         this(origPath,backupPath,new TreeIDMapping());
71     }
72
73     /**
74      * Creates a configuration for a defragmentation run. All properties other
75      * than the provided paths are set to FALSE by default.
76      *
77      * @param origPath The path to the file to be defragmented. Must exist and must be
78      * a valid yap file.
79      * @param backupPath The path to the backup of the original file. No file should
80      * exist at this position, otherwise it will be OVERWRITTEN if forceBackupDelete()
81      * is set to true!
82      * @param mapping The intermediate mapping used internally.
83      */

84     public DefragmentConfig(String JavaDoc origPath, String JavaDoc backupPath,ContextIDMapping mapping) {
85         _origPath = origPath;
86         _backupPath = backupPath;
87         _mapping = mapping;
88     }
89
90     public String JavaDoc origPath() {
91         return _origPath;
92     }
93
94     public String JavaDoc backupPath() {
95         return _backupPath;
96     }
97
98     public ContextIDMapping mapping() {
99         return _mapping;
100     }
101     
102     public StoredClassFilter storedClassFilter() {
103         return (_storedClassFilter==null ? NULLFILTER : _storedClassFilter);
104     }
105     
106     public void storedClassFilter(StoredClassFilter storedClassFilter) {
107         _storedClassFilter=storedClassFilter;
108     }
109
110     public boolean forceBackupDelete() {
111         return _forceBackupDelete;
112     }
113     
114     public void forceBackupDelete(boolean forceBackupDelete) {
115         _forceBackupDelete=forceBackupDelete;
116     }
117
118     public Configuration db4oConfig() {
119         if(_config==null) {
120             _config=vanillaDb4oConfig();
121         }
122         return _config;
123     }
124     
125     public void db4oConfig(Configuration config) {
126         _config=config;
127     }
128     
129     static class NullFilter implements StoredClassFilter {
130         public boolean accept(StoredClass storedClass) {
131             return true;
132         }
133     }
134     
135     private final static StoredClassFilter NULLFILTER=new NullFilter();
136     
137     public static Configuration vanillaDb4oConfig(){
138         Configuration config = Db4o.newConfiguration();
139         config.weakReferences(false);
140         return config;
141     }
142     
143 }
144
Popular Tags