KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > kaha > impl > index > hash > HashPageInfo


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

14
15 package org.apache.activemq.kaha.impl.index.hash;
16
17 import java.io.IOException JavaDoc;
18
19 /**
20  * A Page within a HashPageInfo
21  *
22  * @version $Revision: 1.1.1.1 $
23  */

24 class HashPageInfo{
25
26     private HashIndex hashIndex;
27     private long id;
28     private int size;
29     private HashPage page;
30     private boolean dirty=false;
31
32     HashPageInfo(HashIndex index){
33         this.hashIndex=index;
34     }
35
36     /**
37      * @return the id
38      */

39     long getId(){
40         return this.id;
41     }
42
43     /**
44      * @param id the id to set
45      */

46     void setId(long id){
47         this.id=id;
48     }
49
50     /**
51      * @return the size
52      */

53     int size(){
54         return this.size;
55     }
56
57     /**
58      * @param size the size to set
59      */

60     void setSize(int size){
61         this.size=size;
62     }
63
64     void addHashEntry(int index,HashEntry entry) throws IOException JavaDoc{
65         page.addHashEntry(index,entry);
66         size++;
67         dirty=true;
68     }
69
70     HashEntry getHashEntry(int index) throws IOException JavaDoc{
71         return page.getHashEntry(index);
72     }
73
74     HashEntry removeHashEntry(int index) throws IOException JavaDoc{
75         HashEntry result=page.removeHashEntry(index);
76         if(result!=null){
77             size--;
78             dirty=true;
79         }
80         return result;
81     }
82
83     void dump(){
84         page.dump();
85     }
86
87     void begin() throws IOException JavaDoc{
88         if(page==null){
89             page=hashIndex.getFullPage(id);
90         }
91     }
92
93     void end() throws IOException JavaDoc{
94         if(page!=null){
95             if(dirty){
96                 hashIndex.writeFullPage(page);
97             }
98         }
99         page=null;
100         dirty=false;
101     }
102
103     HashPage getPage(){
104         return page;
105     }
106
107     void setPage(HashPage page){
108         this.page=page;
109     }
110 }
111
Popular Tags