1 package com.daffodilwoods.daffodildb.server.sql99.fulltext.dql.condition; 2 3 import com.daffodilwoods.database.resource.DException; 4 import com.daffodilwoods.daffodildb.server.sql99.dql.iterator._Iterator; 5 import com.daffodilwoods.daffodildb.server.datasystem.interfaces._IndexTable; 6 import com.daffodilwoods.daffodildb.server.sql99.fulltext.dml._FullTextIndexInformation; 7 import com.daffodilwoods.daffodildb.server.datasystem.interfaces._Table; 8 import com.daffodilwoods.daffodildb.server.datasystem.indexsystem._IndexInformation; 9 import com.daffodilwoods.daffodildb.server.sql99.expression.booleanvalueexpression.booleanvalueexpression; 10 import com.daffodilwoods.daffodildb.server.sql99.utils.parser.ConditionParser; 11 import com.daffodilwoods.daffodildb.server.sql99.utils._VariableValues; 12 import com.daffodilwoods.daffodildb.server.sql99.utils.VariableValues; 13 import com.daffodilwoods.daffodildb.server.sql99.utils.ConditionVariableValue; 14 import com.daffodilwoods.daffodildb.server.sql99.dql.iterator.condition.IndexedFilterIterator; 15 import com.daffodilwoods.database.sqlinitiator._Order; 16 import com.daffodilwoods.daffodildb.server.datasystem.indexsystem.ColumnObjectsTable; 17 import com.daffodilwoods.daffodildb.server.sql99.common.GeneralPurposeStaticClass; 18 import com.daffodilwoods.daffodildb.server.sql99.common.Datatypes; 19 import com.daffodilwoods.daffodildb.server.sql99.utils._Reference; 20 import com.daffodilwoods.daffodildb.server.sql99.common.ColumnDetails; 21 import com.daffodilwoods.daffodildb.server.sql99.common.TableDetails; 22 import com.daffodilwoods.daffodildb.utils.field.FieldBase; 23 24 34 35 public class WordRepresentation implements _Word { 39 FieldBase word ; 40 41 String condition; 42 45 String columnName; 46 50 booleanvalueexpression termCondition; 51 55 booleanvalueexpression locationCondition; 56 private _Order order; 57 58 public WordRepresentation(FieldBase word0) throws DException{ 59 word = word0; 60 condition =new String ((byte[]) word.getObject()); 61 termCondition = GeneralPurposeStaticClass.getCondition("term = '"+condition+"'",Datatypes.VARCHAR); 62 locationCondition = GeneralPurposeStaticClass.getCondition("fpk = ?",Datatypes.LONG); 63 } 64 65 public WordRepresentation[] getWord(){ 66 return new WordRepresentation[]{this}; 67 } 68 85 public int getType(){ 86 return PredicateConstant.singleWord; 87 } 88 94 public String getColumn()throws DException{ 95 return columnName; 96 } 97 103 public Object getKeyWords() throws DException{ 104 return word; 105 } 106 107 public double getCost(Object obj) throws DException{ 108 return 0.0; 109 } 110 116 public void setColumn(String colName) throws DException{ 117 columnName = colName; 118 } 119 127 public _Iterator execute(Object indexTable) throws DException { 128 _FullTextIndexInformation fti = getFullTextInformation(indexTable); 129 _Iterator tokenIterator = getTokenIterator(fti,indexTable); 130 return GeneralPurposeStaticClass.getIndexedFilteredIterator(tokenIterator, termCondition); 131 } 132 133 140 private _FullTextIndexInformation getFullTextInformation(Object indexTable) throws DException{ 141 _FullTextIndexInformation[] fullTextIndexInfo = ( (_IndexTable) indexTable). 142 getFullTextIndexInformation(); 143 for(int i = 0;i<fullTextIndexInfo.length;i++){ 144 String [] columnNames = fullTextIndexInfo[i].getColumnName(); 145 if ((columnName.equalsIgnoreCase(fullTextIndexInfo[i].getIndexName())) || (columnNames.length ==1 && (columnName.equalsIgnoreCase(columnNames[0])))) 146 return fullTextIndexInfo[i]; 147 } 148 throw new DException("DSE0",new Object []{"Invalid Column = "+columnName}); 149 } 150 151 154 public _Iterator getTokenIterator(Object indexTable) throws DException{ 155 return execute(indexTable); 156 } 157 164 private _Iterator getTokenIterator(_FullTextIndexInformation fti,Object indexTable) throws DException{ 165 _IndexTable token = (_IndexTable)((_IndexTable)indexTable).getDatabase().getTable(fti.getTokenTableName()); 166 _IndexInformation[] indexInfo = token.getIndexInformations(); 167 for (int i = 0; i < indexInfo.length; i++) { 168 String [] cName = indexInfo[i].getColumns(); 169 if(cName[0].equalsIgnoreCase("term")){ return token.getIterator(i); 171 } 172 } 173 throw new DException("DSE0",new Object []{"Invalid FullTextIndex - "+fti}); 174 } 175 181 public _Reference getFpkReference() throws DException{ 182 return locationCondition.getReferences(null)[0]; 183 } 184 185 192 public _Iterator getLocationIterator(Object indexTable) throws DException{ 193 _FullTextIndexInformation fti = getFullTextInformation(indexTable); 194 _Iterator locationIterator = getLocationIterator(fti,indexTable); 195 return GeneralPurposeStaticClass.getIndexedFilteredIterator (locationIterator, locationCondition); 196 } 197 198 206 private _Iterator getLocationIterator(_FullTextIndexInformation fti,Object indexTable) throws DException{ 207 _IndexTable location = (_IndexTable)((_IndexTable)indexTable).getDatabase().getTable(fti.getLocationTableName()); 208 _IndexInformation[] indexInfo = location.getIndexInformations(); 209 for (int i = 0; i < indexInfo.length; i++) { 210 String [] cName = indexInfo[i].getColumns(); 211 if(cName[0].equalsIgnoreCase("fpk")){ return location.getIterator(i); 213 } 214 } 215 throw new DException("DSE0",new Object []{"Invalid FullTextIndex - "+fti}); 216 } 217 218 public double getCost() throws DException { 219 return 0.0; 220 } 221 public double getEstimatedRow() throws DException { 222 return 0.0; 223 } 224 public void setOrder(_Order order) throws DException { 225 this.order = order; 226 } 227 public _Order getOrder() throws DException { 228 return order; 229 } 230 237 public _Iterator executeForSortedResult(Object indexTable) throws DException{ 238 return execute(indexTable); 239 } 240 247 248 public boolean equals(Object obj){ 249 try { 250 return new String ((byte[])word.getObject()).equalsIgnoreCase( new String ((byte[])((WordRepresentation) obj).word.getObject())); 251 } 252 catch (DException ex) { 253 throw new RuntimeException (ex.getMessage()); 254 } 255 } 256 257 } 258 | Popular Tags |