@ThreadSafe public abstract class AbstractSimpleDAO extends AbstractDAO
IDAO.EModeDEFAULT_AUTO_SAVE_ENABLED, m_aRWLock| Modifier | Constructor and Description |
|---|---|
protected |
AbstractSimpleDAO(IDAOIO aDAOIO,
IHasFilename aFilenameProvider) |
protected |
AbstractSimpleDAO(IDAOIO aDAOIO,
String sFilename) |
protected |
AbstractSimpleDAO(IHasFilename aFilenameProvider) |
protected |
AbstractSimpleDAO(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 abstract com.helger.xml.microdom.IMicroDocument |
createWriteData()
Create the XML document that should be saved to the file.
|
IDAOIO |
getDAOIO() |
IHasFilename |
getFilenameProvider() |
int |
getInitCount() |
String |
getLastFilename() |
LocalDateTime |
getLastInitDateTime() |
LocalDateTime |
getLastReadDateTime() |
LocalDateTime |
getLastWriteDateTime() |
int |
getReadCount() |
protected File |
getSafeFile(String sFilename,
IDAO.EMode eMode) |
int |
getWriteCount() |
protected com.helger.xml.serialize.write.IXMLWriterSettings |
getXMLWriterSettings() |
protected void |
initialRead()
Call this method inside the constructor to read the file contents directly.
|
protected void |
markAsChanged()
This method must be called every time something changed in the DAO.
|
protected void |
modifyWriteData(com.helger.xml.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.xml.microdom.IMicroDocument aDoc)
Fill the internal structures with from the passed XML document.
|
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.xml.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, isDebugLogging, performWithoutAutoSave, performWithoutAutoSave, performWithoutAutoSaveThrowing, performWithoutAutoSaveThrowingprotected AbstractSimpleDAO(@Nonnull IHasFilename aFilenameProvider)
protected AbstractSimpleDAO(@Nonnull IDAOIO aDAOIO, @Nonnull IHasFilename aFilenameProvider)
@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 @MustBeLocked(value=WRITE) protected abstract com.helger.commons.state.EChange onRead(@Nonnull com.helger.xml.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.@MustBeLocked(value=WRITE)
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.xml.microdom.IMicroDocument createWriteData()
null document to write to the file.@OverrideOnDemand @MustBeLocked(value=WRITE) protected void modifyWriteData(@Nonnull com.helger.xml.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.xml.serialize.write.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.xml.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.@MustBeLocked(value=WRITE) protected final void markAsChanged()
public final void writeToFileOnPendingChanges()
@Nonnegative public int getInitCount()
@Nullable public final LocalDateTime 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 LocalDateTime 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 LocalDateTime 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–2017 Philip Helger. All rights reserved.