StorageFactory
, WritableStorageFactory
public class VFMemoryStorageFactory extends java.lang.Object implements StorageFactory, WritableStorageFactory
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).
Modifier and Type | Field | Description |
---|---|---|
private java.lang.String |
canonicalName |
The canonical (unique) name of the database (absolute path).
|
private static java.util.Map<java.lang.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 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).
|
VERSION_NUMBER
Constructor | Description |
---|---|
VFMemoryStorageFactory() |
Creates a new, uninitialized instance of the storage factory.
|
Modifier and Type | Method | Description |
---|---|---|
StorageFile |
createTemporaryFile(java.lang.String prefix,
java.lang.String suffix) |
Creates a handle to a temporary file.
|
private void |
dbDropCleanupInDummy(java.lang.String dbPath) |
Cleans up the internal dummy data store after a database has been
dropped.
|
java.lang.String |
getCanonicalName() |
Get the canonical name of the database.
|
char |
getSeparator() |
Returns the path separator used by this storage factory.
|
int |
getStorageFactoryVersion() |
|
StorageFile |
getTempDir() |
Returns the temporary directory for this storage factory instance.
|
void |
init(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.
|
boolean |
isFast() |
The service is fast and supports random access.
|
boolean |
isReadOnlyDatabase() |
The service supports writes.
|
StorageFile |
newStorageFile(java.lang.String path) |
Returns a handle to the specific storage file.
|
StorageFile |
newStorageFile(java.lang.String directoryName,
java.lang.String fileName) |
Returns a handle to the specified storage file.
|
StorageFile |
newStorageFile(StorageFile directoryName,
java.lang.String fileName) |
Returns a handle to the specified storage file.
|
private java.lang.String |
normalizePath(java.lang.String path) |
Returns a normalized absolute path.
|
private java.lang.String |
normalizePath(java.lang.String dir,
java.lang.String file) |
Returns a normalized absolute path.
|
void |
setCanonicalName(java.lang.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 |
supportsRandomAccess() |
The service supports random access.
|
boolean |
supportsWriteSync() |
This method tests whether the StorageRandomAccessFile "rws" and "rwd" modes
are implemented.
|
void |
sync(java.io.OutputStream stream,
boolean metaData) |
The sync method is a no-op for this storage factory.
|
private static final java.util.Map<java.lang.String,DataStore> DATABASES
private static final DataStore DUMMY_STORE
private java.lang.String canonicalName
private StorageFile dataDirectory
private StorageFile tempDir
private DataStore dbData
public VFMemoryStorageFactory()
To initialize the instance, init
must be called.
public void init(java.lang.String home, java.lang.String databaseName, java.lang.String tempDirNameIgnored, java.lang.String uniqueName) throws java.io.IOException
init
in interface StorageFactory
home
- the value of system.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 itselfjava.io.IOException
- on an error (unexpected).public void shutdown()
shutdown
in interface StorageFactory
public java.lang.String getCanonicalName()
StorageFactory
getCanonicalName
in interface StorageFactory
public void setCanonicalName(java.lang.String name)
setCanonicalName
in interface StorageFactory
name
- uniquely identifiable name for this databasepublic StorageFile newStorageFile(java.lang.String path)
newStorageFile
in interface StorageFactory
path
- the path of the file or directorypublic StorageFile newStorageFile(java.lang.String directoryName, java.lang.String fileName)
newStorageFile
in interface StorageFactory
directoryName
- the name of the parent directoryfileName
- the name of the filepublic StorageFile newStorageFile(StorageFile directoryName, java.lang.String fileName)
newStorageFile
in interface StorageFactory
directoryName
- the name of the parent directoryfileName
- the name of the filepublic StorageFile getTempDir()
getTempDir
in interface StorageFactory
StorageFile
-object representing the temp directory.public boolean isFast()
isFast
in interface StorageFactory
true
public boolean isReadOnlyDatabase()
isReadOnlyDatabase
in interface StorageFactory
false
public boolean supportsRandomAccess()
supportsRandomAccess
in interface StorageFactory
true
public int getStorageFactoryVersion()
getStorageFactoryVersion
in interface StorageFactory
public StorageFile createTemporaryFile(java.lang.String prefix, java.lang.String suffix)
createTemporaryFile
in interface StorageFactory
prefix
- requested prefix for the file namesuffix
- requested suffix for the file name, if null
then
.tmp
will be usedpublic char getSeparator()
getSeparator
in interface StorageFactory
PathUtil.SEP
public void sync(java.io.OutputStream stream, boolean metaData)
sync
in interface WritableStorageFactory
stream
- ignoredmetaData
- ignoredpublic boolean supportsWriteSync()
WritableStorageFactory
supportsWriteSync
in interface WritableStorageFactory
private java.lang.String normalizePath(java.lang.String dir, java.lang.String file)
dir
- parent directory, if null
the dataDirectory
will be usedfile
- the file name (null
not allowed)java.lang.NullPointerException
- if file
is null
private java.lang.String normalizePath(java.lang.String path)
path
- path, if null
the dataDirectory
will be usedprivate void dbDropCleanupInDummy(java.lang.String dbPath)
dbPath
- absolute path of the dropped databaseApache Derby V10.14 Internals - Copyright © 2004,2018 The Apache Software Foundation. All Rights Reserved.