Skip to content

Instantly share code, notes, and snippets.

@calaveraInfo
Created November 21, 2019 08:59
Show Gist options
  • Save calaveraInfo/6943ec5fe4c63e5c2bc0ab95e82b5339 to your computer and use it in GitHub Desktop.
Save calaveraInfo/6943ec5fe4c63e5c2bc0ab95e82b5339 to your computer and use it in GitHub Desktop.
Intermittently mutable data concept
public interface Index() {
/*
* @return mutable copy of indexes contained in this instance.
*/
MutableIndex beginMutation();
/*
* Example usage of indexes for data retrieval.
*/
PrimaryKey findBySomeAttributeValue(String value);
PrimaryKey findByOtherAttributeValue(String value);
/*...*/
}
/*
* This class is not thread safe, it is intended to exist only
* in one thread for a short period of time (equivalent of one transaction).
* #endMutation has to be called before sharing data with others.
*/
public interface MutableIndex extends Index {
/*
* @return immutable copy of indexes contained in this instance.
*/
Index endMutation();
/*
* Example mutable update of contained indexes.
*/
void updateSomeIndexes(SomeDomainObject dto);
void updateOtherIndexes(OtherDomainObject dto);
/*...*/
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment