KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > craftsman > spy > SpyEntity


1 /*
2  * Craftsman Spy.
3  * Copyright (C) 2005 Sébastien LECACHEUR
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
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 JavaDoc;
22 import java.sql.SQLException JavaDoc;
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     /**
40      * The internal reference to the used JDBC connection.
41      */

42     private Connection JavaDoc connection = null;
43
44
45     /**
46      * Constructs a new Spy entoty from a JDBC connection.
47      * @param c Connection The used JDBC connection.
48      */

49     public SpyEntity ( Connection JavaDoc c) {
50         connection = c;
51     }
52
53
54     /**
55      * Returns the used JDBC connection identifier.
56      * @return int The JDBC connection has code otherwise
57      * <code>0</code>.
58      */

59     public int getId() {
60         return connection!=null?(connection instanceof SpyConnection?((SpyConnection)connection).getId():connection.hashCode()):0;
61     }
62
63
64     /**
65      * Returns the used JDBC connection.
66      * @return Connection The used JDBC connection.
67      * @throws SQLException If a database access error occurs.
68      * But in this case, the exception will be never throwed.
69      */

70     public Connection JavaDoc getConnection() throws SQLException JavaDoc {
71         return connection;
72     }
73 }
74
Popular Tags