org.apache.derby.impl.io
Class DirFile4

java.lang.Object
  extended by java.io.File
      extended by org.apache.derby.impl.io.DirFile
          extended by org.apache.derby.impl.io.DirFile4
All Implemented Interfaces:
java.io.Serializable, java.lang.Comparable<java.io.File>, StorageFile

 class DirFile4
extends DirFile

This class implements the StorageFile interface using features of Java 1.4 not available in earlier versions of Java.


Field Summary
private  java.nio.channels.FileLock dbLock
           
private  java.nio.channels.FileChannel lockFileChannel
           
private  java.io.RandomAccessFile lockFileOpen
           
private  boolean rwsOK
           
 
Fields inherited from class java.io.File
pathSeparator, pathSeparatorChar, separator, separatorChar
 
Fields inherited from interface org.apache.derby.io.StorageFile
EXCLUSIVE_FILE_LOCK, EXCLUSIVE_FILE_LOCK_NOT_AVAILABLE, NO_FILE_LOCK_SUPPORT
 
Constructor Summary
DirFile4(DirFile directoryName, java.lang.String fileName, boolean rwsOK)
          Construct a DirFile from a directory name and a file name.
DirFile4(java.lang.String path, boolean rwsOK)
          Construct a DirFile from a path name.
DirFile4(java.lang.String directoryName, java.lang.String fileName, boolean rwsOK)
          Construct a DirFile from a directory name and a file name.
 
Method Summary
 int getExclusiveFileLock()
          Get an exclusive lock.
 java.io.OutputStream getOutputStream(boolean append)
          Creates an output stream from a file name.
 StorageFile getParentDir()
          Get the name of the parent directory if this name includes a parent.
 StorageRandomAccessFile getRandomAccessFile(java.lang.String mode)
          Get a random access (read/write) file.
 void releaseExclusiveFileLock()
          Release the resource associated with an earlier acquired exclusive lock
 
Methods inherited from class org.apache.derby.impl.io.DirFile
deleteAll, getInputStream, getOutputStream, getTempDir, getURL, renameTo
 
Methods inherited from class java.io.File
canExecute, canRead, canWrite, compareTo, createNewFile, createTempFile, createTempFile, delete, deleteOnExit, equals, exists, getAbsoluteFile, getAbsolutePath, getCanonicalFile, getCanonicalPath, getFreeSpace, getName, getParent, getParentFile, getPath, getTotalSpace, getUsableSpace, hashCode, isAbsolute, isDirectory, isFile, isHidden, lastModified, length, list, list, listFiles, listFiles, listFiles, listRoots, mkdir, mkdirs, renameTo, setExecutable, setExecutable, setLastModified, setReadable, setReadable, setReadOnly, setWritable, setWritable, toString, toURI, toURL
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.apache.derby.io.StorageFile
canWrite, createNewFile, delete, exists, getCanonicalPath, getName, getPath, isDirectory, length, list, mkdir, mkdirs, setReadOnly
 

Field Detail

lockFileOpen

private java.io.RandomAccessFile lockFileOpen

lockFileChannel

private java.nio.channels.FileChannel lockFileChannel

dbLock

private java.nio.channels.FileLock dbLock

rwsOK

private final boolean rwsOK
Constructor Detail

DirFile4

DirFile4(java.lang.String path,
         boolean rwsOK)
Construct a DirFile from a path name.

Parameters:
path - The path name.

DirFile4

DirFile4(java.lang.String directoryName,
         java.lang.String fileName,
         boolean rwsOK)
Construct a DirFile from a directory name and a file name.

Parameters:
directoryName - The directory part of the path name.
fileName - The name of the file within the directory.

DirFile4

DirFile4(DirFile directoryName,
         java.lang.String fileName,
         boolean rwsOK)
Construct a DirFile from a directory name and a file name.

Parameters:
directoryName - The directory part of the path name.
fileName - The name of the file within the directory.
Method Detail

getParentDir

public StorageFile getParentDir()
Get the name of the parent directory if this name includes a parent.

Specified by:
getParentDir in interface StorageFile
Overrides:
getParentDir in class DirFile
Returns:
An StorageFile denoting the parent directory of this StorageFile, if it has a parent, null if it does not have a parent.

getOutputStream

public java.io.OutputStream getOutputStream(boolean append)
                                     throws java.io.FileNotFoundException
Creates an output stream from a file name.

Specified by:
getOutputStream in interface StorageFile
Overrides:
getOutputStream in class DirFile
Parameters:
append - If true then data will be appended to the end of the file, if it already exists. If false and a normal file already exists with this name the file will first be truncated to zero length.
Returns:
an output stream suitable for writing to the file.
Throws:
java.io.FileNotFoundException - if the file exists but is a directory rather than a regular file, does not exist but cannot be created, or cannot be opened for any other reason.

getExclusiveFileLock

public int getExclusiveFileLock()
Description copied from class: DirFile
Get an exclusive lock. This is used to ensure that two or more JVMs do not open the same database at the same time.

Specified by:
getExclusiveFileLock in interface StorageFile
Overrides:
getExclusiveFileLock in class DirFile
Returns:
EXCLUSIVE_FILE_LOCK_NOT_AVAILABLE if the lock cannot be acquired because it is already held.
EXCLUSIVE_FILE_LOCK if the lock was successfully acquired.
NO_FILE_LOCK_SUPPORT if the system does not support exclusive locks.

releaseExclusiveFileLock

public void releaseExclusiveFileLock()
Description copied from class: DirFile
Release the resource associated with an earlier acquired exclusive lock

Specified by:
releaseExclusiveFileLock in interface StorageFile
Overrides:
releaseExclusiveFileLock in class DirFile
See Also:
DirFile.getExclusiveFileLock()

getRandomAccessFile

public StorageRandomAccessFile getRandomAccessFile(java.lang.String mode)
                                            throws java.io.FileNotFoundException
Get a random access (read/write) file.

Specified by:
getRandomAccessFile in interface StorageFile
Overrides:
getRandomAccessFile in class DirFile
Parameters:
mode - "r", "rw", "rws", or "rwd". The "rws" and "rwd" modes specify that the data is to be written to persistent store, consistent with the java.io.RandomAccessFile class ("synchronized" with the persistent storage, in the file system meaning of the word "synchronized"). However the implementation is not required to implement the "rws" or "rwd" modes. The implementation may treat "rws" and "rwd" as "rw". It is up to the user of this interface to call the StorageRandomAccessFile.sync method. If the "rws" or "rwd" modes are supported and the RandomAccessFile was opened in "rws" or "rwd" mode then the implementation of StorageRandomAccessFile.sync need not do anything.
Returns:
an object that can be used for random access to the file.
Throws:
java.lang.IllegalArgumentException - if the mode argument is not equal to one of "r", "rw", "rws", or "rwd".
java.io.FileNotFoundException - if the file exists but is a directory rather than a regular file, or cannot be opened or created for any other reason .
See Also:
java.io.RandomAccessFile

Built on Thu 2010-12-23 20:49:13+0000, from revision ???

Apache Derby V10.6 Internals - Copyright © 2004,2007 The Apache Software Foundation. All Rights Reserved.