Top Description Fields Constructors Methods
org.apache.derby.impl.io

public Class VFMemoryStorageFactory

extends Object
implements StorageFactory, WritableStorageFactory
Class Inheritance
All Implemented Interfaces
org.apache.derby.io.WritableStorageFactory, org.apache.derby.io.StorageFactory
Imports
java.io.File, .IOException, .OutputStream, java.util.HashMap, .Map, org.apache.derby.impl.io.vfmem.PathUtil, .DataStore, .VirtualFile, org.apache.derby.io.StorageFactory, .StorageFile, .WritableStorageFactory

A storage factory for virtual files, where the contents of the files are stored in main memory.

Note that data store deletion may happen inside one of two different methods; either in shutdown or in init. This is due to the current implementation and the fact that dropping a database is done through the file IO interface by deleting the service root. As the deletion then becomes a two step process, someone else may boot the database again before the reference to the store has been removed. To avoid this, the init-method will never initialize with a store scheduled for deletion. I have only seen this issue in heavily loaded multithreaded environments (2 CPUs/cores should be enough to reproduce).

Field Summary

Modifier and TypeField and Description
private String
canonicalName

The canonical (unique) name of the database (absolute path).

private static final Map<String, DataStore>
DATABASES

References to the databases created / existing.

private StorageFile
dataDirectory

The data directory of the database.

private DataStore
dbData

The data store used for the database.

private static final DataStore
DUMMY_STORE

Dummy store used to carry out frequent operations that don't require a "proper store", for instance getting the canonical name of the data store.

private StorageFile
tempDir

The temporary directory for the database (absolute path).

Constructor Summary

AccessConstructor and Description
public
VFMemoryStorageFactory()

Creates a new, uninitialized instance of the storage factory.

Method Summary

Modifier and TypeMethod and Description
public StorageFile

Returns:

A handle to the temporary file.
createTemporaryFile
(String
requested prefix for the file name
prefix
,
String
requested suffix for the file name, if null then .tmp will be used
suffix
)

Implements org.apache.derby.io.StorageFactory.createTemporaryFile.

Creates a handle to a temporary file.

private void
dbDropCleanupInDummy(String
absolute path of the dropped database
dbPath
)

Cleans up the internal dummy data store after a database has been dropped.

public String
getCanonicalName()

Implements org.apache.derby.io.StorageFactory.getCanonicalName.

Get the canonical name of the database.

public char

Returns:

PathUtil.SEP
getSeparator
()

Implements org.apache.derby.io.StorageFactory.getSeparator.

Returns the path separator used by this storage factory.

public int
public StorageFile

Returns:

A StorageFile-object representing the temp directory.
getTempDir
()

Implements org.apache.derby.io.StorageFactory.getTempDir.

Returns the temporary directory for this storage factory instance.

public void
init(String
the value of system.home for this storage factory
home
,
String
the name of the database, all relative pathnames are relative to this name
databaseName
,
String
ignored
tempDirNameIgnored
,
String
used to determine when the temporary directory can be created, but not to name the temporary directory itself
uniqueName
)

Implements org.apache.derby.io.StorageFactory.init.

Initializes the storage factory instance by setting up a temporary directory, the database directory and checking if the database being named already exists.

public boolean

Returns:

true
isFast
()

Implements org.apache.derby.io.StorageFactory.isFast.

The service is fast and supports random access.

public boolean

Returns:

false
isReadOnlyDatabase
()

Implements org.apache.derby.io.StorageFactory.isReadOnlyDatabase.

The service supports writes.

public StorageFile

Returns:

A path handle.
newStorageFile
(String
the path of the file or directory
path
)

Implements org.apache.derby.io.StorageFactory.newStorageFile.

Returns a handle to the specific storage file.

public StorageFile

Returns:

A path handle.
newStorageFile
(String
the name of the parent directory
directoryName
,
String
the name of the file
fileName
)

Implements org.apache.derby.io.StorageFactory.newStorageFile.

Returns a handle to the specified storage file.

