1 2 12 package com.versant.core.jdbc.logging; 13 14 import com.versant.core.jdbc.metadata.JdbcTypes; 15 16 import java.sql.Statement ; 17 import java.util.List ; 18 import java.util.Arrays ; 19 import java.io.Serializable ; 20 21 25 public class JdbcStatementParamsEvent extends JdbcStatementEvent { 26 27 30 public static class Row implements Serializable { 31 32 public Object [] values; 33 public int[] sqlTypes; 34 public int size; 35 36 public Row(int sz) { 37 values = new Object [sz]; 38 sqlTypes = new int[sz]; 39 } 40 41 public void set(int index, Object value, int sqlType) { 42 if (--index >= values.length) { 43 int len = values.length; 44 Object [] o = new Object [len * 2]; 45 System.arraycopy(values, 0, o, 0, len); 46 int[] t = new int[len * 2]; 47 System.arraycopy(sqlTypes, 0, t, 0, len); 48 values = o; 49 sqlTypes = t; 50 } 51 if (index >= size) size = index + 1; 52 values[index] = value; 53 sqlTypes[index] = sqlType; 54 } 55 56 public void trim() { 57 if (size == values.length) return; 58 Object [] o = new Object [size]; 59 System.arraycopy(values, 0, o, 0, size); 60 int[] t = new int[size]; 61 System.arraycopy(sqlTypes, 0, t, 0, size); 62 values = o; 63 sqlTypes = t; 64 } 65 66 public String toString() { 67 return getStringValue(); 68 } 69 70 public List getValueList() { 71 return Arrays.asList(values); 72 } 73 74 public String getStringValue() { 75 StringBuffer s = new StringBuffer (); 76 s.append('['); 77 for (int i = 0; i < size; i++) { 78 if (i > 0) s.append(", "); 79 Object v = values[i]; 80 try { 81 s.append(v); 82 } catch (Exception e) { 83 s.append("<toString failed: " + e + ">"); 84 } 85 if (v == null) { 86 s.append('('); 87 s.append(JdbcTypes.toString(sqlTypes[i])); 88 s.append(')'); 89 } 90 } 91 s.append(']'); 92 return s.toString(); 93 } 94 95 public void setStringValue(String s) { 96 } 98 99 } 100 101 private Row[] params; 102 103 public JdbcStatementParamsEvent(long txId, Statement stat, String descr, 104 int type) { 105 super(txId, stat, descr, type); 106 } 107 108 public Row[] getParams() { 109 return params; 110 } 111 112 public List getParamsList() { 113 return Arrays.asList(params); 114 } 115 116 public void setParams(Row[] params) { 117 this.params = params; 118 } 119 120 public String toString() { 121 if (params.length == 1) { 122 return super.toString() + " " + params[0]; 123 } else { 124 return super.toString() + " " + params.length + " param rows"; 125 } 126 } 127 } 128 129 | Popular Tags |