1 package com.daffodilwoods.daffodildb.server.sql99.fulltext.dml; 2 3 import com.daffodilwoods.fulltext.common._FullTextDML; 4 import com.daffodilwoods.fulltext.common._FullTextDocumentParser; 5 import com.daffodilwoods.fulltext.common._FullTextModifications; 6 import com.daffodilwoods.fulltext.common._FullTextAdapter; 7 import com.daffodilwoods.database.resource.DException; 8 import com.daffodilwoods.daffodildb.server.datasystem.interfaces._DatabaseUser; 9 import com.daffodilwoods.daffodildb.utils.field.FieldBase; 10 import com.daffodilwoods.daffodildb.utils.FieldUtility; 11 import com.daffodilwoods.daffodildb.server.datasystem.interfaces.Datatype; 12 import com.daffodilwoods.fulltext.common._Tokenizer; 13 import java.util.TreeSet ; 14 import java.util.TreeMap ; 15 import com.daffodilwoods.fulltext.common._Token; 16 import java.util.Iterator ; 17 import com.daffodilwoods.database.utility.*; 18 19 29 public class DaffodilFullTextDML 30 implements _FullTextDML { 31 32 35 private _FullTextDocumentParser documentParser; 36 39 private _FullTextModifications tokenModification; 40 43 private _FullTextModifications locationModification; 44 47 private int[] columnIndex; 48 51 private _FullTextIndexInformation fullTextIndexInformation; 52 53 public DaffodilFullTextDML(_FullTextDocumentParser documentParser0, 54 _FullTextAdapter adapter) throws DException { 55 documentParser = documentParser0; 56 tokenModification = adapter.getTokenTable(); 57 locationModification = adapter.getLocationTable(); 58 columnIndex = adapter.getColumnIndex(); 59 } 60 61 75 76 public void insert(_DatabaseUser user, Object columnValue, Object pk) throws 77 DException { 78 FieldBase[] objs = (FieldBase[]) columnValue; 79 TreeMap map = new TreeMap (new Comparator()); 80 long startlocation = 0; 81 for (int i = 0; i < objs.length; i++) { 82 if (!objs[i].isNull()) { 83 _Tokenizer tokenizer = documentParser.getTokenizer(objs[i], 84 startlocation); 85 _Token token=null; 86 long[] loc; 87 while (tokenizer.hasMoreToken()) { 88 token = tokenizer.nextToken(); 89 _Token tkn = (_Token) map.get(token); 90 if (tkn == null) { 91 map.put(token, token); 92 } 93 else { 94 loc = token.getLocation(); 95 tkn.addLocation(loc); 96 } 97 } 98 99 if(token != null){ 100 loc = token.getLocation(); 101 startlocation = loc[loc.length - 1] + 1; 102 } 103 } 104 } 105 Iterator iter = map.keySet().iterator(); 106 while (iter.hasNext()) { 107 _Token token = (_Token) iter.next(); 108 Object lastPK = getLastPK(); 109 tokenModification.insert(user, new Object [] {lastPK, token.getTerm(), 110 pk}); 111 long[] locations = token.getLocation(); 112 for (int j = 0; j < locations.length; j++) { 113 locationModification.insert(user, new Object [] {lastPK, 114 FieldUtility.getField(Datatype.LONG, 115 new Long (locations[j])), pk}); 116 } 117 } 118 } 119 120 128 private synchronized Object getLastPK() throws DException { 129 Object lastPK = tokenModification.getLastPK(); 130 Long result = new Long ( ( (Long ) ( (FieldBase) lastPK).getObject()). 131 longValue() + 1); 132 return FieldUtility.getField(Datatype.LONG, result); 133 } 134 135 144 public void update(_DatabaseUser user, Object oldColumnValue, 145 Object newColumnValue, Object pk) throws DException { 146 Object [] newValues = (Object []) newColumnValue; 147 Object [] oldValues = (Object []) oldColumnValue; 148 boolean isSame = true; 149 for (int i = 0; i < newValues.length; i++) { 150 if (!newValues[i].equals(oldValues[i])) { 151 isSame = false; 152 break; 153 } 154 } 155 if (isSame) 156 return; 157 delete(user, pk); 158 insert(user, newColumnValue, pk); 159 } 160 161 168 public void delete(_DatabaseUser user, Object pk) throws DException { 169 tokenModification.delete(user, pk); 170 locationModification.delete(user, pk); 171 } 172 173 177 public int[] getColumnIndex() { 178 return this.columnIndex; 179 180 } 181 182 186 public void setFullTextIndexInformation(_FullTextIndexInformation 187 fullTextIndexInformation0) { 188 this.fullTextIndexInformation = fullTextIndexInformation0; 189 } 190 191 195 public _FullTextIndexInformation getFullTextIndexInformation() { 196 return this.fullTextIndexInformation; 197 } 198 } 199 | Popular Tags |