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

FODBUniqueStringIndex.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.*;
00033 import org.openmobileis.common.util.collection.*;
00034 import org.openmobileis.database.fastobjectdb.FODBIndexDescriptor;
00035 import org.openmobileis.database.fastobjectdb.FODBStringIndexDescriptor;
00036 import org.openmobileis.database.fastobjectdb.db.exception.FODBException;
00037 import org.openmobileis.database.fastobjectdb.db.index.node.*;
00038 import org.openmobileis.database.fastobjectdb.db.query.soda.BaseConstraint;
00039 import org.openmobileis.database.fastobjectdb.db.query.soda.SodaStringIndexComparator;
00040 import org.openmobileis.database.fastobjectdb.db.store.*;
00041 
00044 public class FODBUniqueStringIndex extends FODBStringIndex implements FODBUniqueIndex {
00045         
00046         public FODBUniqueStringIndex(FODBIndexHeader newHeader, FODBCollectionIndexFile cFile, AccessibleObject accObj) throws FODBException    {
00047                 super(newHeader, cFile, accObj);
00048         }
00049         
00050         public FODBUniqueStringIndex(FODBStringIndexDescriptor descriptor, FODBCollectionIndexFile cFile, AccessibleObject accObj) throws FODBException {
00051                 super(descriptor, cFile, accObj);
00052         }
00053 
00054         public int getType() {
00055                 return FODBIndex.UNIQUE;
00056         }
00057         
00058         protected void writeKeyPtr(Node node, int pos, long newptr) throws IOException, ClassNotFoundException {
00059         throw new IOException("rewrite unique String  index Ptr not allowed");
00060         }
00061         
00062         
00063 /*      protected void addSearchResult(long pos, LongArray array) throws IOException, ClassNotFoundException  {
00064                 array.add(pos);
00065         } */
00066         
00067         protected void addSearchResult(StringNode node, int pos, LongArray array, SodaStringIndexComparator comparator) throws IOException, ClassNotFoundException {
00068                 array.add(node.getNodePtrAtPos(pos));
00069         }
00070         
00071 
00072         
00073         public long getKeyPosition(Object keytosearch) throws FODBException {
00074                 if (keytosearch == null) {
00075                         return Node.NO_NODE;
00076                 }
00077                 if (!(keytosearch instanceof String))   {
00078                         throw new FODBException("Key type in getKeyPosition for StringUniqueIndex");
00079                 }
00080                 String key = (String) keytosearch;
00081                 if (key.length() == 0) {
00082                         return Node.NO_NODE;
00083                 }
00084                 
00085                 try     {
00086                         SodaStringIndexComparator comparator = new SodaStringIndexComparator(((FODBStringIndexDescriptor)this.getIndexDescriptor()).isCaseSensitive());
00087                         comparator.setOperand(key);
00088                         comparator.addComparator(BaseConstraint.EQUALS);
00089                         long preResult[] = this.query(comparator);
00090         
00091                         if (preResult == null) { // Shouldn't happen !
00092                                 throw new FODBException("Internal error !!!");
00093                         }
00094                         if (preResult.length > 1) { // Shouldn't happen in a UniqueIndex
00095                                 throw new FODBException("Internal error !!!");
00096                         }
00097                         
00098                         if (preResult.length == 0) {
00099                                 return Node.NO_NODE;
00100                         }
00101                         
00102                         // If we got there, then we had ONE result, has expected
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 
00113         public FODBIndexDescriptor getIndexDescriptor() {
00114                 return new FODBStringIndexDescriptor(this.header.getName(), FODBIndexDescriptor.UNIQUE, this.header.getMemberName(), this.header.order, this.header.keyLen);
00115         }
00116 
00117 }

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