KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2
3    Derby - Class org.apache.derby.impl.store.raw.data.AllocPageOperation
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.data.RawContainerHandle;
33 import org.apache.derby.iapi.store.raw.Transaction;
34 import org.apache.derby.iapi.store.raw.log.LogInstant;
35
36 import org.apache.derby.iapi.services.io.CompressedNumber;
37
38 import java.io.OutputStream JavaDoc;
39 import java.io.ObjectOutput JavaDoc;
40 import java.io.ObjectInput JavaDoc;
41 import java.io.IOException JavaDoc;
42 import org.apache.derby.iapi.services.io.LimitObjectInput;
43
44
45 // Allocation page operation - to allocate, deallocate or free a page
46
public final class AllocPageOperation extends PhysicalPageOperation
47 {
48
49     protected long newPageNumber; // new page's number
50
protected int doStatus; // what the doMe operation should set the status to
51
protected int undoStatus; // what the undoMe operation should set the status to
52

53     public AllocPageOperation(AllocPage allocPage, long pageNumber, int doStatus, int undoStatus)
54          throws StandardException
55     {
56         super(allocPage);
57
58         newPageNumber = pageNumber;
59         this.doStatus = doStatus;
60         this.undoStatus = undoStatus;
61     }
62     
63     /*
64      * Formatable methods
65      */

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

82     public void readExternal(ObjectInput JavaDoc in)
83          throws IOException JavaDoc, ClassNotFoundException JavaDoc
84     {
85         super.readExternal(in);
86         newPageNumber = CompressedNumber.readLong(in);
87         doStatus = CompressedNumber.readInt(in);
88         undoStatus = CompressedNumber.readInt(in);
89     }
90
91     /**
92         Return my format identifier.
93     */

94     public int getTypeFormatId() {
95         return StoredFormatIds.LOGOP_ALLOC_PAGE;
96     }
97
98     /*
99      * Loggable methods
100      */

101     /**
102         Allocate/deallocate/free this page number
103         @exception StandardException container Handle is not active
104     */

105     public final void doMe(Transaction tran, LogInstant instant, LimitObjectInput in)
106          throws StandardException
107     {
108         if (SanityManager.DEBUG) {
109             SanityManager.ASSERT(this.page instanceof AllocPage);
110         }
111
112         ((AllocPage)page).setPageStatus(instant, newPageNumber, doStatus);
113     }
114
115     /*
116      * Undoable methods
117      */

118
119     /**
120         Allocate/deallocate/free this page number.
121
122         @exception StandardException Thrown by methods I call
123
124         @see PhysicalPageOperation#undoMe
125     */

126     public void undoMe(Transaction xact, BasePage undoPage, LogInstant CLRInstant,
127                        LimitObjectInput in)
128          throws StandardException
129     {
130         if (SanityManager.DEBUG) {
131             SanityManager.ASSERT(undoPage != null, "undo Page null");
132             SanityManager.ASSERT(undoPage instanceof AllocPage,
133                                  "undo Page is not an allocPage");
134         }
135
136         // RESOLVE: maybe a free page operation should not be undoable.
137
// Who is going to free that page again? If we don't undo it, it may
138
// be problem if we ever free a page in the same transaction that we
139
// deallocate it, in that case, if we don't rollback the free, then we
140
// can't rollback the deallcoate.
141
((AllocPage)undoPage).setPageStatus(CLRInstant, newPageNumber, undoStatus);
142     }
143
144     /*
145      * method to support BeforeImageLogging
146      */

147     public void restoreMe(Transaction xact, BasePage undoPage, LogInstant CLRinstant, LimitObjectInput in)
148     {
149         // nobody should be calling this since there is no
150
// BI_AllocPageOperation
151
if (SanityManager.DEBUG)
152             SanityManager.THROWASSERT("cannot call restoreMe on BI_AllocPageOperation");
153     }
154
155
156     /** debug */
157     public String JavaDoc toString()
158     {
159         if (SanityManager.DEBUG)
160         {
161             String JavaDoc str = super.toString();
162             str += " Change page allocation status of " + newPageNumber +
163                 " to " + doStatus + "(undo " + undoStatus + ")";
164             return str;
165         }
166         else
167             return null;
168     }
169
170 }
171
172
Popular Tags