T
- the type of Data being managed in the Setpublic class DataSetHelper<T extends Data>
extends java.lang.Object
Example :
public class DemoDBData extends Publication implements DBData { protected TreeSet<Member> myDataSet; private transient DataSetHelper<Member> myDataSetHelper = DataSetHelper.build(this, Member.class, this::setMyDataSet); public Set<Member> getMyDataSet() { if (isDBData()) { myDataSetHelper.refreshDataCollectionIfNeeded(); } return myDataSet; } public void setMyDataSet(TreeSet<Member> groupSet) { this.myDataSet = groupSet; if (isDBData()) { myDataSetHelper.updateIdSet(groupSet); } } public Set<String> getMyDataIdSet() { return myDataSetHelper.getIdSet(); } public void setMyDataIdSet(Set<String> idSet) { myDataSetHelper.setIdSet(idSet); } @Override public void initializeDBDataCollections() { super.initializeDBDataCollections(); if (myDataSetHelper != null) { myDataSetHelper.initializeHibernateCollection(); } } @Override public void cloneDBDataCollections() { super.cloneDBDataCollections(); if (myDataSetHelper != null) { myDataSetHelper = myDataSetHelper.copy(this::setMyDataSet); } } }
Constructor and Description |
---|
DataSetHelper(java.lang.Class<T> collectionDataClass,
java.util.function.Consumer<java.util.TreeSet<T>> dataCollectionSetter)
Create a new DataSetHelper 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.TreeSet<T>> dataCollectionSetter)
Build a new instance of DataSetHelper, IF NEEDED.
|
DataSetHelper<T> |
copy(java.util.function.Consumer<java.util.TreeSet<T>> dataCollectionSetter)
Create a copy of the underlying id set, and invoke the
specified setter to update the Data Collection.
|
java.util.Set<java.lang.String> |
getIdSet()
Retrieve the underlying id Set collection.
|
void |
initializeHibernateCollection()
Force initialization of the underlying Hibernate proxy/collections.
|
void |
refreshDataCollectionIfNeeded()
Invoke the specified data collection setter if needed.
|
void |
setIdSet(java.util.Set<java.lang.String> idSet)
Replace the underlying id Set with the specified one.
|
void |
updateIdSet(java.util.Set<T> dataSet)
Update the underlying id Set with values from the specified Set of Data.
|
public DataSetHelper(java.lang.Class<T> collectionDataClass, java.util.function.Consumer<java.util.TreeSet<T>> dataCollectionSetter)
collectionDataClass
- required, must not be nulldataCollectionSetter
- the setter to invoke in refreshDataCollectionIfNeeded()
public java.util.Set<java.lang.String> getIdSet()
Known Limit : this method return the internal set, which is not thread safe : an underlying modification of the idSet 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 idSet 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 setIdSet(java.util.Set<java.lang.String> idSet)
For use in the setter of your Hibernate id collection.
idSet
- the Set of Data id to usepublic void updateIdSet(java.util.Set<T> dataSet)
For use in the setter of your Data collection.
dataSet
- the Set of Data id to usepublic void initializeHibernateCollection()
For use in Publication.initializeDBDataCollections()
implementation.
public DataSetHelper<T> copy(java.util.function.Consumer<java.util.TreeSet<T>> dataCollectionSetter)
For use in Publication.cloneDBDataCollections()
implementation.
dataCollectionSetter
- the reference to the setter of the cloned objectpublic static <T extends Data> DataSetHelper<T> build(Data data, java.lang.Class<T> collectionDataClass, java.util.function.Consumer<java.util.TreeSet<T>> dataCollectionSetter)
T
- data
- the instance of Data for which DataSetHelper 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.