Class StorageFactoryService

  • All Implemented Interfaces:
    PersistentService

    final class StorageFactoryService
    extends java.lang.Object
    implements PersistentService
    This class implements the PersistentService interface using a StorageFactory class. It handles all subSubProtocols except for cache.
    • Field Detail

      • SERVICE_PROPERTIES_EOF_TOKEN

        private static final java.lang.String SERVICE_PROPERTIES_EOF_TOKEN
        Marker printed as the last line of the service properties file.
        See Also:
        Constant Field Values
      • home

        private java.lang.String home
      • canonicalHome

        private java.lang.String canonicalHome
      • subSubProtocol

        private final java.lang.String subSubProtocol
      • storageFactoryClass

        private final java.lang.Class<?> storageFactoryClass
      • separatorChar

        private char separatorChar
    • Constructor Detail

      • StorageFactoryService

        StorageFactoryService​(java.lang.String subSubProtocol,
                              java.lang.Class storageFactoryClass)
                       throws StandardException
        Throws:
        StandardException
    • Method Detail

      • hasStorageFactory

        public boolean hasStorageFactory()
        Specified by:
        hasStorageFactory in interface PersistentService
        Returns:
        true if the PersistentService has a StorageFactory, false if not.
      • getStorageFactoryInstance

        public StorageFactory getStorageFactoryInstance​(boolean useHome,
                                                        java.lang.String databaseName,
                                                        java.lang.String tempDirName,
                                                        java.lang.String uniqueName)
                                                 throws StandardException,
                                                        java.io.IOException
        Get an initialized StorageFactoryInstance
        Specified by:
        getStorageFactoryInstance in interface PersistentService
        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:
        java.io.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,
                                                             java.lang.String databaseName,
                                                             java.lang.String tempDirName,
                                                             java.lang.String uniqueName)
                                                      throws java.lang.InstantiationException,
                                                             java.lang.IllegalAccessException,
                                                             java.io.IOException,
                                                             java.lang.NoSuchMethodException,
                                                             java.lang.reflect.InvocationTargetException
        Throws:
        java.lang.InstantiationException
        java.lang.IllegalAccessException
        java.io.IOException
        java.lang.NoSuchMethodException
        java.lang.reflect.InvocationTargetException
      • getServiceProperties

        public java.util.Properties getServiceProperties​(java.lang.String serviceName,
                                                         java.util.Properties defaultProperties)
                                                  throws StandardException
        Open the service properties in the directory identified by the service name.
        Specified by:
        getServiceProperties in interface PersistentService
        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​(java.lang.String serviceName,
                                          java.util.Properties properties)
                                   throws StandardException
        Save service.properties during backup
        Specified by:
        saveServiceProperties in interface PersistentService
        Parameters:
        serviceName - backup location of the service
        properties - 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 service
        spf - the service properties file
        Throws:
        StandardException - if a file operation on a service properties file fails
      • recreateServiceRoot

        protected java.lang.String recreateServiceRoot​(java.lang.String serviceName,
                                                       java.util.Properties properties)
                                                throws StandardException
        Throws:
        StandardException
      • vetService

        private void vetService​(StorageFactory storageFactory,
                                java.lang.String serviceName)
                         throws StandardException
        Verify that the service directory looks ok before objecting that the database already exists.
        Throws:
        StandardException
      • getDirectoryPath

        private java.lang.String getDirectoryPath​(java.lang.String name)
      • getCanonicalServiceName

        public java.lang.String getCanonicalServiceName​(java.lang.String name)
                                                 throws StandardException
        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 interface PersistentService
        Throws:
        StandardException - if an error happens when converting the name (name probably invalid)
      • getUserServiceName

        public java.lang.String getUserServiceName​(java.lang.String serviceName)
        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 interface PersistentService
      • isSameService

        public boolean isSameService​(java.lang.String serviceName1,
                                     java.lang.String serviceName2)
        Specified by:
        isSameService in interface PersistentService
      • fileExists

        private final boolean fileExists​(java.io.File file)
        Checks if the specified file exists.
        Parameters:
        file - the file to check
        Returns:
        true if the file exists, false if not.
        Throws:
        java.lang.SecurityException - if the required privileges are missing
      • getStorageFactoryClass

        public java.lang.Class getStorageFactoryClass()
        Get the StorageFactory implementation for this PersistentService
        Returns:
        the StorageFactory class.
      • getProtocolLeadIn

        private java.lang.String 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

        private static ModuleFactory getMonitor()
        Privileged Monitor lookup. Must be private so that user code can't call this entry point.
      • getMostAccuratePath

        private static java.lang.String getMostAccuratePath​(StorageFile file)
        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 or File.getPath.