01: /*
02:
03: Derby - Class org.apache.derby.iapi.store.raw.PageKey
04:
05: Licensed to the Apache Software Foundation (ASF) under one or more
06: contributor license agreements. See the NOTICE file distributed with
07: this work for additional information regarding copyright ownership.
08: The ASF licenses this file to you under the Apache License, Version 2.0
09: (the "License"); you may not use this file except in compliance with
10: the License. You may obtain a copy of the License at
11:
12: http://www.apache.org/licenses/LICENSE-2.0
13:
14: Unless required by applicable law or agreed to in writing, software
15: distributed under the License is distributed on an "AS IS" BASIS,
16: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17: See the License for the specific language governing permissions and
18: limitations under the License.
19:
20: */
21:
22: package org.apache.derby.iapi.store.raw;
23:
24: import org.apache.derby.iapi.store.raw.ContainerKey;
25:
26: import org.apache.derby.iapi.services.sanity.SanityManager;
27: import org.apache.derby.iapi.services.io.CompressedNumber;
28:
29: import java.io.ObjectOutput;
30: import java.io.ObjectInput;
31: import java.io.IOException;
32:
33: /**
34: A key that identifies a BasePage. Used as the key for the caching mechanism.
35:
36: <BR> MT - Immutable :
37: */
38:
39: public class PageKey {
40: private final ContainerKey container;
41: private final long pageNumber; // page number
42:
43: public PageKey(ContainerKey key, long pageNumber) {
44: container = key;
45: this .pageNumber = pageNumber;
46: }
47:
48: public long getPageNumber() {
49: return pageNumber;
50: }
51:
52: public ContainerKey getContainerId() {
53: return container;
54: }
55:
56: /*
57: ** Methods to read and write
58: */
59:
60: public void writeExternal(ObjectOutput out) throws IOException {
61: container.writeExternal(out);
62: CompressedNumber.writeLong(out, pageNumber);
63: }
64:
65: public static PageKey read(ObjectInput in) throws IOException {
66: ContainerKey c = ContainerKey.read(in);
67: long pn = CompressedNumber.readLong(in);
68:
69: return new PageKey(c, pn);
70: }
71:
72: /*
73: ** Methods of object
74: */
75:
76: public boolean equals(Object other) {
77:
78: if (other instanceof PageKey) {
79: PageKey otherKey = (PageKey) other;
80:
81: return (pageNumber == otherKey.pageNumber)
82: && container.equals(otherKey.container);
83: }
84:
85: return false;
86: }
87:
88: public int hashCode() {
89:
90: return (int) (pageNumber ^ container.hashCode());
91: }
92:
93: public String toString() {
94: return "Page(" + pageNumber + "," + container.toString() + ")";
95: }
96:
97: }
|