INTERFACETYPE - Interface type to be handledIMPLTYPE - Implementation type to be handled@ThreadSafe public abstract class AbstractMapBasedWALDAO<INTERFACETYPE extends com.helger.commons.id.IHasID<String> & Serializable,IMPLTYPE extends INTERFACETYPE> extends AbstractWALDAO<IMPLTYPE> implements IMapBasedDAO<INTERFACETYPE>
ICommonsMap for data
storage.| Modifier and Type | Class and Description |
|---|---|
static class |
AbstractMapBasedWALDAO.InitSettings<IMPLTYPE>
Extensible constructor parameter builder.
|
IDAO.EMode| Modifier and Type | Field and Description |
|---|---|
protected static String |
ELEMENT_ITEM |
protected static String |
ELEMENT_ROOT |
DEFAULT_WAITING_TIME, WAL_XWS, WRITE_XWSDEFAULT_AUTO_SAVE_ENABLED, m_aRWLock| Constructor and Description |
|---|
AbstractMapBasedWALDAO(Class<IMPLTYPE> aImplClass,
String sFilename)
Default constructor.
|
AbstractMapBasedWALDAO(Class<IMPLTYPE> aImplClass,
String sFilename,
AbstractMapBasedWALDAO.InitSettings<IMPLTYPE> aInitSettings) |
| Modifier and Type | Method and Description |
|---|---|
boolean |
containsAllIDs(Iterable<String> aIDs) |
boolean |
containsAny() |
boolean |
containsAny(Predicate<? super INTERFACETYPE> aFilter) |
boolean |
containsNone() |
boolean |
containsNone(Predicate<? super INTERFACETYPE> aFilter) |
boolean |
containsOnly(Predicate<? super INTERFACETYPE> aFilter) |
boolean |
containsWithID(String sID) |
protected com.helger.xml.microdom.IMicroDocument |
createWriteData()
Create the XML document that should be saved to the file.
|
void |
findAll(Predicate<? super INTERFACETYPE> aFilter,
Consumer<? super INTERFACETYPE> aConsumer) |
<RETTYPE> void |
findAllMapped(Predicate<? super INTERFACETYPE> aFilter,
Function<? super INTERFACETYPE,? extends RETTYPE> aMapper,
Consumer<? super RETTYPE> aConsumer) |
INTERFACETYPE |
findFirst(Predicate<? super INTERFACETYPE> aFilter) |
<RETTYPE> RETTYPE |
findFirstMapped(Predicate<? super INTERFACETYPE> aFilter,
Function<? super INTERFACETYPE,? extends RETTYPE> aMapper) |
void |
forEach(BiConsumer<? super String,? super INTERFACETYPE> aConsumer) |
void |
forEach(BiPredicate<? super String,? super INTERFACETYPE> aFilter,
BiConsumer<? super String,? super INTERFACETYPE> aConsumer) |
void |
forEachKey(Consumer<? super String> aConsumer) |
void |
forEachKey(Predicate<? super String> aFilter,
Consumer<? super String> aConsumer) |
void |
forEachValue(Consumer<? super INTERFACETYPE> aConsumer) |
void |
forEachValue(Predicate<? super INTERFACETYPE> aFilter,
Consumer<? super INTERFACETYPE> aConsumer) |
com.helger.commons.collection.ext.ICommonsList<INTERFACETYPE> |
getAll() |
com.helger.commons.collection.ext.ICommonsList<INTERFACETYPE> |
getAll(Predicate<? super INTERFACETYPE> aFilter) |
com.helger.commons.collection.ext.ICommonsSet<String> |
getAllIDs() |
<RETTYPE> com.helger.commons.collection.ext.ICommonsList<RETTYPE> |
getAllMapped(Predicate<? super INTERFACETYPE> aFilter,
Function<? super INTERFACETYPE,? extends RETTYPE> aMapper) |
protected Collection<IMPLTYPE> |
getAllSortedByKey() |
protected INTERFACETYPE |
getAtIndex(int nIndex)
Get the item at the specified index.
|
com.helger.commons.callback.CallbackList<IDAOChangeCallback<INTERFACETYPE>> |
getCallbacks() |
int |
getCount() |
int |
getCount(Predicate<? super INTERFACETYPE> aFilter) |
<T> com.helger.commons.collection.ext.ICommonsList<T> |
getNone() |
protected IMPLTYPE |
getOfID(String sID) |
protected IMPLTYPE |
getOfIDLocked(String sID) |
protected IMPLTYPE |
internalCreateItem(IMPLTYPE aNewItem)
Add an item including invoking the callback
|
protected IMPLTYPE |
internalDeleteItem(String sID)
Delete the item by removing it from the map.
|
protected Iterable<IMPLTYPE> |
internalDirectGetAll() |
protected void |
internalForEachValue(Consumer<? super IMPLTYPE> aConsumer) |
protected void |
internalForEachValue(Predicate<? super IMPLTYPE> aFilter,
Consumer<? super IMPLTYPE> aConsumer) |
protected com.helger.commons.collection.ext.ICommonsList<IMPLTYPE> |
internalGetAll(Predicate<? super IMPLTYPE> aFilter) |
protected void |
internalMarkItemDeleted(IMPLTYPE aItem)
Mark an item as "deleted" without actually deleting it from the map.
|
protected void |
internalMarkItemUndeleted(IMPLTYPE aItem)
Mark an item as "no longer deleted" without actually adding it to the map.
|
protected com.helger.commons.state.EChange |
internalRemoveAllItemsNoCallback()
Remove all items without triggering any callback.
|
protected void |
internalUpdateItem(IMPLTYPE aItem)
Update and existing item including invoking the callback
|
protected void |
markAsChanged(IMPLTYPE aModifiedElement,
EDAOActionType eActionType)
Deprecated.
|
protected com.helger.commons.state.EChange |
onRead(com.helger.xml.microdom.IMicroDocument aDoc)
Fill the internal structures with from the passed XML document.
|
protected void |
onRecoveryCreate(IMPLTYPE aItem)
Called when a recovery is needed to create a new item.
|
protected void |
onRecoveryDelete(IMPLTYPE aItem)
Called when a recovery is needed to delete an existing item.
|
protected void |
onRecoveryUpdate(IMPLTYPE aItem)
Called when a recovery is needed to update an existing item.
|
String |
toString() |
convertNativeToWALString, convertWALStringToNative, getDAOIO, getDataTypeClass, getFilenameProvider, getInitCount, getLastFilename, getLastInitDateTime, getLastReadDateTime, getLastWriteDateTime, getReadCount, getSafeFile, getWaitingTime, getWALXMLWriterSettings, getWriteCount, getXMLWriterSettings, initialRead, markAsChanged, modifyWriteData, onBetweenReadAndWAL, onFilenameChange, onInit, setWaitingTime, triggerExceptionHandlersRead, triggerExceptionHandlersWrite, writeToFileOnPendingChangesbeginWithoutAutoSave, endWithoutAutoSave, getExceptionHandlersRead, getExceptionHandlersWrite, hasPendingChanges, internalHasPendingChanges, internalIsAutoSaveEnabled, internalSetPendingChanges, isAutoSaveEnabled, isDebugLogging, performWithoutAutoSave, performWithoutAutoSave, performWithoutAutoSaveThrowing, performWithoutAutoSaveThrowingprotected static final String ELEMENT_ROOT
protected static final String ELEMENT_ITEM
public AbstractMapBasedWALDAO(@Nonnull Class<IMPLTYPE> aImplClass, @Nullable String sFilename) throws DAOException
aImplClass - Implementation class. May not be null.sFilename - The filename to read and write.DAOException - If reading and reading failspublic AbstractMapBasedWALDAO(@Nonnull Class<IMPLTYPE> aImplClass, @Nullable String sFilename, @Nonnull AbstractMapBasedWALDAO.InitSettings<IMPLTYPE> aInitSettings) throws DAOException
DAOExceptionprotected void onRecoveryCreate(@Nonnull IMPLTYPE aItem)
AbstractWALDAOonRecoveryCreate in class AbstractWALDAO<IMPLTYPE extends INTERFACETYPE>aItem - The element to be created. Never null.protected void onRecoveryUpdate(@Nonnull IMPLTYPE aItem)
AbstractWALDAOonRecoveryUpdate in class AbstractWALDAO<IMPLTYPE extends INTERFACETYPE>aItem - The element to be updated. Never null.protected void onRecoveryDelete(@Nonnull IMPLTYPE aItem)
AbstractWALDAOonRecoveryDelete in class AbstractWALDAO<IMPLTYPE extends INTERFACETYPE>aItem - The element to be deleted. Never null.@Nonnull protected com.helger.commons.state.EChange onRead(@Nonnull com.helger.xml.microdom.IMicroDocument aDoc)
AbstractWALDAOonRead in class AbstractWALDAO<IMPLTYPE extends INTERFACETYPE>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.@MustBeLocked(value=READ) @CodingStyleguideUnaware protected final Collection<IMPLTYPE> getAllSortedByKey()
@Nonnull protected com.helger.xml.microdom.IMicroDocument createWriteData()
AbstractWALDAOcreateWriteData in class AbstractWALDAO<IMPLTYPE extends INTERFACETYPE>null document to write to the file.@Nonnull @ReturnsMutableObject(value="design") public com.helger.commons.callback.CallbackList<IDAOChangeCallback<INTERFACETYPE>> getCallbacks()
@MustBeLocked(value=WRITE) @OverridingMethodsMustInvokeSuper @Deprecated @DevelopersNote(value="Avoid that this method is overridden!") protected final void markAsChanged(@Nonnull IMPLTYPE aModifiedElement, @Nonnull EDAOActionType eActionType)
AbstractWALDAOmarkAsChanged in class AbstractWALDAO<IMPLTYPE extends INTERFACETYPE>aModifiedElement - The modified data element. May not be null.eActionType - The action that was performed. May not be null.@MustBeLocked(value=WRITE) protected final IMPLTYPE internalCreateItem(@Nonnull IMPLTYPE aNewItem)
aNewItem - The item to be added. May not be null.IllegalArgumentException - If an item with the same ID is already contained@MustBeLocked(value=WRITE) protected final void internalUpdateItem(@Nonnull IMPLTYPE aItem)
aItem - The item to be updated. May not be null.IllegalArgumentException - If no item with the same ID is already contained@MustBeLocked(value=WRITE) @Nullable protected final IMPLTYPE internalDeleteItem(@Nullable String sID)
sID - The ID to be removed. May be null.null no such item was found and
therefore nothing was removed.@MustBeLocked(value=WRITE) protected final void internalMarkItemDeleted(@Nonnull IMPLTYPE aItem)
aItem - The item that was marked as "deleted"@MustBeLocked(value=WRITE) protected final void internalMarkItemUndeleted(@Nonnull IMPLTYPE aItem)
aItem - The item that was marked as "no longer deleted"@MustBeLocked(value=WRITE) @Nonnull protected final com.helger.commons.state.EChange internalRemoveAllItemsNoCallback()
EChange.CHANGED if something was contained,
EChange.UNCHANGED otherwise.@Nonnull @ReturnsMutableCopy public final <T> com.helger.commons.collection.ext.ICommonsList<T> getNone()
@Nonnull @ReturnsMutableCopy public final com.helger.commons.collection.ext.ICommonsList<INTERFACETYPE> getAll()
getAll in interface IMapBasedDAO<INTERFACETYPE extends com.helger.commons.id.IHasID<String> & Serializable>@Nonnull @ReturnsMutableCopy public final com.helger.commons.collection.ext.ICommonsList<INTERFACETYPE> getAll(@Nullable Predicate<? super INTERFACETYPE> aFilter)
getAll in interface IMapBasedDAO<INTERFACETYPE extends com.helger.commons.id.IHasID<String> & Serializable>@Nonnull @ReturnsMutableCopy protected final Iterable<IMPLTYPE> internalDirectGetAll()
@Nonnull @ReturnsMutableCopy protected final com.helger.commons.collection.ext.ICommonsList<IMPLTYPE> internalGetAll(@Nullable Predicate<? super IMPLTYPE> aFilter)
public final void findAll(@Nullable Predicate<? super INTERFACETYPE> aFilter, @Nonnull Consumer<? super INTERFACETYPE> aConsumer)
findAll in interface IMapBasedDAO<INTERFACETYPE extends com.helger.commons.id.IHasID<String> & Serializable>@Nonnull @ReturnsMutableCopy public final <RETTYPE> com.helger.commons.collection.ext.ICommonsList<RETTYPE> getAllMapped(@Nullable Predicate<? super INTERFACETYPE> aFilter, @Nonnull Function<? super INTERFACETYPE,? extends RETTYPE> aMapper)
getAllMapped in interface IMapBasedDAO<INTERFACETYPE extends com.helger.commons.id.IHasID<String> & Serializable>public final <RETTYPE> void findAllMapped(@Nullable Predicate<? super INTERFACETYPE> aFilter, @Nonnull Function<? super INTERFACETYPE,? extends RETTYPE> aMapper, @Nonnull Consumer<? super RETTYPE> aConsumer)
findAllMapped in interface IMapBasedDAO<INTERFACETYPE extends com.helger.commons.id.IHasID<String> & Serializable>@Nullable public final INTERFACETYPE findFirst(@Nullable Predicate<? super INTERFACETYPE> aFilter)
findFirst in interface IMapBasedDAO<INTERFACETYPE extends com.helger.commons.id.IHasID<String> & Serializable>@Nullable public final <RETTYPE> RETTYPE findFirstMapped(@Nullable Predicate<? super INTERFACETYPE> aFilter, @Nonnull Function<? super INTERFACETYPE,? extends RETTYPE> aMapper)
findFirstMapped in interface IMapBasedDAO<INTERFACETYPE extends com.helger.commons.id.IHasID<String> & Serializable>public final boolean containsAny()
containsAny in interface IMapBasedDAO<INTERFACETYPE extends com.helger.commons.id.IHasID<String> & Serializable>public final boolean containsAny(@Nullable Predicate<? super INTERFACETYPE> aFilter)
containsAny in interface IMapBasedDAO<INTERFACETYPE extends com.helger.commons.id.IHasID<String> & Serializable>public final boolean containsNone()
containsNone in interface IMapBasedDAO<INTERFACETYPE extends com.helger.commons.id.IHasID<String> & Serializable>public final boolean containsNone(@Nullable Predicate<? super INTERFACETYPE> aFilter)
containsNone in interface IMapBasedDAO<INTERFACETYPE extends com.helger.commons.id.IHasID<String> & Serializable>public final boolean containsOnly(@Nullable Predicate<? super INTERFACETYPE> aFilter)
containsOnly in interface IMapBasedDAO<INTERFACETYPE extends com.helger.commons.id.IHasID<String> & Serializable>public final void forEach(@Nullable BiConsumer<? super String,? super INTERFACETYPE> aConsumer)
public final void forEach(@Nullable BiPredicate<? super String,? super INTERFACETYPE> aFilter, @Nullable BiConsumer<? super String,? super INTERFACETYPE> aConsumer)
public final void forEachKey(@Nullable Predicate<? super String> aFilter, @Nullable Consumer<? super String> aConsumer)
public final void forEachValue(@Nullable Consumer<? super INTERFACETYPE> aConsumer)
protected final void internalForEachValue(@Nullable Consumer<? super IMPLTYPE> aConsumer)
public final void forEachValue(@Nullable Predicate<? super INTERFACETYPE> aFilter, @Nullable Consumer<? super INTERFACETYPE> aConsumer)
protected final void internalForEachValue(@Nullable Predicate<? super IMPLTYPE> aFilter, @Nullable Consumer<? super IMPLTYPE> aConsumer)
@Nullable @MustBeLocked(value=READ) protected final IMPLTYPE getOfIDLocked(@Nullable String sID)
@Nullable protected final INTERFACETYPE getAtIndex(@Nonnegative int nIndex)
nIndex - The index to retrieve. Should be ≥ 0.null if an invalid index was provided.public final boolean containsWithID(@Nullable String sID)
containsWithID in interface IMapBasedDAO<INTERFACETYPE extends com.helger.commons.id.IHasID<String> & Serializable>@Nonnull @ReturnsMutableCopy public final com.helger.commons.collection.ext.ICommonsSet<String> getAllIDs()
getAllIDs in interface IMapBasedDAO<INTERFACETYPE extends com.helger.commons.id.IHasID<String> & Serializable>@Nonnegative public final int getCount()
getCount in interface IMapBasedDAO<INTERFACETYPE extends com.helger.commons.id.IHasID<String> & Serializable>@Nonnegative public final int getCount(@Nullable Predicate<? super INTERFACETYPE> aFilter)
getCount in interface IMapBasedDAO<INTERFACETYPE extends com.helger.commons.id.IHasID<String> & Serializable>public String toString()
toString in class AbstractWALDAO<IMPLTYPE extends INTERFACETYPE>Copyright © 2014–2017 Philip Helger. All rights reserved.