Top Description Inners Fields Constructors Methods
org.apache.derby.impl.services.monitor

pack-priv final Class StorageFactoryService

extends Object
implements PersistentService
Class Inheritance
All Implemented Interfaces
org.apache.derby.iapi.services.monitor.PersistentService
Imports
org.apache.derby.shared.common.reference.MessageId, .SQLState, .Attribute, .Property, org.apache.derby.shared.common.i18n.MessageService, org.apache.derby.iapi.services.monitor.ModuleFactory, .Monitor, .PersistentService, org.apache.derby.shared.common.sanity.SanityManager, org.apache.derby.shared.common.error.StandardException, org.apache.derby.io.StorageFile, .StorageFactory, .WritableStorageFactory, .StorageRandomAccessFile, java.io.BufferedReader, .File, .FileInputStream, .FileOutputStream, .FileReader, .InputStream, .BufferedInputStream, .BufferedWriter, .InputStreamReader, .OutputStream, .IOException, .FileNotFoundException, .OutputStreamWriter, java.lang.reflect.InvocationTargetException, java.util.Enumeration, .NoSuchElementException, .Properties, org.apache.derby.iapi.services.io.FileUtil

This class implements the PersistentService interface using a StorageFactory class. It handles all subSubProtocols except for cache.

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv class
private static class
StorageFactoryService.FileOperationHelper

Helper class for common file operations on the service properties files.

Field Summary

Modifier and TypeField and Description
private String
private String
private StorageFactory
private char
private static final String
SERVICE_PROPERTIES_EOF_TOKEN

Marker printed as the last line of the service properties file.

private final Class<?>
private final String

Constructor Summary

AccessConstructor and Description
pack-priv
StorageFactoryService(String subSubProtocol, Class<T> storageFactoryClass)

Method Summary

Modifier and TypeMethod and Description
public void
createDataWarningFile(StorageFactory
StorageFactory will be used to create the file
sf
)

Implements org.apache.derby.iapi.services.monitor.PersistentService.createDataWarningFile.

Put a readme file in database directory which will caution users against touching any files in the directory.

public String
createServiceRoot(final String name, final boolean deleteExisting)

Implements org.apache.derby.iapi.services.monitor.PersistentService.createServiceRoot.

Properties cannot be saved

private final boolean

Returns:

true if the file exists, false if not.
fileExists
(final File
the file to check
file
)

Checks if the specified file exists.

public Enumeration<E>
getBootTimeServices()

Implements org.apache.derby.iapi.services.monitor.PersistentService.getBootTimeServices.

Return a list of all the directoies in the system directory.

public String
private String
private static ModuleFactory
getMonitor()

Must be private so that user code can't call this entry point.

private static String

Returns:

The file path, either ala File.getCanonicalPath or File.getPath.
getMostAccuratePath
(StorageFile
the file to get the path to
file
)

Helper method returning the "best-effort-most-accurate" path.

private String

Returns:

An empty string if the protocol is the default one (PersistentService.DIRECTORY), the subsub protocol name followed by colon otherwise.
getProtocolLeadIn
()

Returns the protocol lead in for this service.

public Properties

Returns:

A Properties object or null if serviceName does not represent a valid service.
getServiceProperties
(final String serviceName, Properties defaultProperties)

Implements org.apache.derby.iapi.services.monitor.PersistentService.getServiceProperties.

Open the service properties in the directory identified by the service name.

public Class<T>

Returns:

the StorageFactory class.
getStorageFactoryClass
()

Get the StorageFactory implementation for this PersistentService

public StorageFactory

Returns:

An initialized StorageFactory.
getStorageFactoryInstance
(final boolean
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.
useHome
,
final String
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.
databaseName
,
final String
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.
tempDirName
,
final String
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.
uniqueName
)

Implements org.apache.derby.iapi.services.monitor.PersistentService.getStorageFactoryInstance.

Get an initialized StorageFactoryInstance

public String
getType()

