001: /*
002: * Copyright 2004 Clinton Begin
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package com.ibatis.common.jdbc.logging;
017:
018: import java.util.*;
019:
020: /**
021: * Base class for proxies to do logging
022: */
023: public class BaseLogProxy {
024:
025: private static int nextId = 100000;
026: protected static final Set SET_METHODS = new HashSet();
027: protected static final Set GET_METHODS = new HashSet();
028: protected static final Set EXECUTE_METHODS = new HashSet();
029:
030: private Map columnMap = new HashMap();
031:
032: private List columnNames = new ArrayList();
033: private List columnValues = new ArrayList();
034:
035: protected int id;
036:
037: /**
038: * Default constructor
039: */
040: public BaseLogProxy() {
041: id = getNextId();
042: }
043:
044: static {
045: SET_METHODS.add("setString");
046: SET_METHODS.add("setInt");
047: SET_METHODS.add("setByte");
048: SET_METHODS.add("setShort");
049: SET_METHODS.add("setLong");
050: SET_METHODS.add("setDouble");
051: SET_METHODS.add("setFloat");
052: SET_METHODS.add("setTimestamp");
053: SET_METHODS.add("setDate");
054: SET_METHODS.add("setTime");
055: SET_METHODS.add("setArray");
056: SET_METHODS.add("setBigDecimal");
057: SET_METHODS.add("setAsciiStream");
058: SET_METHODS.add("setBinaryStream");
059: SET_METHODS.add("setBlob");
060: SET_METHODS.add("setBoolean");
061: SET_METHODS.add("setBytes");
062: SET_METHODS.add("setCharacterStream");
063: SET_METHODS.add("setClob");
064: SET_METHODS.add("setObject");
065: SET_METHODS.add("setNull");
066:
067: GET_METHODS.add("getString");
068: GET_METHODS.add("getInt");
069: GET_METHODS.add("getByte");
070: GET_METHODS.add("getShort");
071: GET_METHODS.add("getLong");
072: GET_METHODS.add("getDouble");
073: GET_METHODS.add("getFloat");
074: GET_METHODS.add("getTimestamp");
075: GET_METHODS.add("getDate");
076: GET_METHODS.add("getTime");
077: GET_METHODS.add("getArray");
078: GET_METHODS.add("getBigDecimal");
079: GET_METHODS.add("getAsciiStream");
080: GET_METHODS.add("getBinaryStream");
081: GET_METHODS.add("getBlob");
082: GET_METHODS.add("getBoolean");
083: GET_METHODS.add("getBytes");
084: GET_METHODS.add("getCharacterStream");
085: GET_METHODS.add("getClob");
086: GET_METHODS.add("getObject");
087: GET_METHODS.add("getNull");
088:
089: EXECUTE_METHODS.add("execute");
090: EXECUTE_METHODS.add("executeUpdate");
091: EXECUTE_METHODS.add("executeQuery");
092:
093: }
094:
095: protected void setColumn(Object key, Object value) {
096: columnMap.put(key, value);
097: columnNames.add(key);
098: columnValues.add(value);
099: }
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(
134: '\t', ' ');
135: }
136:
137: protected synchronized static int getNextId() {
138: return nextId++;
139: }
140:
141: }
|