1 21 22 package org.apache.derby.impl.sql.execute; 23 24 import org.apache.derby.iapi.services.sanity.SanityManager; 25 import org.apache.derby.iapi.error.StandardException; 26 27 import org.apache.derby.iapi.types.DataValueDescriptor; 28 import org.apache.derby.iapi.types.RowLocation; 29 import org.apache.derby.iapi.sql.conn.LanguageConnectionContext; 30 import org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor; 31 import org.apache.derby.iapi.sql.execute.ExecRow; 32 import org.apache.derby.iapi.sql.execute.ExecIndexRow; 33 34 import org.apache.derby.iapi.store.access.ConglomerateController; 35 import org.apache.derby.iapi.store.access.DynamicCompiledOpenConglomInfo; 36 import org.apache.derby.iapi.store.access.ScanController; 37 import org.apache.derby.iapi.store.access.StaticCompiledOpenConglomInfo; 38 import org.apache.derby.iapi.store.access.TransactionController; 39 40 import org.apache.derby.iapi.services.io.FormatableBitSet; 41 import java.util.Enumeration ; 42 import java.util.Hashtable ; 43 44 48 public abstract class GenericRIChecker 49 { 50 protected FKInfo fkInfo; 51 protected DynamicCompiledOpenConglomInfo[] fkDcocis; 52 protected StaticCompiledOpenConglomInfo[] fkScocis; 53 protected DynamicCompiledOpenConglomInfo refDcoci; 54 protected StaticCompiledOpenConglomInfo refScoci; 55 protected TransactionController tc; 56 57 private Hashtable scanControllers; 58 private int numColumns; 59 private IndexRow indexQualifierRow; 60 61 67 GenericRIChecker(TransactionController tc, FKInfo fkinfo) 68 throws StandardException 69 { 70 this.fkInfo = fkinfo; 71 this.tc = tc; 72 scanControllers = new Hashtable (); 73 numColumns = fkInfo.colArray.length; 74 indexQualifierRow = new IndexRow(numColumns); 75 76 fkDcocis = new DynamicCompiledOpenConglomInfo[fkInfo.fkConglomNumbers.length]; 77 fkScocis = new StaticCompiledOpenConglomInfo[fkInfo.fkConglomNumbers.length]; 78 for (int index = 0; index < fkInfo.fkConglomNumbers.length; index++) 79 { 80 fkDcocis[index] = tc.getDynamicCompiledConglomInfo(fkInfo.fkConglomNumbers[index]); 81 fkScocis[index] = tc.getStaticCompiledConglomInfo(fkInfo.fkConglomNumbers[index]); 82 } 83 refDcoci = tc.getDynamicCompiledConglomInfo(fkInfo.refConglomNumber); 84 refScoci = tc.getStaticCompiledConglomInfo(fkInfo.refConglomNumber); 85 } 86 87 94 abstract void doCheck(ExecRow row, boolean restrictCheckOnly) throws StandardException; 95 96 public void doCheck(ExecRow row) throws StandardException 97 { 98 doCheck(row, false); } 100 101 125 protected ScanController getScanController(long conglomNumber, 126 StaticCompiledOpenConglomInfo scoci, 127 DynamicCompiledOpenConglomInfo dcoci, ExecRow searchRow) 128 throws StandardException 129 { 130 int isoLevel = getRICheckIsolationLevel(); 131 ScanController scan; 132 Long hashKey = new Long (conglomNumber); 133 134 138 if ((scan = (ScanController)scanControllers.get(hashKey)) == null) 139 { 140 setupQualifierRow(searchRow); 141 scan = 142 tc.openCompiledScan( 143 false, 0, TransactionController.MODE_RECORD, isoLevel, 147 (FormatableBitSet)null, indexQualifierRow.getRowArray(), ScanController.GE, null, indexQualifierRow.getRowArray(), ScanController.GT, scoci, 154 dcoci 155 ); 156 scanControllers.put(hashKey, scan); 157 } 158 else 159 { 160 167 setupQualifierRow(searchRow); 168 scan.reopenScan( 169 indexQualifierRow.getRowArray(), ScanController.GE, null, indexQualifierRow.getRowArray(), ScanController.GT ); 175 } 176 177 return scan; 178 } 179 180 185 private void setupQualifierRow(ExecRow baseRow) 186 { 187 DataValueDescriptor[] indexColArray = indexQualifierRow.getRowArray(); 188 DataValueDescriptor[] baseColArray = baseRow.getRowArray(); 189 190 for (int i = 0; i < numColumns; i++) 191 { 192 indexColArray[i] = baseColArray[fkInfo.colArray[i] - 1]; 193 } 194 } 195 196 201 boolean isAnyFieldNull(ExecRow baseRow) 202 { 203 DataValueDescriptor[] baseColArray = baseRow.getRowArray(); 204 205 for (int i = 0; i < numColumns; i++) 206 { 207 DataValueDescriptor storable = baseColArray[fkInfo.colArray[i] - 1]; 208 if (storable.isNull()) 209 { 210 return true; 211 } 212 } 213 return false; 214 } 215 216 217 222 void close() 223 throws StandardException 224 { 225 Enumeration e = scanControllers.elements(); 226 while (e.hasMoreElements()) 227 { 228 ScanController scan = (ScanController)e.nextElement(); 229 scan.close(); 230 } 231 scanControllers.clear(); 232 } 233 234 244 int getRICheckIsolationLevel() 245 { 246 return TransactionController.ISOLATION_READ_COMMITTED_NOHOLDLOCK; 247 } 248 } 249 | Popular Tags |