FODBIndexDescriptor.java

00001 /*
00002  * OpenMobileIS - a free Java(TM) Framework for mobile applications Java(TM)
00003  * Copyright (C) 2004-2006 Philippe Delrieu
00004  * All rights reserved.
00005  * Contact: pdelrieu@openmobileis.org
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;
00030 
00031 import java.io.Externalizable;
00032 import java.io.IOException;
00033 import java.io.ObjectInput;
00034 import java.io.ObjectOutput;
00035 
00046 public abstract class FODBIndexDescriptor implements Externalizable     {
00047         static final long serialVersionUID = 5521257935120563452L;
00048         public static final int UNIQUE = 1;
00049         public static final int MULTIPLE = 2;
00050         private String name;
00051         private String memberName;
00052         private int type;
00053         private int order;
00054     
00055     public FODBIndexDescriptor() {
00056     }
00057         
00058         public FODBIndexDescriptor(String newName, int indexType, String newMemberName, int btreeorder) {
00059                 //correct Btree algo pb. Order must be pair
00060                 if (btreeorder%2 != 0)  {
00061                         btreeorder = btreeorder+1;
00062                 }
00063                 this.order = btreeorder;
00064                 name = newName;
00065                 this.type = indexType;
00066                 memberName = newMemberName;
00067         }
00068     
00069     public void writeExternal(ObjectOutput out) throws IOException {
00070         int i;
00071         
00072         for (i = 0; i < name.length(); i++) {
00073             out.writeChar(name.charAt(i));
00074         }
00075         out.writeChar('\0');
00076         
00077         for (i = 0; i < memberName.length(); i++) {
00078             out.writeChar(memberName.charAt(i));
00079         }
00080         out.writeChar('\0');
00081         
00082         out.writeInt(type);
00083         out.writeInt(order);
00084     }
00085     
00086     public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
00087         char parseChar;
00088         
00089         StringBuffer tmpName = new StringBuffer();
00090         while ((parseChar = in.readChar()) != '\0') {
00091             tmpName.append(parseChar);
00092         }
00093         name = tmpName.toString();
00094         
00095         StringBuffer tmpMemberName = new StringBuffer();
00096         while ((parseChar = in.readChar()) != '\0') {
00097             tmpMemberName.append(parseChar);
00098         }
00099         memberName = tmpMemberName.toString();
00100         
00101         type = in.readInt();
00102         order = in.readInt();
00103     }
00104     
00105         public String getName() {
00106                 return name;
00107         }
00108     
00109     public String getMemberName() {
00110         return memberName;
00111     }
00112     
00113     public void setMemberName(String memberName) {
00114         this.memberName = memberName;
00115     }
00116     
00117     public int getType() {
00118         return type;
00119     }
00120     
00121     public void setType(int type) {
00122         this.type = type;
00123     }
00124         
00125         public boolean isUnique() {
00126                 return (type == UNIQUE) ? true : false;
00127         }
00128         
00129         public boolean isMultiple() {
00130                 return (type == MULTIPLE) ? true : false;
00131         }
00132 
00133         public int getOrder() {
00134                 return order;
00135         }
00136 }

Generated on Mon Dec 4 11:03:26 2006 for OpenMobileIS by  doxygen 1.5.1-p1