KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > impl > drda > Pkgnamcsn


1 /*
2  * Derby - class org.apache.derby.impl.drda.Pkgnamcsn
3  *
4  * Licensed to the Apache Software Foundation (ASF) under one or more
5  * contributor license agreements. See the NOTICE file distributed with
6  * this work for additional information regarding copyright ownership.
7  * The ASF licenses this file to You under the Apache License, Version 2.0
8  * (the "License"); you may not use this file except in compliance with
9  * the License. You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
16  * implied. See the License for the specific language governing
17  * permissions and limitations under the License.
18  *
19  */

20
21 package org.apache.derby.impl.drda;
22
23 /**
24  * Class representing a PKGNAMCSN object (RDB Package Name,
25  * Consistency Token, and Section Number).
26  */

27 final class Pkgnamcsn {
28     /** Database name. */
29     private final String JavaDoc rdbnam;
30     /** RDB Package Collection Identifier. */
31     private final String JavaDoc rdbcolid;
32     /** RDB Package Identifier. */
33     private final String JavaDoc pkgid;
34     /** RDB Package Section Number. */
35     private final int pkgsn;
36     /** RDB Package Consistency Token. */
37     private final ConsistencyToken pkgcnstkn;
38
39     /** Object which can be used for hashing when the consistency
40      * token can be ignored. */

41     private Object JavaDoc statementKey = null;
42
43     /**
44      * Create a new <code>Pkgnamcsn</code> instance.
45      *
46      * @param rdbnam database name
47      * @param rdbcolid RDB Package Collection Identifier
48      * @param pkgid RDB Package Identifier
49      * @param pkgsn RDB Package Section Number
50      * @param pkgcnstkn RDB Package Consistency Token
51      */

52     Pkgnamcsn(String JavaDoc rdbnam, String JavaDoc rdbcolid, String JavaDoc pkgid,
53                      int pkgsn, ConsistencyToken pkgcnstkn) {
54         this.rdbnam = rdbnam;
55         this.rdbcolid = rdbcolid;
56         this.pkgid = pkgid;
57         this.pkgsn = pkgsn;
58         this.pkgcnstkn = pkgcnstkn;
59     }
60
61     /**
62      * Get RDBNAM.
63      *
64      * @return database name
65      */

66     public String JavaDoc getRdbnam() {
67         return rdbnam;
68     }
69
70     /**
71      * Get RDBCOLID.
72      *
73      * @return RDB Package Collection Identifier
74      */

75     public String JavaDoc getRdbcolid() {
76         return rdbcolid;
77     }
78
79     /**
80      * Get PKGID.
81      *
82      * @return RDB Package Identifier
83      */

84     public String JavaDoc getPkgid() {
85         return pkgid;
86     }
87
88     /**
89      * Get PKGSN.
90      *
91      * @return RDB Package Section Number
92      */

93     public int getPkgsn() {
94         return pkgsn;
95     }
96
97     /**
98      * Get PKGCNSTKN.
99      *
100      * @return RDB Package Consistency Token
101      */

102     public ConsistencyToken getPkgcnstkn() {
103         return pkgcnstkn;
104     }
105
106     /**
107      * Return string representation.
108      *
109      * @return a <code>String</code> value
110      */

111     public String JavaDoc toString() {
112         return super.toString() + "(\"" + rdbnam + "\", \"" +
113             rdbcolid + "\", \"" + pkgid + "\", " + pkgsn +
114             ", " + pkgcnstkn + ")";
115     }
116
117     /**
118      * Return an object which can be used as a key in a hash table
119      * when the value of the consistency token can be ignored. The
120      * object has <code>equals()</code> and <code>hashCode()</code>
121      * methods which consider other objects returned from
122      * <code>getStatementKey()</code> equal if RDBNAM, RDBCOLID, PKGID
123      * and PKGSN are equal.
124      *
125      * @return an <code>Object</code> value
126      * @see Database#getDRDAStatement(Pkgnamcsn)
127      * @see Database#storeStatement(DRDAStatement)
128      * @see Database#removeStatement(DRDAStatement)
129      */

130     public Object JavaDoc getStatementKey() {
131         if (statementKey == null) {
132             statementKey = new StatementKey();
133         }
134         return statementKey;
135     }
136
137     /**
138      * Class for objects used as keys in the hash table
139      * <code>stmtTable</code> found in the <code>Database</code>
140      * class. The <code>equals()</code> and <code>hashCode()</code>
141      * methods consider other <code>StatementKey</code> objects equal
142      * to this object if they are associated with a
143      * <code>Pkgnamcsn</code> object with the same values for RDBNAM,
144      * RDBCOLID, PKGID and PKGSN.
145      *
146      * @see Database
147      */

148     private final class StatementKey {
149         /** Cached hash code. */
150         private int hash = 0;
151         /**
152          * Check whether RDBNAM, RDBCOLID, PKGID and PKGSN of another
153          * <code>StatementKey</code> object matches this object.
154          *
155          * @param obj another object
156          * @return true if the objects are equal
157          */

158         public boolean equals(Object JavaDoc obj) {
159             if (StatementKey.this == obj) {
160                 return true;
161             } else if (obj instanceof StatementKey) {
162                 return ((StatementKey) obj).isKeyFor(Pkgnamcsn.this);
163             } else {
164                 return false;
165             }
166         }
167         /**
168          * Calculate hash code.
169          *
170          * @return hash code
171          */

172         public int hashCode() {
173             if (hash == 0) {
174                 hash =
175                     rdbnam.hashCode() ^
176                     rdbcolid.hashCode() ^
177                     pkgid.hashCode() ^
178                     pkgsn;
179             }
180             return hash;
181         }
182         /**
183          * Check whether this object can be used as a key for a
184          * <code>Pkgnamcsn</code> object.
185          *
186          * @param p a <code>Pkgnamcsn</code> value
187          * @return true if this object can be key for the
188          * <code>Pkgnamcsn</code> object
189          */

190         private boolean isKeyFor(Pkgnamcsn p) {
191             return
192                 rdbnam.equals(p.rdbnam) &&
193                 rdbcolid.equals(p.rdbcolid) &&
194                 pkgid.equals(p.pkgid) &&
195                 pkgsn == p.pkgsn;
196         }
197     }
198 }
199
Popular Tags