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 java.lang.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
shutdownor ininit. 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, theinit-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
Fields Modifier and Type Field Description private java.lang.StringcanonicalNameThe canonical (unique) name of the database (absolute path).private static java.util.Map<java.lang.String,DataStore>DATABASESReferences to the databases created / existing.private StorageFiledataDirectoryThe data directory of the database.private DataStoredbDataThe data store used for the database.private static DataStoreDUMMY_STOREDummy 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 StorageFiletempDirThe temporary directory for the database (absolute path).-
Fields inherited from interface org.apache.derby.io.StorageFactory
VERSION_NUMBER
-
-
Constructor Summary
Constructors Constructor Description VFMemoryStorageFactory()Creates a new, uninitialized instance of the storage factory.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description StorageFilecreateTemporaryFile(java.lang.String prefix, java.lang.String suffix)Creates a handle to a temporary file.private voiddbDropCleanupInDummy(java.lang.String dbPath)Cleans up the internal dummy data store after a database has been dropped.java.lang.StringgetCanonicalName()Get the canonical name of the database.chargetSeparator()Returns the path separator used by this storage factory.intgetStorageFactoryVersion()StorageFilegetTempDir()Returns the temporary directory for this storage factory instance.voidinit(java.lang.String home, java.lang.String databaseName, java.lang.String tempDirNameIgnored, java.lang.String uniqueName)Initializes the storage factory instance by setting up a temporary directory, the database directory and checking if the database being named already exists.booleanisFast()The service is fast and supports random access.booleanisReadOnlyDatabase()The service supports writes.StorageFilenewStorageFile(java.lang.String path)Returns a handle to the specific storage file.StorageFilenewStorageFile(java.lang.String directoryName, java.lang.String fileName)Returns a handle to the specified storage file.StorageFilenewStorageFile(StorageFile directoryName, java.lang.String fileName)Returns a handle to the specified storage file.private java.lang.StringnormalizePath(java.lang.String path)Returns a normalized absolute path.private java.lang.StringnormalizePath(java.lang.String dir, java.lang.String file)Returns a normalized absolute path.voidsetCanonicalName(java.lang.String name)Set the canonicalName.voidshutdown()Normally does nothing, but if the database is in a state such that it should be deleted this will happen here.booleansupportsRandomAccess()The service supports random access.booleansupportsWriteSync()This method tests whether the StorageRandomAccessFile "rws" and "rwd" modes are implemented.voidsync(java.io.OutputStream stream, boolean metaData)The sync method is a no-op for this storage factory.
-
-
-
Field Detail
-
DATABASES
private static final java.util.Map<java.lang.String,DataStore> DATABASES
References to the databases created / existing.
-
DUMMY_STORE
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.
-
canonicalName
private java.lang.String canonicalName
The canonical (unique) name of the database (absolute path).
-
dataDirectory
private StorageFile dataDirectory
The data directory of the database.
-
tempDir
private StorageFile tempDir
The temporary directory for the database (absolute path).
-
dbData
private DataStore dbData
The data store used for the database.
-
-
Method Detail
-
init
public void init(java.lang.String home, java.lang.String databaseName, java.lang.String tempDirNameIgnored, java.lang.String uniqueName) throws java.io.IOExceptionInitializes the storage factory instance by setting up a temporary directory, the database directory and checking if the database being named already exists.- Specified by:
initin interfaceStorageFactory- Parameters:
home- the value ofsystem.homefor 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:
java.io.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:
shutdownin interfaceStorageFactory
-
getCanonicalName
public java.lang.String getCanonicalName()
Description copied from interface:StorageFactoryGet 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:
getCanonicalNamein interfaceStorageFactory- Returns:
- the canonical name
-
setCanonicalName
public void setCanonicalName(java.lang.String name)
Set the canonicalName. May need adjustment due to DERBY-5096- Specified by:
setCanonicalNamein interfaceStorageFactory- Parameters:
name- uniquely identifiable name for this database
-
newStorageFile
public StorageFile newStorageFile(java.lang.String path)
Returns a handle to the specific storage file.- Specified by:
newStorageFilein interfaceStorageFactory- Parameters:
path- the path of the file or directory- Returns:
- A path handle.
-
newStorageFile
public StorageFile newStorageFile(java.lang.String directoryName, java.lang.String fileName)
Returns a handle to the specified storage file.- Specified by:
newStorageFilein interfaceStorageFactory- Parameters:
directoryName- the name of the parent directoryfileName- the name of the file- Returns:
- A path handle.
-
newStorageFile
public StorageFile newStorageFile(StorageFile directoryName, java.lang.String fileName)
Returns a handle to the specified storage file.- Specified by:
newStorageFilein interfaceStorageFactory- Parameters:
directoryName- the name of the parent directoryfileName- the name of the file- Returns:
- A path handle.
-
getTempDir
public StorageFile getTempDir()
Returns the temporary directory for this storage factory instance.- Specified by:
getTempDirin interfaceStorageFactory- Returns:
- A
StorageFile-object representing the temp directory.
-
isFast
public boolean isFast()
The service is fast and supports random access.- Specified by:
isFastin interfaceStorageFactory- Returns:
true
-
isReadOnlyDatabase
public boolean isReadOnlyDatabase()
The service supports writes.- Specified by:
isReadOnlyDatabasein interfaceStorageFactory- Returns:
false
-
supportsRandomAccess
public boolean supportsRandomAccess()
The service supports random access.- Specified by:
supportsRandomAccessin interfaceStorageFactory- Returns:
true
-
getStorageFactoryVersion
public int getStorageFactoryVersion()
- Specified by:
getStorageFactoryVersionin interfaceStorageFactory- Returns:
- the StorageFactory version supported by this implementation
-
createTemporaryFile
public StorageFile createTemporaryFile(java.lang.String prefix, java.lang.String suffix)
Creates a handle to a temporary file.- Specified by:
createTemporaryFilein interfaceStorageFactory- Parameters:
prefix- requested prefix for the file namesuffix- requested suffix for the file name, ifnullthen.tmpwill be used- Returns:
- A handle to the temporary file.
-
getSeparator
public char getSeparator()
Returns the path separator used by this storage factory.- Specified by:
getSeparatorin interfaceStorageFactory- Returns:
PathUtil.SEP
-
sync
public void sync(java.io.OutputStream stream, boolean metaData)The sync method is a no-op for this storage factory.- Specified by:
syncin interfaceWritableStorageFactory- Parameters:
stream- ignoredmetaData- ignored
-
supportsWriteSync
public boolean supportsWriteSync()
Description copied from interface:WritableStorageFactoryThis 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:
supportsWriteSyncin interfaceWritableStorageFactory- Returns:
- true if an StIRandomAccess file opened with "rws" or "rwd" modes immediately writes data to the underlying storage, false if not.
-
normalizePath
private java.lang.String normalizePath(java.lang.String dir, java.lang.String file)Returns a normalized absolute path.- Parameters:
dir- parent directory, ifnullthedataDirectorywill be usedfile- the file name (nullnot allowed)- Returns:
- A path.
- Throws:
java.lang.NullPointerException- iffileisnull
-
normalizePath
private java.lang.String normalizePath(java.lang.String path)
Returns a normalized absolute path.- Parameters:
path- path, ifnullthedataDirectorywill be used- Returns:
- A path.
-
dbDropCleanupInDummy
private void dbDropCleanupInDummy(java.lang.String dbPath)
Cleans up the internal dummy data store after a database has been dropped.- Parameters:
dbPath- absolute path of the dropped database
-
-