KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > db4o > Config4Field


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;
22
23 import com.db4o.config.ObjectField;
24 import com.db4o.foundation.*;
25
26 class Config4Field extends Config4Abstract implements ObjectField, DeepClone {
27     
28     private final Config4Class _configClass;
29     
30     private final static KeySpec QUERY_EVALUATION=new KeySpec(true);
31     
32     private final static KeySpec INDEXED=new KeySpec(YapConst.DEFAULT);
33     
34     protected Config4Field(Config4Class a_class, KeySpecHashtable4 config) {
35         super(config);
36         _configClass = a_class;
37     }
38     
39     Config4Field(Config4Class a_class, String JavaDoc a_name) {
40         _configClass = a_class;
41         setName(a_name);
42     }
43
44     private Config4Class classConfig() {
45         return _configClass;
46     }
47     
48     String JavaDoc className() {
49         return classConfig().getName();
50     }
51
52     public Object JavaDoc deepClone(Object JavaDoc param) {
53         return new Config4Field((Config4Class)param, _config);
54     }
55
56     public void queryEvaluation(boolean flag) {
57         _config.put(QUERY_EVALUATION, flag);
58     }
59
60     public void rename(String JavaDoc newName) {
61         classConfig().config().rename(new Rename(className(), getName(), newName));
62         setName(newName);
63     }
64
65     public void indexed(boolean flag) {
66         putThreeValued(INDEXED, flag);
67     }
68
69     public void initOnUp(Transaction systemTrans, YapField yapField) {
70         
71         YapStream anyStream = systemTrans.stream();
72         if (!anyStream.maintainsIndices()) {
73             return;
74         }
75         if(Debug.indexAllFields){
76             indexed(true);
77         }
78         if (! yapField.supportsIndex()) {
79             indexed(false);
80         }
81         
82         YapFile stream = (YapFile)anyStream;
83         int indexedFlag=_config.getAsInt(INDEXED);
84         if (indexedFlag == YapConst.NO) {
85             yapField.dropIndex(systemTrans);
86             return;
87         }
88         
89         if (useExistingIndex(systemTrans, yapField)) {
90             return;
91         }
92         
93         if (indexedFlag != YapConst.YES) {
94             return;
95         }
96         
97         createIndex(systemTrans, yapField, stream);
98     }
99
100     private boolean useExistingIndex(Transaction systemTrans, YapField yapField) {
101         return yapField.getIndex(systemTrans) != null;
102     }
103
104     private void createIndex(Transaction systemTrans, YapField yapField, YapFile stream) {
105         if (stream.configImpl().messageLevel() > YapConst.NONE) {
106             stream.message("creating index " + yapField.toString());
107         }
108         yapField.initIndex(systemTrans);
109         stream.setDirtyInSystemTransaction(yapField.getParentYapClass());
110         reindex(systemTrans, yapField, stream);
111     }
112
113     private void reindex(Transaction systemTrans, YapField yapField, YapFile stream) {
114         YapClass yapClass = yapField.getParentYapClass();
115         if (yapField.rebuildIndexForClass(stream, yapClass)) {
116             systemTrans.commit();
117         }
118     }
119     
120     boolean queryEvaluation() {
121         return _config.getAsBoolean(QUERY_EVALUATION);
122     }
123
124
125 }
126
Popular Tags