Implements org.apache.derby.iapi.services.monitor.PersistentService.getType.

The type of the service is 'directory'

public String
getUserServiceName(String serviceName)

Implements org.apache.derby.iapi.services.monitor.PersistentService.getUserServiceName.

Return the user form of a service name.

public boolean

Returns:

true if the PersistentService has a StorageFactory, false if not.
hasStorageFactory
()

Implements org.apache.derby.iapi.services.monitor.PersistentService.hasStorageFactory.

public boolean
private StorageFactory
privGetStorageFactoryInstance(boolean useHome, String databaseName, String tempDirName, String uniqueName)

protected String
recreateServiceRoot(final String serviceName, Properties properties)

private StandardException
public boolean
removeServiceRoot(final String serviceName)

Implements org.apache.derby.iapi.services.monitor.PersistentService.removeServiceRoot.

Remove a service's root and its contents.

private void
resolveServicePropertiesFiles(StorageFactory
the storage factory for the service
sf
,
StorageFile
the service properties file
spf
)

Resolves situations where a failure condition left the service properties file, and/or the service properties file backup, in an inconsistent state.

public void
public void
saveServiceProperties(final String
backup location of the service
serviceName
,
final Properties
the properties to save
properties
)

Implements org.apache.derby.iapi.services.monitor.PersistentService.saveServiceProperties.

Save service.properties during backup

private StandardException
private void
vetService(StorageFactory storageFactory, String serviceName)

Verify that the service directory looks ok before objecting that the database already exists.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

canonicalHomeback to summary
private String canonicalHome
homeback to summary
private String home
rootStorageFactoryback to summary
private StorageFactory rootStorageFactory
separatorCharback to summary
private char separatorChar
SERVICE_PROPERTIES_EOF_TOKENback to summary
private static final String SERVICE_PROPERTIES_EOF_TOKEN

Marker printed as the last line of the service properties file.

storageFactoryClassback to summary
private final Class<?> storageFactoryClass
subSubProtocolback to summary
private final String subSubProtocol

Constructor Detail

StorageFactoryServiceback to summary
pack-priv StorageFactoryService(String subSubProtocol, Class<T> storageFactoryClass) throws StandardException

Method Detail

createDataWarningFileback to summary
public void createDataWarningFile(StorageFactory sf) throws StandardException

Implements org.apache.derby.iapi.services.monitor.PersistentService.createDataWarningFile.

Doc from org.apache.derby.iapi.services.monitor.PersistentService.createDataWarningFile.

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.

Parameters
sf:StorageFactory

StorageFactory will be used to create the file

Exceptions
StandardException:
File can't be created
See Also
PersistentService#createDataWarningFile
createServiceRootback to summary
public String createServiceRoot(final String name, final boolean deleteExisting) throws StandardException

Implements org.apache.derby.iapi.services.monitor.PersistentService.createServiceRoot.

Properties cannot be saved

Exceptions
StandardException:

Doc from org.apache.derby.iapi.services.monitor.PersistentService.createServiceRoot.

Service root cannot be created.

fileExistsback to summary
private final boolean fileExists(final File file)

Checks if the specified file exists.

Parameters
file:File

the file to check

Returns:boolean

true if the file exists, false if not.

getBootTimeServicesback to summary
public Enumeration<E> getBootTimeServices()

Implements org.apache.derby.iapi.services.monitor.PersistentService.getBootTimeServices.

Return a list of all the directoies in the system directory.

See Also
PersistentService#getBootTimeServices
getCanonicalServiceNameback to summary
public String getCanonicalServiceName(String name) throws StandardException

Implements org.apache.derby.iapi.services.monitor.PersistentService.getCanonicalServiceName.

Doc from org.apache.derby.iapi.services.monitor.PersistentService.getCanonicalServiceName.

Convert a service name into its canonical form. Returns null if the name cannot be converted into a canonical form.

