01: /*
02: * Craftsman Spy.
03: * Copyright (C) 2005 Sébastien LECACHEUR
04: *
05: * This program is free software; you can redistribute it and/or modify
06: * it under the terms of the GNU General Public License as published by
07: * the Free Software Foundation; either version 2 of the License, or
08: * (at your option) any later version.
09: *
10: * This program is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13: * GNU General Public License for more details.
14: *
15: * You should have received a copy of the GNU General Public License
16: * along with this program; if not, write to the Free Software
17: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18: */
19: package craftsman.spy;
20:
21: import java.sql.Connection;
22: import java.sql.SQLException;
23:
24: import org.apache.commons.logging.Log;
25: import org.apache.commons.logging.LogFactory;
26:
27: /**
28: * This classe is the base of the Spy JDBC implementation.
29: *
30: * @author Sébastien LECACHEUR
31: */
32: public class SpyEntity {
33: /**
34: * Internal used logger.
35: */
36: protected Log log = LogFactory.getLog(this .getClass().getName());
37:
38: /**
39: * The internal reference to the used JDBC connection.
40: */
41: private Connection connection = null;
42:
43: /**
44: * Constructs a new Spy entoty from a JDBC connection.
45: * @param c Connection The used JDBC connection.
46: */
47: public SpyEntity(Connection c) {
48: connection = c;
49: }
50:
51: /**
52: * Returns the used JDBC connection identifier.
53: * @return int The JDBC connection has code otherwise
54: * <code>0</code>.
55: */
56: public int getId() {
57: return connection != null ? (connection instanceof SpyConnection ? ((SpyConnection) connection)
58: .getId()
59: : connection.hashCode())
60: : 0;
61: }
62:
63: /**
64: * Returns the used JDBC connection.
65: * @return Connection The used JDBC connection.
66: * @throws SQLException If a database access error occurs.
67: * But in this case, the exception will be never throwed.
68: */
69: public Connection getConnection() throws SQLException {
70: return connection;
71: }
72: }
|