001: /*
002: * Copyright (c) 1998 - 2005 Versant Corporation
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * Versant Corporation - initial API and implementation
010: */
011: package com.versant.core.jdbc.logging;
012:
013: import com.versant.core.jdbc.metadata.JdbcTypes;
014:
015: import java.sql.Statement;
016: import java.util.List;
017: import java.util.Arrays;
018: import java.io.Serializable;
019:
020: /**
021: * A statement event with parameters.
022: * @keep-all
023: */
024: public class JdbcStatementParamsEvent extends JdbcStatementEvent {
025:
026: /**
027: * A row of parameters.
028: */
029: public static class Row implements Serializable {
030:
031: public Object[] values;
032: public int[] sqlTypes;
033: public int size;
034:
035: public Row(int sz) {
036: values = new Object[sz];
037: sqlTypes = new int[sz];
038: }
039:
040: public void set(int index, Object value, int sqlType) {
041: if (--index >= values.length) {
042: int len = values.length;
043: Object[] o = new Object[len * 2];
044: System.arraycopy(values, 0, o, 0, len);
045: int[] t = new int[len * 2];
046: System.arraycopy(sqlTypes, 0, t, 0, len);
047: values = o;
048: sqlTypes = t;
049: }
050: if (index >= size)
051: size = index + 1;
052: values[index] = value;
053: sqlTypes[index] = sqlType;
054: }
055:
056: public void trim() {
057: if (size == values.length)
058: return;
059: Object[] o = new Object[size];
060: System.arraycopy(values, 0, o, 0, size);
061: int[] t = new int[size];
062: System.arraycopy(sqlTypes, 0, t, 0, size);
063: values = o;
064: sqlTypes = t;
065: }
066:
067: public String toString() {
068: return getStringValue();
069: }
070:
071: public List getValueList() {
072: return Arrays.asList(values);
073: }
074:
075: public String getStringValue() {
076: StringBuffer s = new StringBuffer();
077: s.append('[');
078: for (int i = 0; i < size; i++) {
079: if (i > 0)
080: s.append(", ");
081: Object v = values[i];
082: try {
083: s.append(v);
084: } catch (Exception e) {
085: s.append("<toString failed: " + e + ">");
086: }
087: if (v == null) {
088: s.append('(');
089: s.append(JdbcTypes.toString(sqlTypes[i]));
090: s.append(')');
091: }
092: }
093: s.append(']');
094: return s.toString();
095: }
096:
097: public void setStringValue(String s) {
098: // dummy set so the Workbencg will allow edit for cut and paste
099: }
100:
101: }
102:
103: private Row[] params;
104:
105: public JdbcStatementParamsEvent(long txId, Statement stat,
106: String descr, int type) {
107: super (txId, stat, descr, type);
108: }
109:
110: public Row[] getParams() {
111: return params;
112: }
113:
114: public List getParamsList() {
115: return Arrays.asList(params);
116: }
117:
118: public void setParams(Row[] params) {
119: this .params = params;
120: }
121:
122: public String toString() {
123: if (params.length == 1) {
124: return super .toString() + " " + params[0];
125: } else {
126: return super .toString() + " " + params.length
127: + " param rows";
128: }
129: }
130: }
|