Class BundleDbPersistenceManager

    • Field Detail

      • SM_BINARY_KEYS

        public static final int SM_BINARY_KEYS
        storage model modifier: binary keys
        See Also:
        Constant Field Values
      • SM_LONGLONG_KEYS

        public static final int SM_LONGLONG_KEYS
        storage model modifier: longlong keys
        See Also:
        Constant Field Values
      • initialized

        protected boolean initialized
        flag indicating if this manager was initialized
      • driver

        protected String driver
        the jdbc driver name
      • url

        protected String url
        the jdbc url string
      • user

        protected String user
        the jdbc user
      • password

        protected String password
        the jdbc password
      • databaseType

        protected String databaseType
        the database type
      • dataSourceName

        protected String dataSourceName
        the logical name of the data source to use
      • schemaObjectPrefix

        protected String schemaObjectPrefix
        the prefix for the database objects
      • consistencyCheck

        protected boolean consistencyCheck
        flag indicating if a consistency check should be issued during startup
      • consistencyFix

        protected boolean consistencyFix
        flag indicating if the consistency check should attempt to fix issues
      • INITIAL_BUFFER_SIZE

        protected static final int INITIAL_BUFFER_SIZE
        initial size of buffer used to serialize objects
        See Also:
        Constant Field Values
      • externalBLOBs

        protected boolean externalBLOBs
        indicates if uses (filesystem) blob store
      • blockOnConnectionLoss

        protected boolean blockOnConnectionLoss
        indicates whether to block if the database connection is lost
      • bundleInsertSQL

        protected String bundleInsertSQL
      • bundleUpdateSQL

        protected String bundleUpdateSQL
      • bundleSelectSQL

        protected String bundleSelectSQL
      • bundleDeleteSQL

        protected String bundleDeleteSQL
      • bundleSelectAllIdsFromSQL

        protected String bundleSelectAllIdsFromSQL
      • bundleSelectAllIdsSQL

        protected String bundleSelectAllIdsSQL
      • bundleSelectAllBundlesFromSQL

        protected String bundleSelectAllBundlesFromSQL
      • bundleSelectAllBundlesSQL

        protected String bundleSelectAllBundlesSQL
      • nodeReferenceInsertSQL

        protected String nodeReferenceInsertSQL
      • nodeReferenceUpdateSQL

        protected String nodeReferenceUpdateSQL
      • nodeReferenceSelectSQL

        protected String nodeReferenceSelectSQL
      • nodeReferenceDeleteSQL

        protected String nodeReferenceDeleteSQL
      • errorHandling

        protected ErrorHandling errorHandling
        flag for error handling
    • Constructor Detail

      • BundleDbPersistenceManager

        public BundleDbPersistenceManager()
    • Method Detail

      • getUrl

        public String getUrl()
        Returns the configured JDBC connection url.
        Returns:
        the configured JDBC connection url.
      • setUrl

        public void setUrl​(String url)
        Sets the JDBC connection URL. The connection can be created using a JNDI Data Source as well. To do that, the driver class name must reference a javax.naming.Context class (for example javax.naming.InitialContext), and the URL must be the JNDI URL (for example java:comp/env/jdbc/Test).
        Parameters:
        url - the url to set.
      • getUser

        public String getUser()
        Returns the configured user that is used to establish JDBC connections.
        Returns:
        the JDBC user.
      • setUser

        public void setUser​(String user)
        Sets the user name that will be used to establish JDBC connections.
        Parameters:
        user - the user name.
      • getPassword

        public String getPassword()
        Returns the configured password that is used to establish JDBC connections.
        Returns:
        the password.
      • setPassword

        public void setPassword​(String password)
        Sets the password that will be used to establish JDBC connections.
        Parameters:
        password - the password for the connection
      • getDriver

        public String getDriver()
        Returns the class name of the JDBC driver.
        Returns:
        the class name of the JDBC driver.
      • setDriver

        public void setDriver​(String driver)
        Sets the class name of the JDBC driver. The driver class will be loaded during init in order to assure the existence. If no driver is specified, the default driver for the database is used.
        Parameters:
        driver - the class name of the driver
      • getSchemaObjectPrefix

        public String getSchemaObjectPrefix()
        Returns the configured schema object prefix.
        Returns:
        the configured schema object prefix.
      • setSchemaObjectPrefix

        public void setSchemaObjectPrefix​(String schemaObjectPrefix)
        Sets the schema object prefix. This string is used to prefix all schema objects, like tables and indexes. this is useful, if several persistence managers use the same database.
        Parameters:
        schemaObjectPrefix - the prefix for schema objects.
      • getSchema

        @Deprecated
        public String getSchema()
        Deprecated.
        This method is deprecated; getDatabaseType() should be used instead.
        Returns the configured database type name.
        Returns:
        the database type name.
      • getDatabaseType

        public String getDatabaseType()
        Returns the configured database type name.
        Returns:
        the database type name.
      • setSchema

        @Deprecated
        public void setSchema​(String databaseType)
        Deprecated.
        This method is deprecated; setDatabaseType(java.lang.String) should be used instead.
        Sets the database type. This identifier is used to load and execute the respective .ddl resource in order to create the required schema objects.
        Parameters:
        databaseType - database type name
      • setDatabaseType

        public void setDatabaseType​(String databaseType)
        Sets the database type. This identifier is used to load and execute the respective .ddl resource in order to create the required schema objects.
        Parameters:
        databaseType - database type name
      • getDataSourceName

        public String getDataSourceName()
      • setDataSourceName

        public void setDataSourceName​(String dataSourceName)
      • isExternalBLOBs

        public boolean isExternalBLOBs()
        Returns if uses external (filesystem) blob store.
        Returns:
        if uses external (filesystem) blob store.
      • setExternalBLOBs

        public void setExternalBLOBs​(boolean externalBLOBs)
        Sets the flag for external (filesystem) blob store usage.
        Parameters:
        externalBLOBs - a value of "true" indicates that an external blob store is to be used.
      • getConsistencyCheck

        public String getConsistencyCheck()
        Checks if consistency check is enabled.
        Returns:
        true if consistency check is enabled.
      • setConsistencyCheck

        public void setConsistencyCheck​(String consistencyCheck)
        Defines if a consistency check is to be performed on initialization.
        Parameters:
        consistencyCheck - the consistency check flag.
      • getConsistencyFix

        public String getConsistencyFix()
        Checks if consistency fix is enabled.
        Returns:
        true if consistency fix is enabled.
      • setConsistencyFix

        public void setConsistencyFix​(String consistencyFix)
        Defines if the consistency check should attempt to fix issues that it finds.
        Parameters:
        consistencyFix - the consistency fix flag.
      • getMinBlobSize

        public String getMinBlobSize()
        Returns the minimum blob size in bytes.
        Returns:
        the minimum blob size in bytes.
      • setMinBlobSize

        public void setMinBlobSize​(String minBlobSize)
        Sets the minimum blob size. This size defines the threshold of which size a property is included in the bundle or is stored in the blob store.
        Parameters:
        minBlobSize - the minimum blob size in bytes.
      • setErrorHandling

        public void setErrorHandling​(String errorHandling)
        Sets the error handling behaviour of this manager. See ErrorHandling for details about the flags.
        Parameters:
        errorHandling - the error handling flags
      • getErrorHandling

        public String getErrorHandling()
        Returns the error handling configuration of this manager
        Returns:
        the error handling configuration of this manager
      • setBlockOnConnectionLoss

        public void setBlockOnConnectionLoss​(String block)
      • getBlockOnConnectionLoss

        public String getBlockOnConnectionLoss()
      • useDbBlobStore

        public boolean useDbBlobStore()
        Returns true if the blobs are stored in the DB.
        Returns:
        true if the blobs are stored in the DB.
      • useLocalFsBlobStore

        public boolean useLocalFsBlobStore()
        Returns true if the blobs are stored in the local fs.
        Returns:
        true if the blobs are stored in the local fs.
      • isSchemaCheckEnabled

        public final boolean isSchemaCheckEnabled()
        Returns:
        whether the schema check is enabled
      • setSchemaCheckEnabled

        public final void setSchemaCheckEnabled​(boolean enabled)
        Parameters:
        enabled - set whether the schema check is enabled
      • store

        public void store​(ChangeLog changeLog)
                   throws ItemStateException
        Right now, this iterates over all items in the changelog and calls the individual methods that handle single item states or node references objects. Properly implemented, this method should ensure that changes are either written completely to the underlying persistence layer, or not at all. Atomically saves the given set of changes. Basically wraps a JDBC transaction around super.store(). FIXME: the retry logic is almost a duplicate of ConnectionHelper.RetryManager.
        Specified by:
        store in interface PersistenceManager
        Overrides:
        store in class AbstractBundlePersistenceManager
        Parameters:
        changeLog - change log containing states that were changed
        Throws:
        ItemStateException - if the changes could not be saved
      • init

        public void init​(PMContext context)
                  throws Exception
        Initializes the persistence manager. The persistence manager is permanently bound to the given context, and any required external resources are acquired.

        An appropriate exception is thrown if the persistence manager initialization fails for whatever reason. In this case the state of the persistence manager is undefined and the instance should be discarded. Initializes the internal structures of this abstract persistence manager.

        Specified by:
        init in interface PersistenceManager
        Overrides:
        init in class AbstractBundlePersistenceManager
        Parameters:
        context - persistence manager context
        Throws:
        Exception - if the persistence manager initialization failed
      • createDbNameIndex

        protected DbNameIndex createDbNameIndex()
                                         throws SQLException
        Returns a new instance of a DbNameIndex.
        Returns:
        a new instance of a DbNameIndex.
        Throws:
        SQLException - if an SQL error occurs.
      • getStorageModel

        public int getStorageModel()
        returns the storage model
        Returns:
        the storage model
      • close

        public void close()
                   throws Exception
        Closes the persistence manager. The consistency of the persistent storage is guaranteed and all acquired resources are released. It is an error to invoke any methods on a closed persistence manager, and implementations are free to enforce this constraint by throwing IllegalStateExceptions in such cases.

        An appropriate exception is thrown if the persistence manager could not be closed properly. In this case the state of the persistence manager is undefined and the instance should be discarded. Closes the persistence manager, release acquired resources.

        Specified by:
        close in interface PersistenceManager
        Overrides:
        close in class AbstractBundlePersistenceManager
        Throws:
        Exception - if the persistence manager failed to close properly
      • getKey

        protected Object[] getKey​(NodeId id)
        Constructs a parameter list for a PreparedStatement for the given node identifier.
        Parameters:
        id - the node id
        Returns:
        a list of Objects
      • createParams

        protected Object[] createParams​(NodeId id,
                                        Object p,
                                        boolean before)
        Creates a parameter array for an SQL statement that needs (i) a node identifier, and (2) another parameter.
        Parameters:
        id - the node id
        p - the other parameter
        before - whether the other parameter should be before the uuid parameter
        Returns:
        an Object array that represents the parameters
      • getAllNodeIds

        public List<NodeId> getAllNodeIds​(NodeId bigger,
                                          int maxCount)
                                   throws ItemStateException,
                                          RepositoryException
        Get all node ids. A typical application will call this method multiple times, where 'after' is the last row read previously. The maxCount parameter defines the maximum number of node ids returned, 0 meaning no limit. The order of the node ids is specific for the given persistent manager. Items that are added concurrently may not be included.
        Specified by:
        getAllNodeIds in interface IterablePersistenceManager
        Parameters:
        bigger - the lower limit, or null for no limit.
        maxCount - the maximum number of node ids to return, or 0 for no limit.
        Returns:
        a list of all node ids.
        Throws:
        ItemStateException - if an error while loading occurs.
        RepositoryException - if a repository exception occurs.
      • getAllNodeInfos

        public Map<NodeId,​NodeInfo> getAllNodeInfos​(NodeId bigger,
                                                          int maxCount)
                                                   throws ItemStateException
        Get all NodeInfos. A typical application will call this method multiple time, where 'after' is the last row read previously. The maxCount parameter defines the maximum number of node ids returned, 0 meaning no limit. The order of the node ids is specific for the given persistence manager. Items that are added concurrently may not be included.
        Specified by:
        getAllNodeInfos in interface IterablePersistenceManager
        Overrides:
        getAllNodeInfos in class AbstractBundlePersistenceManager
        Parameters:
        bigger - the lower limit, or null for no limit.
        maxCount - the maximum number of node infos to return, or 0 for no limit.
        Returns:
        a list of all node infos.
        Throws:
        ItemStateException - if an error while loading occurs.
      • store

        public void store​(NodeReferences refs)
                   throws ItemStateException
        Stores a node references to the underlying system. This method uses shared PreparedStatements, which must be used strictly sequentially. Because this method synchronizes on the persistence manager instance, there is no need to synchronize on the shared statement. If the method would not be synchronized, the shared statement must be synchronized.
        Specified by:
        store in class AbstractBundlePersistenceManager
        Parameters:
        refs - the node references to store.
        Throws:
        ItemStateException - if an error while storing occurs.
      • buildSQLStatements

        protected void buildSQLStatements()
        Initializes the SQL strings.