1 21 22 package org.apache.derby.impl.sql.execute; 23 24 import org.apache.derby.iapi.services.sanity.SanityManager; 25 26 import org.apache.derby.iapi.error.StandardException; 27 28 import org.apache.derby.iapi.sql.conn.LanguageConnectionContext; 29 30 import org.apache.derby.iapi.types.DataValueDescriptor; 31 32 import org.apache.derby.iapi.sql.execute.CursorResultSet; 33 import org.apache.derby.iapi.sql.execute.ExecRow; 34 import org.apache.derby.iapi.sql.execute.NoPutResultSet; 35 36 import org.apache.derby.iapi.sql.Activation; 37 import org.apache.derby.iapi.sql.ResultDescription; 38 39 import java.sql.PreparedStatement ; 40 import java.sql.ResultSet ; 41 42 import java.util.Properties ; 43 44 48 class UpdateVTIResultSet extends DMLVTIResultSet 49 { 50 private java.sql.ResultSet rs; 51 52 private TemporaryRowHolderImpl rowHolder; 53 54 58 public UpdateVTIResultSet(NoPutResultSet source, 59 Activation activation) 60 throws StandardException 61 { 62 super(source, activation); 63 } 64 65 66 69 protected void openCore() throws StandardException 70 { 71 int rowLocationColumn = -1; 72 boolean firstRow = true; 73 74 rs = activation.getTargetVTI(); 75 ExecRow row = getNextRowCore(sourceResultSet); 76 77 if( null != row) 78 rowLocationColumn = row.nColumns(); 79 if (!firstExecute) 80 lcc.getStatementContext().setTopResultSet(this, subqueryTrackingArray); 81 82 88 if (constants.deferred) 89 { 90 activation.clearIndexScanInfo(); 91 } 92 93 if (null == rowHolder && constants.deferred) 94 { 95 Properties properties = new Properties (); 96 97 100 rowHolder = 101 new TemporaryRowHolderImpl(activation, properties, 102 resultDescription); 103 } 104 105 try 106 { 107 while ( row != null ) 108 { 109 if (constants.deferred) 110 { 111 if( firstRow) 113 { 114 row.getColumn( rowLocationColumn).setValue( rs.getRow()); 115 firstRow = false; 116 } 117 else 118 { 119 DataValueDescriptor rowLocation = row.cloneColumn( rowLocationColumn); 120 rowLocation.setValue( rs.getRow()); 121 row.setColumn( rowLocationColumn, rowLocation); 122 } 123 rowHolder.insert(row); 124 } 125 else 126 updateVTI(rs, row); 127 rowCount++; 128 129 if (constants.singleRowSource) 131 { 132 row = null; 133 } 134 else 135 { 136 row = getNextRowCore(sourceResultSet); 137 } 138 } 139 } 140 catch (StandardException se) 141 { 142 throw se; 143 } 144 catch (Throwable t) 145 { 146 throw StandardException.unexpectedUserException(t); 147 } 148 149 153 if (constants.deferred) 154 { 155 CursorResultSet tempRS = rowHolder.getResultSet(); 156 try 157 { 158 tempRS.open(); 159 while ((row = tempRS.getNextRow()) != null) 160 { 161 int rowNumber = row.getColumn( rowLocationColumn).getInt(); 162 rs.absolute( rowNumber); 163 updateVTI(rs, row); 164 } 165 } 166 catch (Throwable t) 167 { 168 throw StandardException.unexpectedUserException(t); 169 } 170 finally 171 { 172 sourceResultSet.clearCurrentRow(); 173 tempRS.close(); 174 } 175 } 176 177 if (rowHolder != null) 178 { 179 rowHolder.close(); 180 } 182 } 184 private void updateVTI(ResultSet target, ExecRow row) 185 throws StandardException 186 { 187 int[] changedColumnIds = constants.changedColumnIds; 188 try 189 { 190 for( int i = 0; i < changedColumnIds.length; i++) 191 { 192 int columnId = changedColumnIds[i]; 193 DataValueDescriptor newValue = row.getColumn( i + 1); 194 if( newValue.isNull()) 195 target.updateNull( columnId); 196 else 197 newValue.setInto( target, columnId); 198 } 199 target.updateRow(); 200 } 201 catch (Throwable t) 202 { 203 throw StandardException.unexpectedUserException(t); 204 } 205 } } 207 | Popular Tags |