Package org.apache.derby.impl.io
Class VFMemoryStorageFactory
java.lang.Object
org.apache.derby.impl.io.VFMemoryStorageFactory
- All Implemented Interfaces:
StorageFactory
,WritableStorageFactory
public class VFMemoryStorageFactory
extends Object
implements StorageFactory, 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
FieldsModifier and TypeFieldDescriptionprivate String
The canonical (unique) name of the database (absolute path).References to the databases created / existing.private StorageFile
The data directory of the database.private DataStore
The data store used for the database.private static final DataStore
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
The temporary directory for the database (absolute path).Fields inherited from interface org.apache.derby.io.StorageFactory
VERSION_NUMBER
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new, uninitialized instance of the storage factory. -
Method Summary
Modifier and TypeMethodDescriptioncreateTemporaryFile
(String prefix, String suffix) Creates a handle to a temporary file.private void
dbDropCleanupInDummy
(String dbPath) Cleans up the internal dummy data store after a database has been dropped.Get the canonical name of the database.char
Returns the path separator used by this storage factory.int
Returns the temporary directory for this storage factory instance.void
Initializes the storage factory instance by setting up a temporary directory, the database directory and checking if the database being named already exists.boolean
isFast()
The service is fast and supports random access.boolean
The service supports writes.newStorageFile
(String path) Returns a handle to the specific storage file.newStorageFile
(String directoryName, String fileName) Returns a handle to the specified storage file.newStorageFile
(StorageFile directoryName, String fileName) Returns a handle to the specified storage file.private String
normalizePath
(String path) Returns a normalized absolute path.private String
normalizePath
(String dir, String file) Returns a normalized absolute path.void
setCanonicalName
(String name) Set the canonicalName.void
shutdown()
Normally does nothing, but if the database is in a state such that it should be deleted this will happen here.boolean
The service supports random access.boolean
This method tests whether the StorageRandomAccessFile "rws" and "rwd" modes are implemented.void
sync
(OutputStream stream, boolean metaData) The sync method is a no-op for this storage factory.
-
Field Details
-
DATABASES
References to the databases created / existing. -
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. -
canonicalName
The canonical (unique) name of the database (absolute path). -
dataDirectory
The data directory of the database. -
tempDir
The temporary directory for the database (absolute path). -
dbData
The data store used for the database.
-
-
Constructor Details
-
VFMemoryStorageFactory
public VFMemoryStorageFactory()Creates a new, uninitialized instance of the storage factory.To initialize the instance,
init
must be called.- See Also:
-
-
Method Details
-
init
public void init(String home, String databaseName, String tempDirNameIgnored, String uniqueName) throws IOException Initializes the storage factory instance by setting up a temporary directory, the database directory and checking if the database being named already exists.- Specified by:
init
in interfaceStorageFactory
- Parameters:
home
- the value ofsystem.home
for this storage factorydatabaseName
- the name of the database, all relative pathnames are relative to this nametempDirNameIgnored
- ignoreduniqueName
- used to determine when the temporary directory can be created, but not to name the temporary directory itself- Throws:
IOException
- on an error (unexpected).
-
shutdown
public void shutdown()Normally does nothing, but if the database is in a state such that it should be deleted this will happen here.- Specified by:
shutdown
in interfaceStorageFactory
-
getCanonicalName
Description copied from interface:StorageFactory
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.- Specified by:
getCanonicalName
in interfaceStorageFactory
- Returns:
- the canonical name
-
setCanonicalName
Set the canonicalName. May need adjustment due to DERBY-5096- Specified by:
setCanonicalName
in interfaceStorageFactory
- Parameters:
name
- uniquely identifiable name for this database
-
newStorageFile
Returns a handle to the specific storage file.- Specified by:
newStorageFile
in interfaceStorageFactory
- Parameters:
path
- the path of the file or directory- Returns:
- A path handle.
-
newStorageFile
Returns a handle to the specified storage file.- Specified by:
newStorageFile
in interfaceStorageFactory
- Parameters:
directoryName
- the name of the parent directoryfileName
- the name of the file- Returns:
- A path handle.
-
newStorageFile
Returns a handle to the specified storage file.- Specified by:
newStorageFile
in interfaceStorageFactory
- Parameters:
directoryName
- the name of the parent directoryfileName
- the name of the file- Returns:
- A path handle.
-
getTempDir
Returns the temporary directory for this storage factory instance.- Specified by:
getTempDir
in interfaceStorageFactory
- Returns:
- A
StorageFile
-object representing the temp directory.
-
isFast
public boolean isFast()The service is fast and supports random access.- Specified by:
isFast
in interfaceStorageFactory
- Returns:
true
-
isReadOnlyDatabase
public boolean isReadOnlyDatabase()The service supports writes.- Specified by:
isReadOnlyDatabase
in interfaceStorageFactory
- Returns:
false
-
supportsRandomAccess
public boolean supportsRandomAccess()The service supports random access.- Specified by:
supportsRandomAccess
in interfaceStorageFactory
- Returns:
true
-
getStorageFactoryVersion
public int getStorageFactoryVersion()- Specified by:
getStorageFactoryVersion
in interfaceStorageFactory
- Returns:
- the StorageFactory version supported by this implementation
-
createTemporaryFile
Creates a handle to a temporary file.- Specified by:
createTemporaryFile
in interfaceStorageFactory
- Parameters:
prefix
- requested prefix for the file namesuffix
- requested suffix for the file name, ifnull
then.tmp
will be used- Returns:
- A handle to the temporary file.
-
getSeparator
public char getSeparator()Returns the path separator used by this storage factory.- Specified by:
getSeparator
in interfaceStorageFactory
- Returns:
PathUtil.SEP
-
sync
The sync method is a no-op for this storage factory.- Specified by:
sync
in interfaceWritableStorageFactory
- Parameters:
stream
- ignoredmetaData
- ignored
-
supportsWriteSync
public boolean supportsWriteSync()Description copied from interface:WritableStorageFactory
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.- Specified by:
supportsWriteSync
in interfaceWritableStorageFactory
- Returns:
- true if an StIRandomAccess file opened with "rws" or "rwd" modes immediately writes data to the underlying storage, false if not.
-
normalizePath
Returns a normalized absolute path.- Parameters:
dir
- parent directory, ifnull
thedataDirectory
will be usedfile
- the file name (null
not allowed)- Returns:
- A path.
- Throws:
NullPointerException
- iffile
isnull
-
normalizePath
Returns a normalized absolute path.- Parameters:
path
- path, ifnull
thedataDirectory
will be used- Returns:
- A path.
-
dbDropCleanupInDummy
Cleans up the internal dummy data store after a database has been dropped.- Parameters:
dbPath
- absolute path of the dropped database
-