public StorageFile

Returns:

A path handle.
newStorageFile
(StorageFile
the name of the parent directory
directoryName
,
String
the name of the file
fileName
)

Implements org.apache.derby.io.StorageFactory.newStorageFile.

Returns a handle to the specified storage file.

private String

Returns:

A path.
normalizePath
(String
parent directory, if null the dataDirectory will be used
dir
,
String
the file name (null not allowed)
file
)

Returns a normalized absolute path.

private String

Returns:

A path.
normalizePath
(String
path, if null the dataDirectory will be used
path
)

Returns a normalized absolute path.

public void
setCanonicalName(String
uniquely identifiable name for this database
name
)

Implements org.apache.derby.io.StorageFactory.setCanonicalName.

Set the canonicalName.

public void
shutdown()

Implements org.apache.derby.io.StorageFactory.shutdown.

Normally does nothing, but if the database is in a state such that it should be deleted this will happen here.

public boolean

Returns:

true
supportsRandomAccess
()

Implements org.apache.derby.io.StorageFactory.supportsRandomAccess.

The service supports random access.

public boolean
supportsWriteSync()

Implements org.apache.derby.io.WritableStorageFactory.supportsWriteSync.

This method tests whether the StorageRandomAccessFile "rws" and "rwd" modes are implemented.

public void
sync(OutputStream
ignored
stream
,
boolean
ignored
metaData
)

Implements org.apache.derby.io.WritableStorageFactory.sync.

The sync method is a no-op for this storage factory.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

canonicalNameback to summary
private String canonicalName

The canonical (unique) name of the database (absolute path).

DATABASESback to summary
private static final Map<String, DataStore> DATABASES

References to the databases created / existing.

dataDirectoryback to summary
private StorageFile dataDirectory

The data directory of the database.

dbDataback to summary
private DataStore dbData

The data store used for the database.

DUMMY_STOREback to summary
private static final DataStore DUMMY_STORE

Dummy store used to carry out frequent operations that don't require a "proper store", for instance getting the canonical name of the data store.

tempDirback to summary
private StorageFile tempDir

The temporary directory for the database (absolute path).

Constructor Detail

VFMemoryStorageFactoryback to summary
public VFMemoryStorageFactory()

Creates a new, uninitialized instance of the storage factory.

To initialize the instance, init must be called.

See Also
init

Method Detail

createTemporaryFileback to summary
public StorageFile createTemporaryFile(String prefix, String suffix)

Implements org.apache.derby.io.StorageFactory.createTemporaryFile.

Creates a handle to a temporary file.

Parameters
prefix:String

requested prefix for the file name

suffix:String

requested suffix for the file name, if null then .tmp will be used

Returns:StorageFile

A handle to the temporary file.

dbDropCleanupInDummyback to summary
private void dbDropCleanupInDummy(String dbPath)

Cleans up the internal dummy data store after a database has been dropped.

Parameters
dbPath:String

absolute path of the dropped database

getCanonicalNameback to summary
public String getCanonicalName()

Implements org.apache.derby.io.StorageFactory.getCanonicalName.

Doc from org.apache.derby.io.StorageFactory.getCanonicalName.

Get the canonical name of the database. This is a name that uniquely identifies it. It is system dependent. The normal, disk based implementation uses method java.io.File.getCanonicalPath on the directory holding the database to construct the canonical name.

Returns:String

the canonical name

getSeparatorback to summary
public char getSeparator()

Implements org.apache.derby.io.StorageFactory.getSeparator.

Returns the path separator used by this storage factory.

Returns:char

PathUtil.SEP

getStorageFactoryVersionback to summary
public int getStorageFactoryVersion()

Implements org.apache.derby.io.StorageFactory.getStorageFactoryVersion.

Returns:int

Doc from org.apache.derby.io.StorageFactory.getStorageFactoryVersion.

the StorageFactory version supported by this implementation

getTempDirback to summary
public StorageFile getTempDir()

Implements org.apache.derby.io.StorageFactory.getTempDir.

