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.AccessibleObject;
00033
00034 import org.openmobileis.common.util.collection.LongArray;
00035 import org.openmobileis.database.fastobjectdb.FODBLongIndexDescriptor;
00036 import org.openmobileis.database.fastobjectdb.db.exception.FODBException;
00037 import org.openmobileis.database.fastobjectdb.db.index.node.LongNode;
00038 import org.openmobileis.database.fastobjectdb.db.index.node.Node;
00039 import org.openmobileis.database.fastobjectdb.db.query.soda.BaseConstraint;
00040 import org.openmobileis.database.fastobjectdb.db.query.soda.SodaLongIndexComparator;
00041 import org.openmobileis.database.fastobjectdb.db.store.FODBCollectionIndexFile;
00042
00045 public class FODBUniqueLongIndex extends FODBLongIndex implements FODBUniqueIndex {
00046
00047 public FODBUniqueLongIndex(FODBIndexHeader newHeader, FODBCollectionIndexFile cFile, AccessibleObject accObj) throws FODBException {
00048 super(newHeader, cFile, accObj);
00049 }
00050
00051 public FODBUniqueLongIndex(FODBLongIndexDescriptor descriptor, FODBCollectionIndexFile cFile, AccessibleObject accObj) throws FODBException {
00052 super(descriptor, cFile, accObj);
00053 }
00054
00055
00056
00057
00058
00059 public int getType() {
00060 return FODBIndex.UNIQUE;
00061 }
00062
00063 protected void writeKeyPtr(Node pg, int pos, long newptr) throws IOException, ClassNotFoundException {
00064
00065 pg.ptr[pos] = newptr;
00066
00067 colFile.rewriteNode(pg, pg.filePtr);
00068
00069 return;
00070 }
00071
00072 protected void addSearchResult(LongNode pg, int pos, LongArray array) throws IOException, ClassNotFoundException {
00073 array.add(pg.ptr[pos]);
00074 }
00075
00076 public long getKeyPosition(Object keytosearch) throws FODBException {
00077 if (keytosearch == null) {
00078 return Node.NO_NODE;
00079 }
00080 if (!(keytosearch instanceof Long)) {
00081 throw new FODBException("Key type in getKeyPosition for LongUniqueIndex");
00082 }
00083 long key = ((Long)keytosearch).longValue();
00084
00085 try {
00086 SodaLongIndexComparator comparator = new SodaLongIndexComparator();
00087 comparator.setOperand(new Long(key));
00088 comparator.addComparator(BaseConstraint.EQUALS);
00089 long preResult[] = this.query(comparator);
00090
00091 if (preResult == null) {
00092 throw new FODBException("Internal error !!!");
00093 }
00094 if (preResult.length > 1) {
00095 throw new FODBException("Internal error !!!");
00096 }
00097
00098 if (preResult.length == 0) {
00099 return Node.NO_NODE;
00100 }
00101
00102
00103 return preResult[0];
00104 } catch (Throwable ex) {
00105 throw new FODBException(ex);
00106 }
00107 }
00108
00109 protected boolean removeKeyPtr(Node pg, int pos, long pointer) throws IOException, ClassNotFoundException {
00110 return true;
00111 }
00112 }