Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Use a <a href="http://martinfowler.com/eaaCatalog/unitOfWork.html" rel="nofollow">Unit Of Work</a>. A Unit Of Work is used to determine which entities/objects are "dirty" - meaning their in-memory data is out-of-sync with the persistence store or database - and which are "clean".</p> <p>Just tweak the concept to keep track of which properties are dirty and you're good to go.</p> <h1>Example</h1> <p>(it's been a while since I've written Java and I don't have Java on this machine, so there might be little errors)</p> <h2><code>MyClass.java</code></h2> <pre><code>public class MyClass extends ChangeObservable { private String name; private Age int; public MyClass(name, age) { // when the object is first created, // I'm assuming that the "clean" values are provided this.name = name; this.age = age; } public String getName() { return name; } public void setName(n) { name = n; this.fireChangeEvent("name"); } public String getAge() { return age; } public void setAge(a) { age = a; this.fireChangeEvent("age"); } } </code></pre> <h2><code>UnitOfWork.java</code></h2> <pre><code>public class UnitOfWork implements ChangeListener { // dunno if this is the most efficient implementation... private HashSet&lt;String&gt; dirties = new HashSet&lt;String&gt;(); private Observable obj; public UnitOfWork(Observable obj) { this.obj = obj; obj.registerChangeListener(this); } public void registerDirty(propName) { // probably more code needed... dirties.add(propName); } public HashSet&lt;String&gt; getDirtyProperties() { // probably more code needed... return new HashSet&lt;String&gt;(dirties); } public void onChangeEvent(propName) { this.registerDirty(propName); } // note: a UnitOfWork needs more functionality than this! // I've implemented the bare minimum for the example // but it would also need methods like `registerClean(...)` } </code></pre> <h2><code>Driver.java</code></h2> <pre><code>public class MyDriver { public static void main(String[] argv) { MyClass myObj = new MyClass("Richard", 3); UnitOfWork uow = new UnitOfWork(myObj); myObj.setName("Mark"); for(String propName : uow.getDirtyProperties()) { System.out.print(propName); } } } </code></pre> <p>... now the <code>UnitOfWork.getDirtyProperties(...)</code> can be used to determine which properties are clean and dirty.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload