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