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