01: /*
02:
03: Derby - Class org.apache.derby.impl.io.DirRandomAccessFile4
04:
05: Licensed to the Apache Software Foundation (ASF) under one or more
06: contributor license agreements. See the NOTICE file distributed with
07: this work for additional information regarding copyright ownership.
08: The ASF licenses this file to you under the Apache License, Version 2.0
09: (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.io;
23:
24: import java.io.File;
25: import java.io.FileNotFoundException;
26: import java.io.IOException;
27: import java.io.SyncFailedException;
28: import java.nio.channels.ClosedChannelException;
29:
30: /**
31: * This class provides a disk based implementation of the StIRandomAccess File interface. It is used by the
32: * database engine to access persistent data and transaction logs under the directory (default) subsubprotocol.
33: *
34: * This class extends DirRandomAccessFile to use the java.nio.channels.FileChannel.force() method to
35: * implement sync(). Java.nio.channels.FileChannel was introduced in Java 1.4; it was not available in Java 1.3.
36: */
37: class DirRandomAccessFile4 extends DirRandomAccessFile {
38:
39: /**
40: * Construct a StorageRandomAccessFileImpl.
41: *
42: * @param name The file name.
43: * @param mode The file open mode: "r", "rw", "rws", or "rwd". The "rws" and "rwd" modes specify that the file is to
44: * be synchronized, consistent with the java.io.RandomAccessFile class. However the
45: * StorageRandomAccessFile.sync() method will be called even if the file was opened
46: * in "rws" or "rwd" mode. If the "rws" or "rwd" modes are supported then the implementation
47: * of StorageRandomAccessFile.sync need not do anything.
48: *
49: * @exception IllegalArgumentException if the mode argument is not equal to one of "r", "rw".
50: * @exception FileNotFoundException if the file exists but is a directory rather than a regular
51: * file, or cannot be opened or created for any other reason .
52: */
53: DirRandomAccessFile4(File name, String mode)
54: throws FileNotFoundException {
55: super (name, mode);
56: }
57:
58: /**
59: * Force any changes out to the persistent store.
60: *
61: * @param metaData If true then this method is required to force changes to both the file's
62: * content and metadata to be written to storage; otherwise, it need only force content changes
63: * to be written.
64: *
65: * @exception IOException If an IO error occurs.
66: */
67: public void sync(boolean metaData) throws IOException {
68: try {
69: getChannel().force(metaData);
70: } catch (ClosedChannelException cce) {
71: throw cce;
72: } catch (IOException ioe) {
73: SyncFailedException sne = new SyncFailedException(ioe
74: .getMessage());
75: sne.initCause(ioe);
76: throw sne;
77: }
78: } // end of sync
79: }
|