DATATYPE - The data type to be serialized@ThreadSafe public abstract class AbstractWALDAO<DATATYPE extends Serializable> extends AbstractDAO
| Modifier and Type | Class and Description |
|---|---|
static class |
AbstractWALDAO.WALListener
The global write ahead logging manager that schedules future writings of a
DAO.
|
IDAO.EMode| Modifier and Type | Field and Description |
|---|---|
protected static com.helger.commons.lang.TimeValue |
DEFAULT_WAITING_TIME |
DEFAULT_AUTO_SAVE_ENABLED, m_aRWLock| Modifier | Constructor and Description |
|---|---|
protected |
AbstractWALDAO(Class<DATATYPE> aDataTypeClass,
IDAOIO aDAOIO,
IHasFilename aFilenameProvider) |
protected |
AbstractWALDAO(Class<DATATYPE> aDataTypeClass,
IDAOIO aDAOIO,
String sFilename) |
protected |
AbstractWALDAO(Class<DATATYPE> aDataTypeClass,
IHasFilename aFilenameProvider) |
protected |
AbstractWALDAO(Class<DATATYPE> aDataTypeClass,
String sFilename) |
| Modifier and Type | Method and Description |
|---|---|
protected void |
beforeWriteToFile(String sFilename,
File aFile)
Optional callback method that is invoked before the file handle gets
opened.
|
protected DATATYPE |
convertToNative(String sElement)
This method is used upon recovery to convert a stored object to its native
representation.
|
protected String |
convertToString(DATATYPE aModifiedElement) |
protected abstract com.helger.commons.microdom.IMicroDocument |
createWriteData()
Create the XML document that should be saved to the file.
|
IDAOIO |
getDAOIO() |
protected Class<DATATYPE> |
getDataTypeClass() |
IHasFilename |
getFilenameProvider() |
int |
getInitCount() |
String |
getLastFilename() |
org.joda.time.DateTime |
getLastInitDateTime() |
org.joda.time.DateTime |
getLastReadDateTime() |
org.joda.time.DateTime |
getLastWriteDateTime() |
int |
getReadCount() |
protected File |
getSafeFile(String sFilename,
IDAO.EMode eMode) |
com.helger.commons.lang.TimeValue |
getWaitingTime() |
int |
getWriteCount() |
protected com.helger.commons.xml.serialize.IXMLWriterSettings |
getXMLWriterSettings() |
protected void |
initialRead()
Call this method inside the constructor to read the file contents directly.
|
protected void |
markAsChanged(DATATYPE aModifiedElement,
EDAOActionType eActionType)
This method must be called every time something changed in the DAO.
|
protected void |
markAsChanged(List<DATATYPE> aModifiedElements,
EDAOActionType eActionType) |
protected void |
modifyWriteData(com.helger.commons.microdom.IMicroDocument aDoc)
Modify the created document by e.g. adding some comment or digital
signature or whatsoever.
|
protected void |
onFilenameChange(String sPreviousFilename,
String sNewFilename)
Called after a successful write of the file, if the filename is different
from the previous filename.
|
protected com.helger.commons.state.EChange |
onInit()
Custom initialization routine.
|
protected abstract com.helger.commons.state.EChange |
onRead(com.helger.commons.microdom.IMicroDocument aDoc)
Fill the internal structures with from the passed XML document.
|
protected abstract void |
onRecoveryCreate(DATATYPE aElement)
Called when a recovery is needed to create a new item.
|
protected abstract void |
onRecoveryDelete(DATATYPE aElement)
Called when a recovery is needed to delete an existing item.
|
protected abstract void |
onRecoveryUpdate(DATATYPE aElement)
Called when a recovery is needed to update an existing item.
|
protected void |
setWaitingTime(com.helger.commons.lang.TimeValue aWaitingTime)
Set the waiting time used before the file is effectively written.
|
String |
toString() |
protected static void |
triggerExceptionHandlersRead(Throwable t,
boolean bIsInitialization,
File aFile)
Trigger the registered custom exception handlers for read errors.
|
protected static void |
triggerExceptionHandlersWrite(Throwable t,
String sErrorFilename,
com.helger.commons.microdom.IMicroDocument aDoc)
Trigger the registered custom exception handlers for read errors.
|
void |
writeToFileOnPendingChanges()
In case there are pending changes write them to the file.
|
beginWithoutAutoSave, endWithoutAutoSave, getExceptionHandlersRead, getExceptionHandlersWrite, hasPendingChanges, internalHasPendingChanges, internalIsAutoSaveEnabled, internalSetPendingChanges, isAutoSaveEnabled, performWithoutAutoSave, performWithoutAutoSave, performWithoutAutoSave, performWithoutAutoSaveprotected static final com.helger.commons.lang.TimeValue DEFAULT_WAITING_TIME
protected AbstractWALDAO(@Nonnull Class<DATATYPE> aDataTypeClass, @Nullable String sFilename)
protected AbstractWALDAO(@Nonnull Class<DATATYPE> aDataTypeClass, @Nonnull IHasFilename aFilenameProvider)
protected AbstractWALDAO(@Nonnull Class<DATATYPE> aDataTypeClass, @Nonnull IDAOIO aDAOIO, @Nullable String sFilename)
@Nonnull public final IHasFilename getFilenameProvider()
null.@Nonnull @OverrideOnDemand protected com.helger.commons.state.EChange onInit()
EChange.CHANGED if something was modified inside this
method@Nonnull protected abstract com.helger.commons.state.EChange onRead(@Nonnull com.helger.commons.microdom.IMicroDocument aDoc)
aDoc - The XML document to read from. Never null.EChange.CHANGED if reading the data changed something in
the internal structures that requires a writing.@Nonnull protected final File getSafeFile(@Nonnull String sFilename, @Nonnull IDAO.EMode eMode) throws DAOException
DAOExceptionprotected static void triggerExceptionHandlersRead(@Nonnull Throwable t, boolean bIsInitialization, @Nullable File aFile)
t - Thrown exception. Never null.bIsInitialization - true if this happened during initialization of a new
file, false if it happened during regular reading.aFile - The file that was read. May be null for in-memory DAOs.@Nullable @OverrideOnDemand @IsLocked(value=WRITE) protected DATATYPE convertToNative(@Nonnull String sElement)
convertToString(Serializable) as well.sElement - The string representation to be converted. Never null.null, the recovery will fail with an exception!@IsLocked(value=WRITE) protected abstract void onRecoveryCreate(@Nonnull DATATYPE aElement)
aElement - The element to be created. Never null.@IsLocked(value=WRITE) protected abstract void onRecoveryUpdate(@Nonnull DATATYPE aElement)
aElement - The element to be updated. Never null.@IsLocked(value=WRITE) protected abstract void onRecoveryDelete(@Nonnull DATATYPE aElement)
aElement - The element to be deleted. Never null.protected final void initialRead()
throws DAOException
DAOException - in case initialization or reading failed!@OverrideOnDemand @MustBeLocked(value=WRITE) protected void onFilenameChange(@Nullable String sPreviousFilename, @Nonnull String sNewFilename)
sPreviousFilename - The previous filename. May be null.sNewFilename - The new filename. Never null.@Nonnull @MustBeLocked(value=WRITE) protected abstract com.helger.commons.microdom.IMicroDocument createWriteData()
null document to write to the file.@OverrideOnDemand @MustBeLocked(value=WRITE) protected void modifyWriteData(@Nonnull com.helger.commons.microdom.IMicroDocument aDoc)
aDoc - The created non-null document.@OverrideOnDemand @MustBeLocked(value=WRITE) protected void beforeWriteToFile(@Nonnull String sFilename, @Nonnull File aFile)
sFilename - The filename provided by the internal filename provider. Never
null.aFile - The resolved file. It is already consistency checked. Never
null.@Nonnull @OverrideOnDemand protected com.helger.commons.xml.serialize.IXMLWriterSettings getXMLWriterSettings()
IXMLWriterSettings to be used to serialize the data.@Nullable public final String getLastFilename()
null if
no wrote action was performed yet.protected static void triggerExceptionHandlersWrite(@Nonnull Throwable t, @Nonnull String sErrorFilename, @Nullable com.helger.commons.microdom.IMicroDocument aDoc)
t - Thrown exception. Never null.sErrorFilename - The filename tried to write to. Never null.aDoc - The XML content that should be written. May be null if
the error occurred in XML creation.@Nonnull @OverrideOnDemand protected String convertToString(@Nonnull DATATYPE aModifiedElement)
@MustBeLocked(value=WRITE) protected final void markAsChanged(@Nonnull DATATYPE aModifiedElement, @Nonnull EDAOActionType eActionType)
@Nonnull public com.helger.commons.lang.TimeValue getWaitingTime()
null. Default value is 10 seconds.protected void setWaitingTime(@Nonnull com.helger.commons.lang.TimeValue aWaitingTime)
aWaitingTime - The waiting time to be used. May not be null.@MustBeLocked(value=WRITE) protected final void markAsChanged(@Nonnull List<DATATYPE> aModifiedElements, @Nonnull EDAOActionType eActionType)
public final void writeToFileOnPendingChanges()
@Nonnegative public int getInitCount()
@Nullable public final org.joda.time.DateTime getLastInitDateTime()
null if it wasn't read before. Usually this field is
not persistent and only is valid until the application ends.@Nonnegative public int getReadCount()
@Nullable public final org.joda.time.DateTime getLastReadDateTime()
null if it wasn't read before. Usually this field is
not persistent and only is valid until the application ends.@Nonnegative public int getWriteCount()
@Nullable public final org.joda.time.DateTime getLastWriteDateTime()
null if it wasn't written before. Usually this field
is not persistent and only is valid until the application ends.public String toString()
toString in class AbstractDAOCopyright © 2014–2015 Philip Helger. All rights reserved.