Class StorageFactoryService
java.lang.Object
org.apache.derby.impl.services.monitor.StorageFactoryService
- All Implemented Interfaces:
PersistentService
This class implements the PersistentService interface using a StorageFactory class.
It handles all subSubProtocols except for cache.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) final class
private static class
Helper class for common file operations on the service properties files. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate String
private String
private StorageFactory
private char
private static final String
Marker printed as the last line of the service properties file.private final Class
<?> private final String
Fields inherited from interface org.apache.derby.iapi.services.monitor.PersistentService
CLASSPATH, DB_README_FILE_NAME, DIRECTORY, HTTP, HTTPS, INMEMORY, JAR, PROPERTIES_NAME, ROOT, TYPE
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Put a readme file in database directory which will caution users against touching any files in the directory.createServiceRoot
(String name, boolean deleteExisting) Properties cannot be savedprivate final boolean
fileExists
(File file) Checks if the specified file exists.Return a list of all the directoies in the system directory.Convert a service name into its canonical form.private String
getDirectoryPath
(String name) private static ModuleFactory
Privileged Monitor lookup.private static String
Helper method returning the "best-effort-most-accurate" path.private String
Returns the protocol lead in for this service.getServiceProperties
(String serviceName, Properties defaultProperties) Open the service properties in the directory identified by the service name.Get the StorageFactory implementation for this PersistentServicegetStorageFactoryInstance
(boolean useHome, String databaseName, String tempDirName, String uniqueName) Get an initialized StorageFactoryInstancegetType()
The type of the service is 'directory'getUserServiceName
(String serviceName) Return the user form of a service name.boolean
boolean
isSameService
(String serviceName1, String serviceName2) private StorageFactory
privGetStorageFactoryInstance
(boolean useHome, String databaseName, String tempDirName, String uniqueName) protected String
recreateServiceRoot
(String serviceName, Properties properties) boolean
removeServiceRoot
(String serviceName) Remove a service's root and its contents.private void
Resolves situations where a failure condition left the service properties file, and/or the service properties file backup, in an inconsistent state.void
saveServiceProperties
(String serviceName, Properties properties) Save service.properties during backupvoid
saveServiceProperties
(String serviceName, StorageFactory sf, Properties properties, boolean replace) private void
vetService
(StorageFactory storageFactory, String serviceName) Verify that the service directory looks ok before objecting that the database already exists.
-
Field Details
-
SERVICE_PROPERTIES_EOF_TOKEN
Marker printed as the last line of the service properties file.- See Also:
-
home
-
canonicalHome
-
subSubProtocol
-
storageFactoryClass
-
rootStorageFactory
-
separatorChar
private char separatorChar
-
-
Constructor Details
-
StorageFactoryService
StorageFactoryService(String subSubProtocol, Class storageFactoryClass) throws StandardException - Throws:
StandardException
-
-
Method Details
-
hasStorageFactory
public boolean hasStorageFactory()- Specified by:
hasStorageFactory
in interfacePersistentService
- Returns:
- true if the PersistentService has a StorageFactory, false if not.
-
getStorageFactoryInstance
public StorageFactory getStorageFactoryInstance(boolean useHome, String databaseName, String tempDirName, String uniqueName) throws StandardException, IOException Get an initialized StorageFactoryInstance- Specified by:
getStorageFactoryInstance
in interfacePersistentService
- Parameters:
useHome
- If true and the database name is not absolute then the database directory will be relative to the home directory, if one is defined in the properties file.databaseName
- The name of the database (directory). The name does not include the subSubProtocol. If null then the storage factory will only be used to deal with the directory containing the databases.tempDirName
- The name of the temporary file directory set in properties. If null then a default directory should be used. Each database should get a separate temporary file directory within this one to avoid collisions.uniqueName
- A unique name that can be used to create the temporary file directory for this database. If null then temporary files will not be created in this StorageFactory instance.- Returns:
- An initialized StorageFactory.
- Throws:
IOException
- if create, the database directory does not exist, and it cannot be created; if !create and the database does not exist as a directory.StandardException
-
privGetStorageFactoryInstance
private StorageFactory privGetStorageFactoryInstance(boolean useHome, String databaseName, String tempDirName, String uniqueName) throws InstantiationException, IllegalAccessException, IOException, NoSuchMethodException, InvocationTargetException -
getType
The type of the service is 'directory'- Specified by:
getType
in interfacePersistentService
- See Also:
-
getBootTimeServices
Return a list of all the directoies in the system directory.- Specified by:
getBootTimeServices
in interfacePersistentService
- See Also:
-
getServiceProperties
public Properties getServiceProperties(String serviceName, Properties defaultProperties) throws StandardException Open the service properties in the directory identified by the service name.- Specified by:
getServiceProperties
in interfacePersistentService
- Returns:
- A Properties object or null if serviceName does not represent a valid service.
- Throws:
StandardException
- Service appears valid but the properties cannot be created.
-
saveServiceProperties
public void saveServiceProperties(String serviceName, StorageFactory sf, Properties properties, boolean replace) throws StandardException - Specified by:
saveServiceProperties
in interfacePersistentService
- Throws:
StandardException
- Properties cannot be saved.
-
createDataWarningFile
Description copied from interface:PersistentService
Put a readme file in database directory which will caution users against touching any files in the directory. This file will be created at database creation time.- Specified by:
createDataWarningFile
in interfacePersistentService
- Parameters:
sf
- StorageFactory will be used to create the file- Throws:
StandardException
- File can't be created- See Also:
-
saveServiceProperties
public void saveServiceProperties(String serviceName, Properties properties) throws StandardException Save service.properties during backup- Specified by:
saveServiceProperties
in interfacePersistentService
- Parameters:
serviceName
- backup location of the serviceproperties
- the properties to save- Throws:
StandardException
- Properties cannot be saved.
-
resolveServicePropertiesFiles
private void resolveServicePropertiesFiles(StorageFactory sf, StorageFile spf) throws StandardException Resolves situations where a failure condition left the service properties file, and/or the service properties file backup, in an inconsistent state.Note that this method doesn't resolve the situation where both the current service properties file and the backup file are missing.
- Parameters:
sf
- the storage factory for the servicespf
- the service properties file- Throws:
StandardException
- if a file operation on a service properties file fails
-
recreateServiceRoot
protected String recreateServiceRoot(String serviceName, Properties properties) throws StandardException - Throws:
StandardException
-
createServiceRoot
Properties cannot be saved- Specified by:
createServiceRoot
in interfacePersistentService
- Throws:
StandardException
- Service root cannot be created.
-
vetService
Verify that the service directory looks ok before objecting that the database already exists.- Throws:
StandardException
-
getDirectoryPath
-
removeServiceRoot
Description copied from interface:PersistentService
Remove a service's root and its contents.- Specified by:
removeServiceRoot
in interfacePersistentService
-
getCanonicalServiceName
Description copied from interface:PersistentService
Convert a service name into its canonical form. Returns null if the name cannot be converted into a canonical form.- Specified by:
getCanonicalServiceName
in interfacePersistentService
- Throws:
StandardException
- if an error happens when converting the name (name probably invalid)
-
getUserServiceName
Description copied from interface:PersistentService
Return the user form of a service name. This name is only valid within this system. The separator character used must be '/'- Specified by:
getUserServiceName
in interfacePersistentService
-
isSameService
- Specified by:
isSameService
in interfacePersistentService
-
fileExists
Checks if the specified file exists.- Parameters:
file
- the file to check- Returns:
true
if the file exists,false
if not.- Throws:
SecurityException
- if the required privileges are missing
-
getStorageFactoryClass
Get the StorageFactory implementation for this PersistentService- Returns:
- the StorageFactory class.
-
getProtocolLeadIn
Returns the protocol lead in for this service.- Returns:
- An empty string if the protocol is the default one (PersistentService.DIRECTORY), the subsub protocol name followed by colon otherwise.
-
getMonitor
Privileged Monitor lookup. Must be private so that user code can't call this entry point. -
getMostAccuratePath
Helper method returning the "best-effort-most-accurate" path.- Parameters:
file
- the file to get the path to- Returns:
- The file path, either ala
File.getCanonicalPath
orFile.getPath
.
-