T
- the type of Data being managed in the Listpublic class DataListHelper<T extends Data>
extends java.lang.Object
Example :
public class DemoDBData extends Publication implements DBData { protected List<Member> myDataList; private transient DataListHelper<Member> myDataListHelper = DataListHelper.build(this, Member.class, this::setMyDataList); public List<Member> getMyDataList() { if (isDBData()) { myDataListHelper.refreshDataCollectionIfNeeded(); } return myDataList; } public void setMyDataList(List<Member> groupList) { this.myDataList = groupList; if (isDBData()) { myDataListHelper.updateIdList(groupList); } } public List<String> getMyDataIdList() { return myDataListHelper.getIdList(); } public void setMyDataIdList(List<String> idList) { myDataListHelper.setIdList(idList); } @Override public void initializeDBDataCollections() { super.initializeDBDataCollections(); if (myDataListHelper != null) { myDataListHelper.initializeHibernateCollection(); } } @Override public void cloneDBDataCollections() { super.cloneDBDataCollections(); if (myDataListHelper != null) { myDataListHelper = myDataListHelper.copy(this::setMyDataList); } } }
Constructor and Description |
---|
DataListHelper(java.lang.Class<T> collectionDataClass,
java.util.function.Consumer<java.util.List<T>> dataCollectionSetter)
Create a new DataListHelper to manage a collection of the specified Data type.
|
Modifier and Type | Method and Description |
---|---|
static <T extends Data> |
build(Data data,
java.lang.Class<T> collectionDataClass,
java.util.function.Consumer<java.util.List<T>> dataCollectionSetter)
Build a new instance of DataListHelper, IF NEEDED.
|
DataListHelper<T> |
copy(java.util.function.Consumer<java.util.List<T>> dataCollectionSetter)
Create a copy of the underlying id set, and invoke the
specified setter to update the Data Collection.
|
java.util.List<java.lang.String> |
getIdList()
Retrieve the underlying id List collection.
|
void |
initializeHibernateCollection()
Force initialization of the underlying Hibernate proxy/collections.
|
void |
refreshDataCollectionIfNeeded()
Invoke the specified data collection setter if needed.
|
void |
setIdList(java.util.List<java.lang.String> idList)
Replace the underlying id List with the specified one.
|
void |
updateIdList(java.util.List<T> dataList)
Update the underlying id List with values from the specified List of Data.
|
public DataListHelper(java.lang.Class<T> collectionDataClass, java.util.function.Consumer<java.util.List<T>> dataCollectionSetter)
collectionDataClass
- required, must not be nulldataCollectionSetter
- the setter to invoke in refreshDataCollectionIfNeeded()
public java.util.List<java.lang.String> getIdList()
Known Limit : this method return the internal set, which is not thread safe : an underlying modification of the idList could happen while you retrieve it. Life is hard, so is computer science, deal with it.
For use in the getter of your Hibernate id collection.
public void refreshDataCollectionIfNeeded()
that is if idList was set/modified, and data collection setter was never invoked since the modification.
For use, as lazy loading, in the getter of your Data collection.
public void setIdList(java.util.List<java.lang.String> idList)
For use in the setter of your Hibernate id collection.
idList
- the List of Data id to usepublic void updateIdList(java.util.List<T> dataList)
For use in the setter of your Data collection.
dataList
- the List of Data id to usepublic void initializeHibernateCollection()
For use in Publication.initializeDBDataCollections()
implementation.
public DataListHelper<T> copy(java.util.function.Consumer<java.util.List<T>> dataCollectionSetter)
For use in Publication.cloneDBDataCollections()
implementation.
dataCollectionSetter
- the reference to the setter of the cloned objectpublic static <T extends Data> DataListHelper<T> build(Data data, java.lang.Class<T> collectionDataClass, java.util.function.Consumer<java.util.List<T>> dataCollectionSetter)
T
- data
- the instance of Data for which DataListHelper is built, return null if the specified Data is a JStore objectcollectionDataClass
- the type of Data being manipulated in the collectiondataCollectionSetter
- the setter of the Data collection on the Data instanceCopyright © 2001-2021 Jalios SA. All Rights Reserved.