01: //jTDS JDBC Driver for Microsoft SQL Server and Sybase
02: //Copyright (C) 2004 The jTDS Project
03: //
04: //This library is free software; you can redistribute it and/or
05: //modify it under the terms of the GNU Lesser General Public
06: //License as published by the Free Software Foundation; either
07: //version 2.1 of the License, or (at your option) any later version.
08: //
09: //This library is distributed in the hope that it will be useful,
10: //but WITHOUT ANY WARRANTY; without even the implied warranty of
11: //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12: //Lesser General Public License for more details.
13: //
14: //You should have received a copy of the GNU Lesser General Public
15: //License along with this library; if not, write to the Free Software
16: //Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17: //
18: package net.sourceforge.jtds.jdbc.cache;
19:
20: import net.sourceforge.jtds.jdbc.ConnectionJDBC2;
21:
22: /**
23: * Cache key for an SQL query, consisting of the query and server type, major
24: * and minor version.
25: *
26: * @author Brett Wooldridge
27: * @author Alin Sinpalean
28: * @version $Id: SQLCacheKey.java,v 1.2 2005/05/25 09:24:02 alin_sinpalean Exp $
29: */
30: public class SQLCacheKey {
31: private final String sql;
32: private final int serverType;
33: private final int majorVersion;
34: private final int minorVersion;
35: private final int hashCode;
36:
37: public SQLCacheKey(String sql, ConnectionJDBC2 connection) {
38: this .sql = sql;
39: this .serverType = connection.getServerType();
40: this .majorVersion = connection.getDatabaseMajorVersion();
41: this .minorVersion = connection.getDatabaseMinorVersion();
42:
43: this .hashCode = sql.hashCode()
44: ^ (serverType << 24 | majorVersion << 16 | minorVersion);
45: }
46:
47: public int hashCode() {
48: return hashCode;
49: }
50:
51: public boolean equals(Object object) {
52: try {
53: SQLCacheKey key = (SQLCacheKey) object;
54:
55: return this .hashCode == key.hashCode
56: && this .majorVersion == key.majorVersion
57: && this .minorVersion == key.minorVersion
58: && this .serverType == key.serverType
59: && this .sql.equals(key.sql);
60: } catch (ClassCastException e) {
61: return false;
62: }
63: }
64: }
|