01: /*
02: * The contents of this file are subject to the Mozilla Public License
03: * Version 1.1 (the "License"); you may not use this file except in
04: * compliance with the License. You may obtain a copy of the License at
05: * http://www.mozilla.org/MPL/
06: *
07: * Software distributed under the License is distributed on an "AS IS"
08: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
09: * License for the specific language governing rights and limitations
10: * under the License.
11: *
12: * The Original Code is iSQL-Viewer, A Mutli-Platform Database Tool.
13: *
14: * The Initial Developer of the Original Code is iSQL-Viewer, A Mutli-Platform Database Tool.
15: * Portions created by Mark A. Kobold are Copyright (C) 2000-2007. All Rights Reserved.
16: *
17: * Contributor(s):
18: * Mark A. Kobold [mkobold <at> isqlviewer <dot> com].
19: *
20: * If you didn't download this code from the following link, you should check
21: * if you aren't using an obsolete version: http://www.isqlviewer.com
22: */
23: package org.isqlviewer.sql.platform;
24:
25: import java.net.InetAddress;
26: import java.net.UnknownHostException;
27: import java.sql.CallableStatement;
28: import java.sql.Connection;
29: import java.sql.SQLException;
30:
31: import org.isqlviewer.sql.PlatformRegistrar;
32: import org.isqlviewer.util.IsqlToolkit;
33: import org.isqlviewer.util.LoggableObject;
34:
35: /**
36: * Oracle Session registration code.
37: * <p>
38: * makes a call to DBMS_APPLICATION_INFO.SET_CLIENT_INFO(?) identifying the session as an iSQL-Viewer session to the
39: * database server, and any DBA's looking into V$SESSION or whatever that table is.
40: *
41: * @author Mark A. Kobold <mkobold at isqlviewer dot com>
42: * @version 1.0
43: */
44: public class OracleRegistrar extends LoggableObject implements
45: PlatformRegistrar {
46:
47: public boolean register(Connection nativeConnection)
48: throws SQLException {
49:
50: CallableStatement insertEvent = null;
51: String hostname = null;
52: try {
53: hostname = InetAddress.getLocalHost().toString();
54: } catch (UnknownHostException uhe) {
55: hostname = "localhost/unknown";
56: }
57:
58: String appid = "iSQL-Viewer/" + IsqlToolkit.getVersionInfo()
59: + "@" + hostname;
60: try {
61: insertEvent = nativeConnection
62: .prepareCall("{ call dbms_application_info.set_client_info(?) }");
63: insertEvent.setString(1, appid);
64: insertEvent.execute();
65: return true;
66: } finally {
67: if (insertEvent != null) {
68: try {
69: insertEvent.close();
70: } catch (SQLException sqle) {
71: }
72: }
73: }
74:
75: }
76:
77: }
|