1 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 a_name) { 40 _configClass = a_class; 41 setName(a_name); 42 } 43 44 private Config4Class classConfig() { 45 return _configClass; 46 } 47 48 String className() { 49 return classConfig().getName(); 50 } 51 52 public Object deepClone(Object 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 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 |