00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 package org.openmobileis.database.fastobjectdb.db.index;
00030
00031 import java.io.IOException;
00032 import java.lang.reflect.*;
00033 import org.openmobileis.common.util.collection.*;
00034 import org.openmobileis.database.fastobjectdb.FODBStringIndexDescriptor;
00035 import org.openmobileis.database.fastobjectdb.db.exception.FODBException;
00036 import org.openmobileis.database.fastobjectdb.db.index.node.*;
00037 import org.openmobileis.database.fastobjectdb.db.query.soda.BaseConstraint;
00038 import org.openmobileis.database.fastobjectdb.db.query.soda.SodaStringIndexComparator;
00039 import org.openmobileis.database.fastobjectdb.db.store.*;
00040
00043 public class FODBUniqueStringIndex extends FODBStringIndex implements FODBUniqueIndex {
00044
00045 public FODBUniqueStringIndex(FODBIndexHeader newHeader, FODBCollectionIndexFile cFile, AccessibleObject accObj) throws FODBException {
00046 super(newHeader, cFile, accObj);
00047 }
00048
00049 public FODBUniqueStringIndex(FODBStringIndexDescriptor descriptor, FODBCollectionIndexFile cFile, AccessibleObject accObj) throws FODBException {
00050 super(descriptor, cFile, accObj);
00051 }
00052
00053 public int getType() {
00054 return FODBIndex.UNIQUE;
00055 }
00056
00057 protected void writeKeyPtr(Node node, int pos, long newptr) throws IOException, ClassNotFoundException {
00058 throw new IOException("rewrite unique String index Ptr not allowed");
00059 }
00060
00061
00062
00063
00064
00065
00066 protected void addSearchResult(StringNode node, int pos, LongArray array, SodaStringIndexComparator comparator) throws IOException, ClassNotFoundException {
00067 array.add(node.getNodePtrAtPos(pos));
00068 }
00069
00070
00071
00072 public long getKeyPosition(Object keytosearch) throws FODBException {
00073 if (keytosearch == null) {
00074 return Node.NO_NODE;
00075 }
00076 if (!(keytosearch instanceof String)) {
00077 throw new FODBException("Key type in getKeyPosition for StringUniqueIndex");
00078 }
00079 String key = (String) keytosearch;
00080 if (key.length() == 0) {
00081 return Node.NO_NODE;
00082 }
00083
00084 try {
00085 SodaStringIndexComparator comparator = new SodaStringIndexComparator(((FODBStringIndexDescriptor)this.getIndexDescriptor()).isCaseSensitive());
00086 comparator.setOperand(key);
00087 comparator.addComparator(BaseConstraint.EQUALS);
00088 long preResult[] = this.query(comparator);
00089
00090 if (preResult == null) {
00091 throw new FODBException("Internal error !!!");
00092 }
00093 if (preResult.length > 1) {
00094 throw new FODBException("Internal error !!!");
00095 }
00096
00097 if (preResult.length == 0) {
00098 return Node.NO_NODE;
00099 }
00100
00101
00102 return preResult[0];
00103 } catch (Throwable ex) {
00104 throw new FODBException(ex);
00105 }
00106 }
00107
00108 protected boolean removeKeyPtr(Node pg, int pos, long pointer) throws IOException, ClassNotFoundException {
00109 return true;
00110 }
00111
00112 }