Class AbstractDAO

  • All Implemented Interfaces:
    com.helger.commons.log.IHasConditionalLogger, IAutoSaveAware, IDAO
    Direct Known Subclasses:
    AbstractSimpleDAO, AbstractWALDAO

    @ThreadSafe
    public abstract class AbstractDAO
    extends Object
    implements IDAO, com.helger.commons.log.IHasConditionalLogger
    Base implementation of IDAO
    Author:
    Philip Helger
    • Field Detail

      • DEFAULT_AUTO_SAVE_ENABLED

        public static final boolean DEFAULT_AUTO_SAVE_ENABLED
        By default auto-save is enabled
        See Also:
        Constant Field Values
      • FILENAME_EXTENSION_PREV

        public static final String FILENAME_EXTENSION_PREV
        The default extension for an old file that was not yet deleted. Mainly used in the WAL DAO
        See Also:
        Constant Field Values
      • FILENAME_EXTENSION_NEW

        public static final String FILENAME_EXTENSION_NEW
        The default extension for a file that is newly created. Mainly used in the WAL DAO
        See Also:
        Constant Field Values
      • RW_LOCK

        protected static final com.helger.commons.concurrent.SimpleReadWriteLock RW_LOCK
      • CONDLOG

        protected static final com.helger.commons.log.ConditionalLogger CONDLOG
      • m_aRWLock

        protected final com.helger.commons.concurrent.SimpleReadWriteLock m_aRWLock
    • Constructor Detail

      • AbstractDAO

        protected AbstractDAO()
    • Method Detail

      • isSilentMode

        public static boolean isSilentMode()
        Returns:
        true if logging is disabled, false if it is enabled.
        Since:
        9.2.0
      • setSilentMode

        public static boolean setSilentMode​(boolean bSilentMode)
        Enable or disable certain regular log messages.
        Parameters:
        bSilentMode - true to disable logging, false to enable logging
        Returns:
        The previous value of the silent mode.
        Since:
        9.2.0
      • exceptionHandlersRead

        @Nonnull
        @ReturnsMutableObject
        public static final com.helger.commons.callback.CallbackList<IDAOReadExceptionCallback> exceptionHandlersRead()
        Returns:
        The static mutable exception handler list that is invoked for read exceptions. Never null. The list applies to ALL DAOs since it is static.
      • exceptionHandlersWrite

        @Nonnull
        @ReturnsMutableObject
        public static final com.helger.commons.callback.CallbackList<IDAOWriteExceptionCallback> exceptionHandlersWrite()
        Returns:
        The static mutable exception handler list that is invoked for write exceptions. Never null. The list applies to ALL DAOs since it is static.
      • internalIsAutoSaveEnabled

        @MustBeLocked(READ)
        protected final boolean internalIsAutoSaveEnabled()
        Returns:
        true if auto save is enabled, false otherwise.
      • isAutoSaveEnabled

        public final boolean isAutoSaveEnabled()
        Specified by:
        isAutoSaveEnabled in interface IAutoSaveAware
        Returns:
        true if auto save is enabled, false otherwise.
      • internalSetPendingChanges

        @MustBeLocked(WRITE)
        public final void internalSetPendingChanges​(boolean bPendingChanges)
      • internalHasPendingChanges

        @MustBeLocked(READ)
        public final boolean internalHasPendingChanges()
        Returns:
        true if unsaved changes are present
      • hasPendingChanges

        public final boolean hasPendingChanges()
        Specified by:
        hasPendingChanges in interface IDAO
        Returns:
        true if unsaved changes are present
      • checkFileAccess

        protected static void checkFileAccess​(@Nonnull
                                              File aFile,
                                              @Nonnull
                                              IDAO.EMode eMode)
                                       throws DAOException
        Check the access to the passed file using the specified mode. If the access is not provided, a DAOException is thrown. If everything is good, this method returns without a comment.
        Parameters:
        aFile - The file to check. May not be null.
        eMode - The access mode. May not be null.
        Throws:
        DAOException - If the requested access mode cannot be provided.