Exceptions
StandardException:
if an error happens when converting the name (name probably invalid)
getDirectoryPathback to summary
private String getDirectoryPath(String name)
getMonitorback to summary
private static ModuleFactory getMonitor()

Must be private so that user code can't call this entry point.

getMostAccuratePathback to summary
private static String getMostAccuratePath(StorageFile file)

Helper method returning the "best-effort-most-accurate" path.

Parameters
file:StorageFile

the file to get the path to

Returns:String

The file path, either ala File.getCanonicalPath or File.getPath.

getProtocolLeadInback to summary
private String getProtocolLeadIn()

Returns the protocol lead in for this service.

Returns:String

An empty string if the protocol is the default one (PersistentService.DIRECTORY), the subsub protocol name followed by colon otherwise.

getServicePropertiesback to summary
public Properties getServiceProperties(final String serviceName, Properties defaultProperties) throws StandardException

Implements org.apache.derby.iapi.services.monitor.PersistentService.getServiceProperties.

Open the service properties in the directory identified by the service name.

Returns:Properties

A Properties object or null if serviceName does not represent a valid service.

Exceptions
StandardException:
Service appears valid but the properties cannot be created.
getStorageFactoryClassback to summary
public Class<T> getStorageFactoryClass()

Get the StorageFactory implementation for this PersistentService

Returns:Class<T>

the StorageFactory class.

getStorageFactoryInstanceback to summary
public StorageFactory getStorageFactoryInstance(final boolean useHome, final String databaseName, final String tempDirName, final String uniqueName) throws StandardException, IOException

Implements org.apache.derby.iapi.services.monitor.PersistentService.getStorageFactoryInstance.

Get an initialized StorageFactoryInstance

Parameters
useHome:boolean

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:String

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:String

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:String

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:StorageFactory

An initialized StorageFactory.

Exceptions
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.
getTypeback to summary
public String getType()

Implements org.apache.derby.iapi.services.monitor.PersistentService.getType.

The type of the service is 'directory'

See Also
PersistentService#getType
getUserServiceNameback to summary
public String getUserServiceName(String serviceName)

Implements org.apache.derby.iapi.services.monitor.PersistentService.getUserServiceName.

Doc from org.apache.derby.iapi.services.monitor.PersistentService.getUserServiceName.

Return the user form of a service name. This name is only valid within this system. The separator character used must be '/'

hasStorageFactoryback to summary
public boolean hasStorageFactory()

Implements org.apache.derby.iapi.services.monitor.PersistentService.hasStorageFactory.

Returns:boolean

true if the PersistentService has a StorageFactory, false if not.

isSameServiceback to summary
public boolean isSameService(String serviceName1, String serviceName2)

Implements org.apache.derby.iapi.services.monitor.PersistentService.isSameService.

privGetStorageFactoryInstanceback to summary
private StorageFactory privGetStorageFactoryInstance(boolean useHome, String databaseName, String tempDirName, String uniqueName) throws InstantiationException, IllegalAccessException, IOException, NoSuchMethodException, InvocationTargetException
recreateServiceRootback to summary
protected String recreateServiceRoot(final String serviceName, Properties properties) throws StandardException
registeredClassInstanceErrorback to summary
private StandardException registeredClassInstanceError(Exception e)
removeServiceRootback to summary
public boolean removeServiceRoot(final String serviceName)

Implements org.apache.derby.iapi.services.monitor.PersistentService.removeServiceRoot.

Doc from org.apache.derby.iapi.services.monitor.PersistentService.removeServiceRoot.

Remove a service's root and its contents.

resolveServicePropertiesFilesback to summary
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:StorageFactory

the storage factory for the service

spf:StorageFile

the service properties file

Exceptions
StandardException:
if a file operation on a service properties file fails
saveServicePropertiesback to summary
public void saveServiceProperties(final String serviceName, StorageFactory sf, final Properties properties, final boolean replace) throws StandardException

Implements org.apache.derby.iapi.services.monitor.PersistentService.saveServiceProperties.