Returns the temporary directory for this storage factory instance.

Returns:StorageFile

A StorageFile-object representing the temp directory.

initback to summary
public void init(String home, String databaseName, String tempDirNameIgnored, String uniqueName) throws IOException

Implements org.apache.derby.io.StorageFactory.init.

Initializes the storage factory instance by setting up a temporary directory, the database directory and checking if the database being named already exists.

Parameters
home:String

the value of system.home for this storage factory

databaseName:String

the name of the database, all relative pathnames are relative to this name

tempDirNameIgnored:String

ignored

uniqueName:String

used to determine when the temporary directory can be created, but not to name the temporary directory itself

Exceptions
IOException:
on an error (unexpected).
isFastback to summary
public boolean isFast()

Implements org.apache.derby.io.StorageFactory.isFast.

The service is fast and supports random access.

Returns:boolean

true

isReadOnlyDatabaseback to summary
public boolean isReadOnlyDatabase()

Implements org.apache.derby.io.StorageFactory.isReadOnlyDatabase.

The service supports writes.

Returns:boolean

false

newStorageFileback to summary
public StorageFile newStorageFile(String path)

Implements org.apache.derby.io.StorageFactory.newStorageFile.

Returns a handle to the specific storage file.

Parameters
path:String

the path of the file or directory

Returns:StorageFile

A path handle.

newStorageFileback to summary
public StorageFile newStorageFile(String directoryName, String fileName)

Implements org.apache.derby.io.StorageFactory.newStorageFile.

Returns a handle to the specified storage file.

Parameters
directoryName:String

the name of the parent directory

fileName:String

the name of the file

Returns:StorageFile

A path handle.

newStorageFileback to summary
public StorageFile newStorageFile(StorageFile directoryName, String fileName)

Implements org.apache.derby.io.StorageFactory.newStorageFile.

Returns a handle to the specified storage file.

Parameters
directoryName:StorageFile

the name of the parent directory

fileName:String

the name of the file

Returns:StorageFile

A path handle.

normalizePathback to summary
private String normalizePath(String dir, String file)

Returns a normalized absolute path.

Parameters
dir:String

parent directory, if null the dataDirectory will be used

file:String

the file name (null not allowed)

Returns:String

A path.

Exceptions
NullPointerException:
if file is null
normalizePathback to summary
private String normalizePath(String path)

Returns a normalized absolute path.

Parameters
path:String

path, if null the dataDirectory will be used

Returns:String

A path.

setCanonicalNameback to summary
public void setCanonicalName(String name)

Implements org.apache.derby.io.StorageFactory.setCanonicalName.

Set the canonicalName. May need adjustment due to DERBY-5096

Parameters
name:String

uniquely identifiable name for this database

shutdownback to summary
public void shutdown()

Implements org.apache.derby.io.StorageFactory.shutdown.

Normally does nothing, but if the database is in a state such that it should be deleted this will happen here.

supportsRandomAccessback to summary
public boolean supportsRandomAccess()

Implements org.apache.derby.io.StorageFactory.supportsRandomAccess.

The service supports random access.

Returns:boolean

true

supportsWriteSyncback to summary
public boolean supportsWriteSync()

Implements org.apache.derby.io.WritableStorageFactory.supportsWriteSync.

Doc from org.apache.derby.io.WritableStorageFactory.supportsWriteSync.

This method tests whether the StorageRandomAccessFile "rws" and "rwd" modes are implemented. If the "rws" and "rwd" modes are supported then the database engine will conclude that the write methods of "rws"/"rwd" mode StorageRandomAccessFiles are slow but the sync method is fast and optimize accordingly.

Returns:boolean

true if an StIRandomAccess file opened with "rws" or "rwd" modes immediately writes data to the underlying storage, false if not.

syncback to summary
public void sync(OutputStream stream, boolean metaData)

Implements org.apache.derby.io.WritableStorageFactory.sync.

The sync method is a no-op for this storage factory.

Parameters
stream:OutputStream

ignored

metaData:boolean

ignored