Skip to content
urvaksh edited this page Sep 17, 2015 · 2 revisions

Sheldon

A framework that detects changes and complains about them

What is Sheldon?

Sheldon is basically a dirty checking framework that deep compares two objects and detects any changes in the entire object graph.

//Just mark the Entity as Auditable
@Auditable(name = "Missy Cooper", comparatorFields = @AuditComparator({ "dnaSeq" }))
public class MissyCooper {

	//Used as the identifier of this record, hence added in @AuditComparator
	private DnaSequence dnaSeq;

    	//This field is dirty checked automatically
	@AuditField(fieldName = "Last Name", groups = {"matrimony","standard"})
	private String lastName;

	//Unlikely to change hence not Audited
	private String firstName;

    	//It works on component objects.
	//Because Missy keeps tabs on Sheldon and tattles to her mom
	//And SheldonCooper is a singleton class with a one of a kind IQ!
	@AuditField(fieldName = "Sibling", comparatorFields = @AuditComparator("iq"), groups = "exceptional")
	private SheldonCooper twin;

	//We don't care about him, so not annotation
	private Person brother;

    	//And on Iterables
	@AuditableList(groups = {"standard","mischievous"}, comparatorFields = @AuditComparator("id"))
	private List<Child> children = new ArrayList<Child>();

}

Now dirty checking is as simple as

AuditChecker checker = new AuditChecker<MissyCooper>();
//Detects all the changes
List<AuditChangeEntry> changes = checker.checkObjects(oldMissy, newMissy);
//If you only want to detect changes in the group "exceptional"
List<AuditChangeEntry> sheldonyChanges = checker.checkObjects(oldMissy, newMissy, "exceptional");