Package com.helger.dao
Class AbstractDAO
- java.lang.Object
-
- com.helger.dao.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 ofIDAO- Author:
- Philip Helger
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface com.helger.dao.IDAO
IDAO.EMode
-
-
Field Summary
Fields Modifier and Type Field Description protected static com.helger.commons.log.ConditionalLoggerCONDLOGstatic booleanDEFAULT_AUTO_SAVE_ENABLEDBy default auto-save is enabledstatic StringFILENAME_EXTENSION_NEWThe default extension for a file that is newly created.static StringFILENAME_EXTENSION_PREVThe default extension for an old file that was not yet deleted.protected com.helger.commons.concurrent.SimpleReadWriteLockm_aRWLockprotected static com.helger.commons.concurrent.SimpleReadWriteLockRW_LOCK
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractDAO()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidbeginWithoutAutoSave()Start doing something without auto save.protected static voidcheckFileAccess(File aFile, IDAO.EMode eMode)Check the access to the passed file using the specified mode.voidendWithoutAutoSave()End doing something without auto save.static com.helger.commons.callback.CallbackList<IDAOReadExceptionCallback>exceptionHandlersRead()static com.helger.commons.callback.CallbackList<IDAOWriteExceptionCallback>exceptionHandlersWrite()booleanhasPendingChanges()booleaninternalHasPendingChanges()protected booleaninternalIsAutoSaveEnabled()voidinternalSetPendingChanges(boolean bPendingChanges)booleanisAutoSaveEnabled()static booleanisSilentMode()static booleansetSilentMode(boolean bSilentMode)Enable or disable certain regular log messages.StringtoString()-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.helger.dao.IAutoSaveAware
performWithoutAutoSave, performWithoutAutoSave, performWithoutAutoSaveThrowing, performWithoutAutoSaveThrowing
-
Methods inherited from interface com.helger.dao.IDAO
getInitCount, getLastInitDateTime, getLastReadDateTime, getLastWriteDateTime, getReadCount, getWriteCount, isReloadable, reload, writeToFileOnPendingChanges
-
-
-
-
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
-
-
Method Detail
-
isSilentMode
public static boolean isSilentMode()
- Returns:
trueif logging is disabled,falseif it is enabled.- Since:
- 9.2.0
-
setSilentMode
public static boolean setSilentMode(boolean bSilentMode)
Enable or disable certain regular log messages.- Parameters:
bSilentMode-trueto disable logging,falseto 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:
trueif auto save is enabled,falseotherwise.
-
isAutoSaveEnabled
public final boolean isAutoSaveEnabled()
- Specified by:
isAutoSaveEnabledin interfaceIAutoSaveAware- Returns:
trueif auto save is enabled,falseotherwise.
-
internalSetPendingChanges
@MustBeLocked(WRITE) public final void internalSetPendingChanges(boolean bPendingChanges)
-
internalHasPendingChanges
@MustBeLocked(READ) public final boolean internalHasPendingChanges()
- Returns:
trueif unsaved changes are present
-
hasPendingChanges
public final boolean hasPendingChanges()
- Specified by:
hasPendingChangesin interfaceIDAO- Returns:
trueif unsaved changes are present
-
beginWithoutAutoSave
public final void beginWithoutAutoSave()
Description copied from interface:IAutoSaveAwareStart doing something without auto save.- Specified by:
beginWithoutAutoSavein interfaceIAutoSaveAware
-
endWithoutAutoSave
public final void endWithoutAutoSave()
Description copied from interface:IAutoSaveAwareEnd doing something without auto save. It must be ensure that each call toIAutoSaveAware.beginWithoutAutoSave()is always correctly ended with a call to this method.- Specified by:
endWithoutAutoSavein interfaceIAutoSaveAware
-
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, aDAOExceptionis thrown. If everything is good, this method returns without a comment.- Parameters:
aFile- The file to check. May not benull.eMode- The access mode. May not benull.- Throws:
DAOException- If the requested access mode cannot be provided.
-
-