Exceptions
StandardException:
Properties cannot be saved.
saveServicePropertiesback to summary
public void saveServiceProperties(final String serviceName, final Properties properties) throws StandardException

Implements org.apache.derby.iapi.services.monitor.PersistentService.saveServiceProperties.

Save service.properties during backup

Parameters
serviceName:String

backup location of the service

properties:Properties

the properties to save

Exceptions
StandardException:
Properties cannot be saved.
serviceDirectoryCreateErrorback to summary
private StandardException serviceDirectoryCreateError(Exception t, String name)
vetServiceback to summary
private void vetService(StorageFactory storageFactory, String serviceName) throws StandardException

Verify that the service directory looks ok before objecting that the database already exists.

org.apache.derby.impl.services.monitor back to summary

pack-priv final Class StorageFactoryService.DirectoryList

extends Object
implements Enumeration
Class Inheritance
  • java.lang.Object
  • org.apache.derby.impl.services.monitor.StorageFactoryService.DirectoryList
All Implemented Interfaces
java.util.Enumeration

Field Summary

Modifier and TypeField and Description
private int
private String[]
private static final int
private int
private static final int
private StorageFile
private boolean

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public boolean
hasMoreElements()

Implements java.util.Enumeration.hasMoreElements.

Tests if this enumeration contains more elements.

public Object
nextElement()

Implements java.util.Enumeration.nextElement.

Returns the next element of this enumeration if this enumeration object has at least one more element to provide.

public final StorageFactoryService.DirectoryList
run()

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

actionCodeback to summary
private int actionCode
contentsback to summary
private String[] contents
HAS_MORE_ELEMENTS_ACTIONback to summary
private static final int HAS_MORE_ELEMENTS_ACTION
indexback to summary
private int index
INIT_ACTIONback to summary
private static final int INIT_ACTION
systemDirectoryback to summary
private StorageFile systemDirectory
validIndexback to summary
private boolean validIndex

Constructor Detail

DirectoryListback to summary
pack-priv DirectoryList()

Method Detail

hasMoreElementsback to summary
public boolean hasMoreElements()

Implements java.util.Enumeration.hasMoreElements.

Doc from java.util.Enumeration.hasMoreElements.

Tests if this enumeration contains more elements.

Returns:boolean

true if and only if this enumeration object contains at least one more element to provide; false otherwise.

nextElementback to summary
public Object nextElement() throws NoSuchElementException

Implements java.util.Enumeration.nextElement.

Doc from java.util.Enumeration.nextElement.

Returns the next element of this enumeration if this enumeration object has at least one more element to provide.

Returns:Object

the next element of this enumeration.

Exceptions
NoSuchElementException:
if no more elements exist.
runback to summary
public final StorageFactoryService.DirectoryList run()
org.apache.derby.impl.services.monitor back to summary

private Class StorageFactoryService.FileOperationHelper

extends Object
Class Inheritance
  • java.lang.Object
  • org.apache.derby.impl.services.monitor.StorageFactoryService.FileOperationHelper

Helper class for common file operations on the service properties files.

Introduced to take care of error reporting for common file operations carried out in StorageFactoryService.

Field Summary

Modifier and TypeField and Description
private String
operation

Name of the most recently performed operation.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
pack-priv boolean
delete(StorageFile file, boolean mustSucceed)

pack-priv boolean
exists(StorageFile file, boolean mustSucceed)

pack-priv boolean
renameTo(StorageFile from, StorageFile to, boolean mustSucceed)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

operationback to summary
private String operation

Name of the most recently performed operation.

Constructor Detail

FileOperationHelperback to summary
private FileOperationHelper()

Method Detail

deleteback to summary
pack-priv boolean delete(StorageFile file, boolean mustSucceed) throws StandardException
existsback to summary
pack-priv boolean exists(StorageFile file, boolean mustSucceed) throws StandardException
renameToback to summary
pack-priv boolean renameTo(StorageFile from, StorageFile to, boolean mustSucceed) throws StandardException