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.internal;
022:
023: import com.db4o.*;
024: import com.db4o.config.ObjectField;
025: import com.db4o.foundation.*;
026:
027: class Config4Field extends Config4Abstract implements ObjectField,
028: DeepClone {
029:
030: private final Config4Class _configClass;
031:
032: private final static KeySpec QUERY_EVALUATION = new KeySpec(true);
033:
034: private final static KeySpec INDEXED = new KeySpec(
035: TernaryBool.UNSPECIFIED);
036:
037: protected Config4Field(Config4Class a_class,
038: KeySpecHashtable4 config) {
039: super (config);
040: _configClass = a_class;
041: }
042:
043: Config4Field(Config4Class a_class, String a_name) {
044: _configClass = a_class;
045: setName(a_name);
046: }
047:
048: private Config4Class classConfig() {
049: return _configClass;
050: }
051:
052: String className() {
053: return classConfig().getName();
054: }
055:
056: public Object deepClone(Object param) {
057: return new Config4Field((Config4Class) param, _config);
058: }
059:
060: public void queryEvaluation(boolean flag) {
061: _config.put(QUERY_EVALUATION, flag);
062: }
063:
064: public void rename(String newName) {
065: classConfig().config().rename(
066: new Rename(className(), getName(), newName));
067: setName(newName);
068: }
069:
070: public void indexed(boolean flag) {
071: putThreeValued(INDEXED, flag);
072: }
073:
074: public void initOnUp(Transaction systemTrans, FieldMetadata yapField) {
075:
076: ObjectContainerBase anyStream = systemTrans.container();
077: if (!anyStream.maintainsIndices()) {
078: return;
079: }
080: if (Debug.indexAllFields) {
081: indexed(true);
082: }
083: if (!yapField.supportsIndex()) {
084: indexed(false);
085: }
086:
087: TernaryBool indexedFlag = _config.getAsTernaryBool(INDEXED);
088: if (indexedFlag.definiteNo()) {
089: yapField.dropIndex(systemTrans);
090: return;
091: }
092:
093: if (useExistingIndex(systemTrans, yapField)) {
094: return;
095: }
096:
097: if (!indexedFlag.definiteYes()) {
098: return;
099: }
100:
101: yapField.createIndex();
102: }
103:
104: private boolean useExistingIndex(Transaction systemTrans,
105: FieldMetadata yapField) {
106: return yapField.getIndex(systemTrans) != null;
107: }
108:
109: boolean queryEvaluation() {
110: return _config.getAsBoolean(QUERY_EVALUATION);
111: }
112:
113: }
|