KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > versant > core > jdbc > logging > JdbcStatementParamsEvent


1
2 /*
3  * Copyright (c) 1998 - 2005 Versant Corporation
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  * Versant Corporation - initial API and implementation
11  */

12 package com.versant.core.jdbc.logging;
13
14 import com.versant.core.jdbc.metadata.JdbcTypes;
15
16 import java.sql.Statement JavaDoc;
17 import java.util.List JavaDoc;
18 import java.util.Arrays JavaDoc;
19 import java.io.Serializable JavaDoc;
20
21 /**
22  * A statement event with parameters.
23  * @keep-all
24  */

25 public class JdbcStatementParamsEvent extends JdbcStatementEvent {
26
27     /**
28      * A row of parameters.
29      */

30     public static class Row implements Serializable JavaDoc {
31
32         public Object JavaDoc[] values;
33         public int[] sqlTypes;
34         public int size;
35
36         public Row(int sz) {
37             values = new Object JavaDoc[sz];
38             sqlTypes = new int[sz];
39         }
40
41         public void set(int index, Object JavaDoc value, int sqlType) {
42             if (--index >= values.length) {
43                 int len = values.length;
44                 Object JavaDoc[] o = new Object JavaDoc[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 JavaDoc[] o = new Object JavaDoc[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 JavaDoc toString() {
67             return getStringValue();
68         }
69
70         public List JavaDoc getValueList() {
71             return Arrays.asList(values);
72         }
73
74         public String JavaDoc getStringValue() {
75             StringBuffer JavaDoc s = new StringBuffer JavaDoc();
76             s.append('[');
77             for (int i = 0; i < size; i++) {
78                 if (i > 0) s.append(", ");
79                 Object JavaDoc v = values[i];
80                 try {
81                     s.append(v);
82                 } catch (Exception JavaDoc 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 JavaDoc s) {
96             // dummy set so the Workbencg will allow edit for cut and paste
97
}
98
99     }
100
101     private Row[] params;
102
103     public JdbcStatementParamsEvent(long txId, Statement JavaDoc stat, String JavaDoc descr,
104             int type) {
105         super(txId, stat, descr, type);
106     }
107
108     public Row[] getParams() {
109         return params;
110     }
111
112     public List JavaDoc getParamsList() {
113         return Arrays.asList(params);
114     }
115
116     public void setParams(Row[] params) {
117         this.params = params;
118     }
119
120     public String JavaDoc 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