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.logging.LogEvent;
014: import com.versant.core.logging.LogEvent;
015:
016: /**
017: * JDBC related performance events.
018: */
019: public class JdbcLogEvent extends LogEvent {
020:
021: protected int type;
022: protected String descr;
023:
024: public static final int CON_OPEN = 0;
025: public static final int CON_CLOSE = 1;
026: public static final int CON_COMMIT = 2;
027: public static final int CON_ROLLBACK = 3;
028: public static final int CON_AUTOCOMMIT = 4;
029: public static final int CON_ISOLATION = 30;
030: public static final int CON_CREATE_STATEMENT = 5;
031: public static final int CON_PREPARE_STATEMENT = 6;
032: public static final int CON_PREPARE_CALL = 7;
033:
034: public static final int STAT_EXEC_QUERY = 8;
035: public static final int STAT_EXEC_UPDATE = 9;
036: public static final int STAT_EXEC = 10;
037: public static final int STAT_CLOSE = 11;
038: public static final int STAT_ADD_BATCH = 12;
039: public static final int STAT_EXEC_BATCH = 13;
040: public static final int STAT_MAX_ROWS = 28;
041:
042: public static final int RS_CLOSE = 14;
043: public static final int RS_NEXT = 15;
044: public static final int RS_RELATIVE = 16;
045: public static final int RS_ABSOLUTE = 17;
046: public static final int RS_LAST = 18;
047: public static final int RS_GET_ROW = 19;
048: public static final int RS_FETCH_SIZE = 20;
049:
050: public static final int QUERY_COMPILE = 21;
051:
052: public static final int POOL_ALLOC = 22;
053: public static final int POOL_RELEASE = 23;
054: public static final int POOL_BAD_CON = 24;
055: public static final int POOL_CON_FAILED = 25;
056: public static final int POOL_CON_TIMEOUT = 29;
057: public static final int POOL_CON_EXPIRED = 32;
058: public static final int POOL_FULL = 31;
059:
060: public static final int PSPOOL_ALLOC = 26;
061: public static final int PSPOOL_RELEASE = 27;
062:
063: public JdbcLogEvent(long txId, int type, String descr) {
064: this .datastoreTxId = txId;
065: this .type = type;
066: this .descr = descr;
067: }
068:
069: /**
070: * Get a short descriptive name for this event.
071: */
072: public String getName() {
073: switch (type) {
074: case CON_OPEN:
075: return "jdbc.con.connect";
076: case CON_CLOSE:
077: return "jdbc.con.close";
078: case CON_COMMIT:
079: return "jdbc.con.commit";
080: case CON_ROLLBACK:
081: return "jdbc.con.rollback";
082: case CON_AUTOCOMMIT:
083: return "jdbc.con.autoCommit";
084: case CON_ISOLATION:
085: return "jdbc.con.isolation";
086: case CON_CREATE_STATEMENT:
087: return "jdbc.con.createStat";
088: case CON_PREPARE_STATEMENT:
089: return "jdbc.con.prepareStat";
090: case CON_PREPARE_CALL:
091: return "jdbc.con.prepareCall";
092:
093: case STAT_EXEC_QUERY:
094: return "jdbc.stat.execQuery";
095: case STAT_EXEC_UPDATE:
096: return "jdbc.stat.execUpdate";
097: case STAT_EXEC:
098: return "jdbc.stat.exec";
099: case STAT_CLOSE:
100: return "jdbc.stat.close";
101: case STAT_ADD_BATCH:
102: return "jdbc.stat.addBatch";
103: case STAT_EXEC_BATCH:
104: return "jdbc.stat.execBatch";
105: case STAT_MAX_ROWS:
106: return "jdbc.stat.maxrows";
107:
108: case RS_CLOSE:
109: return "jdbc.rs.close";
110: case RS_NEXT:
111: return "jdbc.rs.next";
112: case RS_RELATIVE:
113: return "jdbc.rs.relative";
114: case RS_ABSOLUTE:
115: return "jdbc.rs.absolute";
116: case RS_LAST:
117: return "jdbc.rs.last";
118: case RS_GET_ROW:
119: return "jdbc.rs.getrow";
120: case RS_FETCH_SIZE:
121: return "jdbc.rs.fetchsize";
122:
123: case QUERY_COMPILE:
124: return "jdbc.query.compile";
125:
126: case POOL_ALLOC:
127: return "jdbc.pool.alloc";
128: case POOL_RELEASE:
129: return "jdbc.pool.release";
130: case POOL_BAD_CON:
131: return "jdbc.pool.badcon";
132: case POOL_CON_FAILED:
133: return "jdbc.pool.confailed";
134: case POOL_CON_TIMEOUT:
135: return "jdbc.pool.contimeout";
136: case POOL_CON_EXPIRED:
137: return "jdbc.pool.conexpired";
138: case POOL_FULL:
139: return "jdbc.pool.full";
140:
141: case PSPOOL_ALLOC:
142: return "jdbc.pspool.alloc";
143: case PSPOOL_RELEASE:
144: return "jdbc.pspool.release";
145: }
146: return "jdbc.UNKNOWN(" + type + ")";
147: }
148:
149: public String toString() {
150: String d = getDescription();
151: if (d == null) {
152: return getName();
153: } else {
154: StringBuffer s = new StringBuffer();
155: s.append(getName());
156: for (int n = 22 - s.length(); n > 0; n--)
157: s.append(' ');
158: s.append(d);
159: return s.toString();
160: }
161: }
162:
163: public String getDescr() {
164: return descr;
165: }
166:
167: public void setDescr(String descr) {
168: this .descr = descr;
169: }
170:
171: /**
172: * Get a long description for this event (e.g. the query text).
173: */
174: public String getDescription() {
175: return descr;
176: }
177:
178: public boolean isOwnTab() {
179: switch (type) {
180: case STAT_EXEC:
181: case STAT_EXEC_BATCH:
182: case STAT_EXEC_QUERY:
183: case STAT_EXEC_UPDATE:
184: return true;
185: }
186: return false;
187: }
188:
189: /**
190: * Get the type of this event (STAT_EXEC_QUERY etc).
191: */
192: public int getType() {
193: return type;
194: }
195: }
|