View Javadoc

1   package org.apache.labs.bananadb.store.data;
2   
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 implied.
16   * See the License for the specific language governing permissions and
17   * limitations under the License.
18   */
19  
20  
21  import org.apache.labs.bananadb.store.lock.LockFactory;
22  
23  import java.io.RandomAccessFile;
24  import java.io.IOException;
25  import java.io.File;
26  
27  /**
28   * @author kalle
29   * @since 2009-mar-16 14:16:39
30   */
31  public class Metadata extends FileHandler<Metadata.Header, FileHandler.Posting> {
32  
33    public Metadata(File directory, String access, LockFactory lockFactory) throws IOException {
34      super(directory, 0, "md", access, lockFactory);
35    }
36  
37    public static final int HEADER_BYTE_SIZE = 1024;
38    public int getHeaderByteSize() {
39      return HEADER_BYTE_SIZE;
40    }
41  
42    public static class Header extends FileHandler.Header {
43      /**
44       * File format version.
45       */
46      private int fileFormatVersion;
47  
48      /**
49       * Current hashtable file id. -- will change after rehash.
50       */
51      private int currentHashtableId;
52  
53      /** Current hash codes partition used for appending new postings */
54      private int currentHashCodesPartition;
55  
56      /** Current keys partition used for appending new postings */
57      private int currentKeysPartition;
58  
59      /** Current values partition used for appending new postings */
60      private int currentValuesPartition;
61  
62      /**
63       * Total number of value postings.
64       */
65      private long valuePostingsCount;
66  
67      /**
68       * Commit version, will increase by one after each modification to the database.
69       */
70      private long storeRevision;
71  
72      public int getCurrentHashCodesPartition() {
73        return currentHashCodesPartition;
74      }
75  
76      public void setCurrentHashCodesPartition(int currentHashCodesPartition) {
77        this.currentHashCodesPartition = currentHashCodesPartition;
78      }
79  
80      public int getCurrentKeysPartition() {
81        return currentKeysPartition;
82      }
83  
84      public void setCurrentKeysPartition(int currentKeysPartition) {
85        this.currentKeysPartition = currentKeysPartition;
86      }
87  
88      public int getCurrentValuesPartition() {
89        return currentValuesPartition;
90      }
91  
92      public void setCurrentValuesPartition(int currentValuesPartition) {
93        this.currentValuesPartition = currentValuesPartition;
94      }
95  
96      public int getFileFormatVersion() {
97        return fileFormatVersion;
98      }
99  
100     public void setFileFormatVersion(int fileFormatVersion) {
101       this.fileFormatVersion = fileFormatVersion;
102     }
103 
104     public int getCurrentHashtableId() {
105       return currentHashtableId;
106     }
107 
108     public void setCurrentHashtableId(int currentHashtableId) {
109       this.currentHashtableId = currentHashtableId;
110     }
111 
112     public long getValuePostingsCount() {
113       return valuePostingsCount;
114     }
115 
116     public void setValuePostingsCount(long valuePostingsCount) {
117       this.valuePostingsCount = valuePostingsCount;
118     }
119 
120     public long getStoreRevision() {
121       return storeRevision;
122     }
123 
124     public void setStoreRevision(long storeRevision) {
125       this.storeRevision = storeRevision;
126     }
127 
128     public long increaseRevision(long value) {
129       return storeRevision += value;
130     }
131 
132     public long increaseValuePostingsCount(long value) {
133       return valuePostingsCount += value;
134     }
135 
136     public long decreaseValuePostingsCount(long value) {
137       return valuePostingsCount -= value;
138     }
139 
140   }
141 
142   public void readHeader(Header header, RandomAccessFile RAF) throws IOException {
143     header.fileFormatVersion = RAF.readInt();
144     header.storeRevision = RAF.readLong();
145     header.currentHashtableId = RAF.readInt();
146     header.currentHashCodesPartition = RAF.readInt();
147     header.currentKeysPartition = RAF.readInt();
148     header.currentValuesPartition = RAF.readInt();
149     header.valuePostingsCount = RAF.readLong();
150     System.currentTimeMillis();
151   }
152 
153   public void writeHeader(Header header, RandomAccessFile RAF) throws IOException {
154     RAF.writeInt(header.fileFormatVersion);
155     RAF.writeLong(header.storeRevision);
156     RAF.writeInt(header.currentHashtableId);
157     RAF.writeInt(header.currentHashCodesPartition);
158     RAF.writeInt(header.currentKeysPartition);
159     RAF.writeInt(header.currentValuesPartition);
160     RAF.writeLong(header.valuePostingsCount);
161   }
162 
163   public void writePosting(Posting posting, RandomAccessFile RAF) throws IOException {
164     throw new UnsupportedOperationException();
165   }
166 
167   public void readPosting(Posting posting, RandomAccessFile RAF) throws IOException {
168     throw new UnsupportedOperationException();
169   }
170 
171   public void markPostingAsDeleted(int startOffset, RandomAccessFile RAF, long revision) throws IOException {
172     throw new UnsupportedOperationException();
173   }
174 }