1 21 22 package org.apache.derby.diag; 23 24 import org.apache.derby.iapi.services.monitor.Monitor; 25 import org.apache.derby.iapi.services.sanity.SanityManager; 26 27 import org.apache.derby.iapi.sql.conn.LanguageConnectionContext; 28 import org.apache.derby.iapi.sql.conn.ConnectionUtil; 29 import org.apache.derby.iapi.store.access.AccessFactory; 30 import org.apache.derby.iapi.store.access.TransactionInfo; 31 32 import org.apache.derby.vti.VTITemplate; 33 import org.apache.derby.vti.VTICosting; 34 import org.apache.derby.vti.VTIEnvironment; 35 36 import org.apache.derby.iapi.sql.ResultColumnDescriptor; 37 import org.apache.derby.impl.jdbc.EmbedResultSetMetaData; 38 39 import org.apache.derby.iapi.reference.Limits; 40 import org.apache.derby.iapi.util.StringUtil; 41 42 import java.sql.ResultSetMetaData ; 43 import java.sql.SQLException ; 44 import java.sql.Types ; 45 46 86 public class TransactionTable extends VTITemplate implements VTICosting { 87 88 private TransactionInfo[] transactionTable; 89 boolean initialized; 90 int currentRow; 91 private boolean wasNull; 92 93 96 public ResultSetMetaData getMetaData() 97 { 98 return metadata; 99 } 100 101 105 public boolean next() throws SQLException 106 { 107 if (!initialized) 108 { 109 LanguageConnectionContext lcc = ConnectionUtil.getCurrentLCC(); 110 111 AccessFactory af = lcc.getLanguageConnectionFactory().getAccessFactory(); 112 transactionTable = af.getTransactionInfo(); 113 114 initialized = true; 115 currentRow = -1; 116 } 117 118 if (transactionTable == null) 119 return false; 120 121 for (currentRow++; 122 currentRow < transactionTable.length; 123 currentRow++) 124 { 125 TransactionInfo info = transactionTable[currentRow]; 126 if (info == null) 127 continue; return true; 130 } 131 132 transactionTable = null; 134 return false; 135 } 136 137 140 public void close() 141 { 142 transactionTable = null; 143 } 144 145 149 public String getString(int columnNumber) 150 { 151 TransactionInfo info = transactionTable[currentRow]; 152 String str = null; 153 154 switch(columnNumber) 155 { 156 case 1: 157 str = info.getTransactionIdString(); break; 158 159 case 2: 160 str = info.getGlobalTransactionIdString(); break; 161 162 case 3: 163 str = info.getUsernameString(); break; 164 165 case 4: 166 str = info.getTransactionTypeString(); break; 167 168 case 5: 169 str = info.getTransactionStatusString(); break; 170 171 case 6: 172 str = info.getFirstLogInstantString(); break; 173 174 case 7: 175 176 str = info.getStatementTextString(); 177 str = StringUtil.truncate(str, Limits.DB2_VARCHAR_MAXWIDTH); 178 break; 179 180 default: 181 str = null; 182 } 183 184 wasNull = (str == null); 185 return str; 186 187 } 188 189 192 public boolean wasNull() 193 { 194 return wasNull; 195 } 196 197 198 199 200 203 public double getEstimatedRowCount(VTIEnvironment vtiEnvironment) 204 { 205 return VTICosting.defaultEstimatedRowCount; 206 } 207 208 211 public double getEstimatedCostPerInstantiation(VTIEnvironment vtiEnvironment) 212 { 213 return VTICosting.defaultEstimatedCost; 214 } 215 216 220 public boolean supportsMultipleInstantiations(VTIEnvironment vtiEnvironment) 221 { 222 return false; 223 } 224 225 226 229 private static final ResultColumnDescriptor[] columnInfo = { 230 231 EmbedResultSetMetaData.getResultColumnDescriptor("XID", Types.VARCHAR, false, 15), 232 EmbedResultSetMetaData.getResultColumnDescriptor("GLOBAL_XID", Types.VARCHAR, true, 140), 233 EmbedResultSetMetaData.getResultColumnDescriptor("USERNAME", Types.VARCHAR, true, 128), 234 EmbedResultSetMetaData.getResultColumnDescriptor("TYPE", Types.VARCHAR, false, 30), 235 EmbedResultSetMetaData.getResultColumnDescriptor("STATUS", Types.VARCHAR, false, 8), 236 EmbedResultSetMetaData.getResultColumnDescriptor("FIRST_INSTANT", Types.VARCHAR, true, 20), 237 EmbedResultSetMetaData.getResultColumnDescriptor("SQL_TEXT", Types.VARCHAR, true, Limits.DB2_VARCHAR_MAXWIDTH), 238 }; 239 240 private static final ResultSetMetaData metadata = new EmbedResultSetMetaData(columnInfo); 241 } 242 243 | Popular Tags |