KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > impl > store > raw > data > ChainAllocPageOperation


1 /*
2
3    Derby - Class org.apache.derby.impl.store.raw.data.ChainAllocPageOperation
4
5    Licensed to the Apache Software Foundation (ASF) under one or more
6    contributor license agreements. See the NOTICE file distributed with
7    this work for additional information regarding copyright ownership.
8    The ASF licenses this file to you under the Apache License, Version 2.0
9    (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.impl.store.raw.data;
23
24 import org.apache.derby.impl.store.raw.data.PhysicalPageOperation;
25 import org.apache.derby.impl.store.raw.data.BasePage;
26
27 import org.apache.derby.iapi.services.io.FormatIdUtil;
28 import org.apache.derby.iapi.services.io.StoredFormatIds;
29 import org.apache.derby.iapi.services.sanity.SanityManager;
30
31 import org.apache.derby.iapi.error.StandardException;
32 import org.apache.derby.iapi.store.raw.ContainerHandle;
33 import org.apache.derby.iapi.store.raw.data.RawContainerHandle;
34 import org.apache.derby.iapi.store.raw.Transaction;
35 import org.apache.derby.iapi.store.raw.log.LogInstant;
36
37 import org.apache.derby.iapi.services.io.CompressedNumber;
38
39 import java.io.OutputStream JavaDoc;
40 import java.io.ObjectOutput JavaDoc;
41 import java.io.IOException JavaDoc;
42 import org.apache.derby.iapi.services.io.LimitObjectInput;
43 import java.io.ObjectInput JavaDoc;
44
45
46 // Allocation page operation - to allocate, deallocate or free a page
47
public final class ChainAllocPageOperation extends PhysicalPageOperation
48 {
49
50     protected long newAllocPageNum; // the next alloc page's page number
51
protected long newAllocPageOffset; // the next alloc page's page offset
52

53     public ChainAllocPageOperation(AllocPage allocPage, long pageNumber, long pageOffset)
54          throws StandardException
55     {
56         super(allocPage);
57
58         newAllocPageNum = pageNumber;
59         newAllocPageOffset = pageOffset;
60     }
61     
62     /*
63      * Formatable methods
64      */

65
66     // no-arg constructor, required by Formatable
67
public ChainAllocPageOperation() { super(); }
68
69     public void writeExternal(ObjectOutput JavaDoc out) throws IOException JavaDoc
70     {
71         super.writeExternal(out);
72         CompressedNumber.writeLong(out, newAllocPageNum);
73         CompressedNumber.writeLong(out, newAllocPageOffset);
74     }
75
76     /**
77         @exception IOException error reading from log stream
78         @exception ClassNotFoundException cannot read object from input
79     */

80     public void readExternal(ObjectInput in)
81          throws IOException JavaDoc, ClassNotFoundException JavaDoc
82     {
83         super.readExternal(in);
84         newAllocPageNum = CompressedNumber.readLong(in);
85         newAllocPageOffset = CompressedNumber.readLong(in);
86     }
87
88     /**
89         Return my format identifier.
90     */

91     public int getTypeFormatId() {
92         return StoredFormatIds.LOGOP_CHAIN_ALLOC_PAGE;
93     }
94
95     /*
96      * Loggable methods
97      */

98     /**
99         Link the next alloc page into the page chain
100         @exception StandardException container Handle is not active
101     */

102     public final void doMe(Transaction tran, LogInstant instant, LimitObjectInput in)
103          throws StandardException
104     {
105         if (SanityManager.DEBUG) {
106             SanityManager.ASSERT(this.page instanceof AllocPage);
107         }
108
109         ((AllocPage)page).chainNextAllocPage(instant, newAllocPageNum, newAllocPageOffset);
110     }
111
112     /*
113      * Undoable methods
114      */

115
116     /**
117         Unlink the next alloc page from the page chain
118
119         @exception StandardException Thrown by methods I call
120         @see PhysicalPageOperation#undoMe
121     */

122     public void undoMe(Transaction xact, BasePage undoPage, LogInstant CLRInstant,
123                        LimitObjectInput in)
124          throws StandardException
125     {
126         if (SanityManager.DEBUG) {
127             SanityManager.ASSERT(undoPage != null, "undo Page null");
128             SanityManager.ASSERT(undoPage instanceof AllocPage,
129                                  "undo Page is not an allocPage");
130         }
131
132         ((AllocPage)undoPage).chainNextAllocPage(CLRInstant,
133                                              ContainerHandle.INVALID_PAGE_NUMBER,
134                                              0 /* undefine */);
135     }
136
137     /*
138      * method to support BeforeImageLogging
139      */

140     public void restoreMe(Transaction xact, BasePage undoPage, LogInstant CLRinstant, LimitObjectInput in)
141     {
142         // nobody should be calling this since there is no
143
// BI_AllocPageOperation
144
if (SanityManager.DEBUG)
145             SanityManager.THROWASSERT("cannot call restoreMe on BI_ChainAllocPageOperation");
146     }
147
148
149     /** debug */
150     public String JavaDoc toString()
151     {
152         if (SanityManager.DEBUG)
153         {
154             String JavaDoc str = super.toString();
155             str += " Chain new alloc page number " + newAllocPageNum + " at " +
156                 newAllocPageOffset + " to " + getPageId();
157             return str;
158         }
159         else
160             return null;
161     }
162
163 }
164
165
Popular Tags