Main Page | Packages | Class Hierarchy | Class List | Directories | File List | Class Members | Related Pages

FODBUniqueLongIndex.java

00001 /*
00002  * OpenMobileIS - a free Java(TM) Framework for mobile applications Java(TM)
00003  * Copyright (C) 2004-2005 Philippe Delrieu
00004  * All rights reserved.
00005  * Contact: openmobileis@e-care.fr
00006  *
00007  * This library is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or any later version.
00011  *
00012  * This library is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with this library; if not, write to the Free Software
00019  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
00020  * USA
00021  *
00022  *  Author : Philippe Delrieu
00023  *  
00024  *  Modifications :
00025  *  2004 Creation P.Delrieu
00026  *  2004 Modified by Romain Beaugrand
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.FODBIndexDescriptor;
00036 import org.openmobileis.database.fastobjectdb.FODBLongIndexDescriptor;
00037 import org.openmobileis.database.fastobjectdb.db.exception.FODBException;
00038 import org.openmobileis.database.fastobjectdb.db.index.node.LongNode;
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.SodaLongIndexComparator;
00042 import org.openmobileis.database.fastobjectdb.db.store.FODBCollectionIndexFile;
00043 
00046 public class FODBUniqueLongIndex extends FODBLongIndex implements FODBUniqueIndex {
00047 
00048         public FODBUniqueLongIndex(FODBIndexHeader newHeader, FODBCollectionIndexFile cFile, AccessibleObject accObj) throws FODBException {
00049                 super(newHeader, cFile, accObj);
00050         }
00051         
00052         public FODBUniqueLongIndex(FODBLongIndexDescriptor descriptor, FODBCollectionIndexFile cFile, AccessibleObject accObj) throws FODBException {
00053                 super(descriptor, cFile, accObj);
00054         }
00055 
00056 
00057         /* (non-Javadoc)
00058          * @see org.openmobileis.embedded.fastobjectdb.db.FODBIndex#getType()
00059          */
00060         public int getType() {
00061                 return FODBIndex.UNIQUE;
00062         }
00063 
00064         protected void writeKeyPtr(Node pg, int pos, long newptr) throws IOException, ClassNotFoundException {
00065                 // TODO : This case shoudn't happen... Think about removing this.
00066                 pg.ptr[pos] = newptr;
00067                 // rewrite modified page
00068                 colFile.rewriteNode(pg, pg.filePtr);
00069                 
00070                 return;
00071         }
00072         
00073         protected void addSearchResult(LongNode pg, int pos, LongArray array) throws IOException, ClassNotFoundException {
00074                 array.add(pg.ptr[pos]);
00075         }
00076         
00077         public long getKeyPosition(Object keytosearch) throws FODBException {
00078                 if (keytosearch == null) {
00079                         return Node.NO_NODE;
00080                 }
00081                 if (!(keytosearch instanceof Long))     {
00082                         throw new FODBException("Key type in getKeyPosition for LongUniqueIndex");
00083                 }
00084                 long key = ((Long)keytosearch).longValue();
00085 
00086                 try     {
00087                         SodaLongIndexComparator comparator = new SodaLongIndexComparator();
00088                         comparator.setOperand(new Long(key));
00089                         comparator.addComparator(BaseConstraint.EQUALS);
00090                         long preResult[] = this.query(comparator);
00091         
00092                         if (preResult == null) { // Shouldn't happen !
00093                                 throw new FODBException("Internal error !!!");
00094                         }
00095                         if (preResult.length > 1) { // Shouldn't happen in a UniqueIndex
00096                                 throw new FODBException("Internal error !!!");
00097                         }
00098                         
00099                         if (preResult.length == 0) {
00100                                 return Node.NO_NODE;
00101                         }
00102                         
00103                         // If we got there, then we had ONE result, has expected
00104                         return preResult[0];
00105                 } catch (Throwable ex) {
00106                         throw new FODBException(ex);
00107                 }
00108         }
00109         
00110         protected boolean removeKeyPtr(Node pg, int pos, long pointer) throws IOException, ClassNotFoundException {
00111                 return true;
00112         }
00113 
00114         public FODBIndexDescriptor getIndexDescriptor() {
00115                 return new FODBLongIndexDescriptor(this.header.getName(), FODBIndexDescriptor.UNIQUE, this.header.getMemberName(), this.header.order);
00116         }
00117 }

Generated on Wed Dec 14 21:05:33 2005 for OpenMobileIS by  doxygen 1.4.4