KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ojb > broker > accesslayer > sql > SqlCacheKey


1 package org.apache.ojb.broker.accesslayer.sql;
2
3 /* Copyright 2002-2004 The Apache Software Foundation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 import org.apache.ojb.broker.query.Query;
19 import org.apache.ojb.broker.metadata.ClassDescriptor;
20
21 /**
22  * Helper key class to store generated sql statements
23  *
24  * @author Matthew Baird
25  * @version $Id: SqlCacheKey.java,v 1.7 2004/04/04 23:53:32 brianm Exp $
26  */

27 class SqlCacheKey
28 {
29     public static final int TYPE_SELECT = 1;
30     public static final int TYPE_INSERT = 2;
31     public static final int TYPE_UPDATE = 3;
32     public static final int TYPE_DELETE = 4;
33
34     private final Query m_query;
35     private final ClassDescriptor m_cld;
36     private final int type;
37
38     public SqlCacheKey(final Query query, final ClassDescriptor cld, final int type)
39     {
40         m_query = query;
41         m_cld = cld;
42         this.type = type;
43     }
44
45     public int hashCode()
46     {
47         int retval = 0;
48         if (getCld() != null)
49         {
50             retval += getCld().hashCode();
51         }
52         if (getQuery() != null)
53         {
54             retval += getQuery().hashCode();
55         }
56         return retval+type;
57     }
58
59     public boolean equals(Object JavaDoc other)
60     {
61         if (other == null)
62         {
63             return false;
64         }
65         if (other instanceof SqlCacheKey)
66         {
67             SqlCacheKey temp = (SqlCacheKey) other;
68             if (temp.getCld().equals(getCld()) && (temp.getQuery().equals(getQuery())) && (temp.getType() == this.getType()))
69             {
70                 return true;
71             }
72             else
73             {
74                 return false;
75             }
76         }
77         else
78         {
79             return false;
80         }
81     }
82
83     public Query getQuery()
84     {
85         return m_query;
86     }
87
88     public ClassDescriptor getCld()
89     {
90         return m_cld;
91     }
92
93     public int getType()
94     {
95         return type;
96     }
97     /*
98     arminw:
99     When we declare cld and query final, we have to eliminate setters.
100     */

101
102 // public void setCld(ClassDescriptor cld)
103
// {
104
// m_cld = cld;
105
// }
106
//
107
// public void setQuery(Query query)
108
// {
109
// m_query = query;
110
// }
111

112 }
113
Popular Tags