public final class DataStore
extends java.lang.Object
A newly created data store doesn't contain a single existing directory.
Modifier and Type | Field | Description |
---|---|---|
private java.lang.String |
databaseName |
The name of the database this store serves, expected to be the absolute
path of the service root (i.e.
|
private boolean |
deleteMe |
Tells if this store is scheduled for deletion.
|
private static java.lang.String[] |
EMPTY_STR_ARR |
Constant for the empty String array.
|
private java.util.Map<java.lang.String,DataStoreEntry> |
files |
The files exsiting in the store.
|
private java.lang.Object |
LOCK |
Lock object for the file map.
|
private static char |
SEP |
The path separator used.
|
private java.lang.Object |
TMP_COUNTER_LOCK |
Lock object for the temporary file counter.
|
private long |
tmpFileCounter |
Counter used to generate unique temporary file names.
|
Constructor | Description |
---|---|
DataStore(java.lang.String databaseName) |
Creates a new data store.
|
Modifier and Type | Method | Description |
---|---|---|
private boolean |
_deleteAll(java.lang.String prefixPath) |
Deletes every child of the root path specified.
|
boolean |
createAllParents(java.lang.String path) |
Creates all the parents of the specified path.
|
DataStoreEntry |
createEntry(java.lang.String iPath,
boolean isDir) |
Creates a new entry in the data store.
|
boolean |
deleteAll(java.lang.String iPath) |
Deletes the specified entry and all its children.
|
boolean |
deleteEntry(java.lang.String iPath) |
Deletes the specified entry.
|
java.lang.String |
getDatabaseName() |
Returns the database name, which is expected to equal the path of the
service root.
|
DataStoreEntry |
getEntry(java.lang.String iPath) |
Returns the entry with the specified path.
|
private java.lang.String[] |
getParentList(java.lang.String path) |
Returns the list of parents for the specified path.
|
long |
getTempFileCounter() |
Returns an identifier for a temporary file.
|
java.lang.String[] |
listChildren(java.lang.String iPath) |
Lists the childen of the specified path.
|
boolean |
move(StorageFile currentFile,
StorageFile newFile) |
Moves / renames a file.
|
void |
purge() |
Purges the database and releases all files associated with it.
|
boolean |
scheduledForDeletion() |
Tells if this data store is scheduled for deletion.
|
private static final char SEP
private static final java.lang.String[] EMPTY_STR_ARR
private final java.lang.Object LOCK
private final java.lang.Object TMP_COUNTER_LOCK
private final java.util.Map<java.lang.String,DataStoreEntry> files
The initial size is set to the number of initial files of a Derby database, pluss a few more.
private final java.lang.String databaseName
private long tmpFileCounter
private boolean deleteMe
public DataStore(java.lang.String databaseName)
databaseName
- the name of the assoicated database, expected to be
the absolute path of the service root.public java.lang.String getDatabaseName()
public boolean scheduledForDeletion()
true
if the store is awaiting deletion,
false
otherwise.public DataStoreEntry createEntry(java.lang.String iPath, boolean isDir)
This method returns null
if the path already exists, if one of
the parent directories doesn't exist, or if one of the parents is a
file instead of a directory.
iPath
- the path of the entryisDir
- tells if the new entry shall be directory or a fileDataStoreEntry
-instance if the entry was successfully
created, null
otherwisepublic boolean createAllParents(java.lang.String path)
true
if all parents either already existed as directories
or were created, false
otherwisepublic boolean deleteEntry(java.lang.String iPath)
If the specified entry is a directory, it is only deleted if it is empty. Read-only entries are deleted.
iPath
- path of the entry to deletetrue
if the entry was deleted, false
otherwise.public DataStoreEntry getEntry(java.lang.String iPath)
iPath
- path of the entry to fetchnull
if the entry doesn't exist, the
DataStoreEntry
-object otherwise.public boolean deleteAll(java.lang.String iPath)
iPath
- the root entrytrue
if the entry and all its children were deleted,
false
if the root doesn't exist.public java.lang.String[] listChildren(java.lang.String iPath)
iPath
- the directory to list the children ofpublic boolean move(StorageFile currentFile, StorageFile newFile)
currentFile
- the current filenewFile
- the new filetrue
if the file was moved, false
if the new
file already existed or the existing file doesn't exist.public void purge()
private boolean _deleteAll(java.lang.String prefixPath)
Note that the root itself must be removed outside of this method.
prefixPath
- the normalized root path to start deleting fromtrue
if all children of the root path were deleted,
false
otherwise.public long getTempFileCounter()
private java.lang.String[] getParentList(java.lang.String path)
The lowest level parent is listed first in the list, so all absolute paths will have the root listed as the last element.
path
- the normalized path to create a parent list forApache Derby V10.14 Internals - Copyright © 2004,2018 The Apache Software Foundation. All Rights Reserved.