001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: *
023: * Free Software Foundation, Inc.
024: * 59 Temple Place, Suite 330
025: * Boston, MA 02111-1307 USA
026: *
027: * @author Scott Ferguson
028: */
029:
030: package com.caucho.db.store;
031:
032: import com.caucho.log.Log;
033: import com.caucho.util.L10N;
034:
035: import java.io.IOException;
036: import java.util.logging.Level;
037: import java.util.logging.Logger;
038:
039: /**
040: * Represents a write (dirty) block.
041: *
042: * The AutoCommitWriteBlock
043: */
044: public class AutoCommitWriteBlock extends WriteBlock {
045: private static final Logger log = Log
046: .open(AutoCommitWriteBlock.class);
047: private static final L10N L = new L10N(AutoCommitWriteBlock.class);
048:
049: public AutoCommitWriteBlock(Block block) throws IOException {
050: super (block);
051:
052: Thread.dumpStack();
053:
054: // The block should already be allocated
055: // block.allocate();
056: block.read();
057: }
058:
059: /**
060: * The buffer for the auto-commit is the same as the read buffer.
061: */
062: public byte[] getBuffer() {
063: return _block.getBuffer();
064: }
065:
066: public void setDirty(int minDirty, int maxDirty) {
067: _block.setDirty(minDirty, maxDirty);
068: }
069:
070: public void setFlushDirtyOnCommit(boolean flushOnCommit) {
071: _block.setFlushDirtyOnCommit(flushOnCommit);
072: }
073:
074: public void commit() throws IOException {
075: _block.commit();
076: }
077:
078: /*
079: public void free()
080: {
081: super.free();
082:
083: if (isFree())
084: destroy();
085: }
086: */
087:
088: /**
089: * Closes the write block.
090: */
091: protected void freeImpl() {
092: super .freeImpl();
093:
094: Block block = _block;
095: _block = block;
096:
097: if (block != null) {
098: try {
099: block.commit();
100: } catch (Throwable e) {
101: log.log(Level.FINE, e.toString(), e);
102: }
103:
104: block.free();
105:
106: throw new IllegalStateException();
107: //close();
108: }
109: }
110:
111: public String toString() {
112: return "AutoCommitWriteBlock[" + getStore() + ","
113: + getBlockId() / Store.BLOCK_SIZE + "]";
114: }
115: }
|