KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > db > store > AutoCommitWriteBlock


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  *
23  * Free Software Foundation, Inc.
24  * 59 Temple Place, Suite 330
25  * Boston, MA 02111-1307 USA
26  *
27  * @author Scott Ferguson
28  */

29
30 package com.caucho.db.store;
31
32 import com.caucho.log.Log;
33 import com.caucho.util.L10N;
34
35 import java.io.IOException JavaDoc;
36 import java.util.logging.Level JavaDoc;
37 import java.util.logging.Logger JavaDoc;
38
39 /**
40  * Represents a write (dirty) block.
41  *
42  * The AutoCommitWriteBlock
43  */

44 public class AutoCommitWriteBlock extends WriteBlock {
45   private static final Logger JavaDoc log = Log.open(AutoCommitWriteBlock.class);
46   private static final L10N L = new L10N(AutoCommitWriteBlock.class);
47
48   public AutoCommitWriteBlock(Block block)
49     throws IOException JavaDoc
50   {
51     super(block);
52
53     Thread.dumpStack();
54     
55     // The block should already be allocated
56
// block.allocate();
57
block.read();
58   }
59
60   /**
61    * The buffer for the auto-commit is the same as the read buffer.
62    */

63   public byte []getBuffer()
64   {
65     return _block.getBuffer();
66   }
67
68   public void setDirty(int minDirty, int maxDirty)
69   {
70     _block.setDirty(minDirty, maxDirty);
71   }
72
73   public void setFlushDirtyOnCommit(boolean flushOnCommit)
74   {
75     _block.setFlushDirtyOnCommit(flushOnCommit);
76   }
77
78   public void commit()
79     throws IOException JavaDoc
80   {
81     _block.commit();
82   }
83
84   /*
85   public void free()
86   {
87     super.free();
88
89     if (isFree())
90       destroy();
91   }
92   */

93
94   /**
95    * Closes the write block.
96    */

97   protected void freeImpl()
98   {
99     super.freeImpl();
100     
101     Block block = _block;
102     _block = block;
103
104     if (block != null) {
105       try {
106     block.commit();
107       } catch (Throwable JavaDoc e) {
108     log.log(Level.FINE, e.toString(), e);
109       }
110       
111       block.free();
112
113       throw new IllegalStateException JavaDoc();
114       //close();
115
}
116   }
117
118   public String JavaDoc toString()
119   {
120     return "AutoCommitWriteBlock[" + getStore() + "," + getBlockId() / Store.BLOCK_SIZE + "]";
121   }
122 }
123
Popular Tags