1 16 package com.ibatis.common.jdbc.logging; 17 18 import java.util.*; 19 20 23 public class BaseLogProxy { 24 25 private static int nextId = 100000; 26 protected static final Set SET_METHODS = new HashSet(); 27 protected static final Set GET_METHODS = new HashSet(); 28 protected static final Set EXECUTE_METHODS = new HashSet(); 29 30 private Map columnMap = new HashMap(); 31 32 private List columnNames = new ArrayList(); 33 private List columnValues = new ArrayList(); 34 35 protected int id; 36 37 40 public BaseLogProxy() { 41 id = getNextId(); 42 } 43 44 static { 45 SET_METHODS.add("setString"); 46 SET_METHODS.add("setInt"); 47 SET_METHODS.add("setByte"); 48 SET_METHODS.add("setShort"); 49 SET_METHODS.add("setLong"); 50 SET_METHODS.add("setDouble"); 51 SET_METHODS.add("setFloat"); 52 SET_METHODS.add("setTimestamp"); 53 SET_METHODS.add("setDate"); 54 SET_METHODS.add("setTime"); 55 SET_METHODS.add("setArray"); 56 SET_METHODS.add("setBigDecimal"); 57 SET_METHODS.add("setAsciiStream"); 58 SET_METHODS.add("setBinaryStream"); 59 SET_METHODS.add("setBlob"); 60 SET_METHODS.add("setBoolean"); 61 SET_METHODS.add("setBytes"); 62 SET_METHODS.add("setCharacterStream"); 63 SET_METHODS.add("setClob"); 64 SET_METHODS.add("setObject"); 65 SET_METHODS.add("setNull"); 66 67 GET_METHODS.add("getString"); 68 GET_METHODS.add("getInt"); 69 GET_METHODS.add("getByte"); 70 GET_METHODS.add("getShort"); 71 GET_METHODS.add("getLong"); 72 GET_METHODS.add("getDouble"); 73 GET_METHODS.add("getFloat"); 74 GET_METHODS.add("getTimestamp"); 75 GET_METHODS.add("getDate"); 76 GET_METHODS.add("getTime"); 77 GET_METHODS.add("getArray"); 78 GET_METHODS.add("getBigDecimal"); 79 GET_METHODS.add("getAsciiStream"); 80 GET_METHODS.add("getBinaryStream"); 81 GET_METHODS.add("getBlob"); 82 GET_METHODS.add("getBoolean"); 83 GET_METHODS.add("getBytes"); 84 GET_METHODS.add("getCharacterStream"); 85 GET_METHODS.add("getClob"); 86 GET_METHODS.add("getObject"); 87 GET_METHODS.add("getNull"); 88 89 EXECUTE_METHODS.add("execute"); 90 EXECUTE_METHODS.add("executeUpdate"); 91 EXECUTE_METHODS.add("executeQuery"); 92 93 } 94 95 protected void setColumn(Object key, Object value) { 96 columnMap.put(key, value); 97 columnNames.add(key); 98 columnValues.add(value); 99 } 100 101 protected Object getColumn(Object key) { 102 return columnMap.get(key); 103 } 104 105 protected String getValueString() { 106 return columnValues.toString(); 107 } 108 109 protected String getTypeString() { 110 List typeList = new ArrayList(columnValues.size()); 111 for (int i = 0; i < columnValues.size(); i++) { 112 Object value = columnValues.get(i); 113 if (value == null) { 114 typeList.add("null"); 115 } else { 116 typeList.add(value.getClass().getName()); 117 } 118 } 119 return typeList.toString(); 120 } 121 122 protected String getColumnString() { 123 return columnNames.toString(); 124 } 125 126 protected void clearColumnInfo() { 127 columnMap.clear(); 128 columnNames.clear(); 129 columnValues.clear(); 130 } 131 132 protected String removeBreakingWhitespace(String original) { 133 return original.replace('\n', ' ').replace('\r', ' ').replace('\t', ' '); 134 } 135 136 protected synchronized static int getNextId() { 137 return nextId++; 138 } 139 140 } 141 | Popular Tags |