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 import org.apache.derby.iapi.sql.conn.LanguageConnectionContext; 27 import org.apache.derby.iapi.sql.execute.CursorResultSet; 28 import org.apache.derby.iapi.sql.execute.ExecRow; 29 import org.apache.derby.iapi.sql.execute.NoPutResultSet; 30 import org.apache.derby.iapi.sql.Activation; 31 import org.apache.derby.iapi.sql.ResultDescription; 32 33 import org.apache.derby.iapi.store.access.TransactionController; 34 35 import org.apache.derby.iapi.types.SQLInteger; 36 37 import java.util.Properties ; 38 39 45 class DeleteVTIResultSet extends DMLVTIResultSet 46 { 47 48 private java.sql.ResultSet rs; 49 private TemporaryRowHolderImpl rowHolder; 50 54 55 59 63 public DeleteVTIResultSet 64 ( 65 NoPutResultSet source, 66 Activation activation 67 ) 68 throws StandardException 69 { 70 super(source, activation); 71 } 72 73 76 protected void openCore() throws StandardException 77 { 78 lcc.getStatementContext().setTopResultSet(this, subqueryTrackingArray); 79 80 ExecRow row = getNextRowCore(sourceResultSet); 81 82 if (row != null) 83 { 84 rs = activation.getTargetVTI(); 85 86 if (SanityManager.DEBUG) 87 { 88 SanityManager.ASSERT(rs != null, 89 "rs expected to be non-null"); 90 } 91 } 92 93 94 100 if (constants.deferred) 101 { 102 activation.clearIndexScanInfo(); 103 if( null == rowHolder) 104 rowHolder = 105 new TemporaryRowHolderImpl(activation, new Properties (), 106 (ResultDescription) null); 107 } 108 109 try 110 { 111 while ( row != null ) 112 { 113 if( !constants.deferred) 114 rs.deleteRow(); 115 else 116 { 117 ExecRow rowId = new ValueRow(1); 118 rowId.setColumn( 1, new SQLInteger( rs.getRow())); 119 rowHolder.insert( rowId); 120 } 121 122 rowCount++; 123 124 if (constants.singleRowSource) 126 { 127 row = null; 128 } 129 else 130 { 131 row = getNextRowCore(sourceResultSet); 132 } 133 } 134 } 135 catch (StandardException se) 136 { 137 throw se; 138 } 139 catch (Throwable t) 140 { 141 throw StandardException.unexpectedUserException(t); 142 } 143 144 if (constants.deferred) 145 { 146 CursorResultSet tempRS = rowHolder.getResultSet(); 147 try 148 { 149 ExecRow deferredRowBuffer = null; 150 151 tempRS.open(); 152 while ((deferredRowBuffer = tempRS.getNextRow()) != null) 153 { 154 int rowNumber = deferredRowBuffer.getColumn( 1).getInt(); 155 rs.absolute( rowNumber); 156 rs.deleteRow(); 157 } 158 } 159 catch (Throwable t) 160 { 161 throw StandardException.unexpectedUserException(t); 162 } 163 finally 164 { 165 sourceResultSet.clearCurrentRow(); 166 tempRS.close(); 167 } 168 } 169 170 if (rowHolder != null) 171 { 172 rowHolder.close(); 173 } 175 } } 177 | Popular Tags |