isDirty

"tibor_ml" <[email protected]>
Newsgroups gmane.comp.java.orm.simpleorm
Message-ID <[email protected]>
Hello ,

I have usecase where I need to check if entity was changed or not. Entity should report 
isDirty as false also if the same values/references was set on it. I have found that 
SimpleORM works great for fields, but not for references in this case.

see BasicTests.empTest() for sample data
 
		Department dep = ses.find(Department.DEPARTMENT, "200");
		Employee employee = ses.find(Employee.EMPLOYEE, "300");
		employee.setPhoneNumber( "123 456 7890");
		TestUte.assertTrue( ! employee.isDirty()); // works
		employee.setReference( Employee.DEPARTMENT, dep );
		TestUte.assertTrue( ! employee.isDirty()); // broken !!!
 
after looking into code I have found how to fix it, see patch below.

it is my first touch with SimpleORM and thanks to it's simplicity I can very easy find what's 
going on underneath. Thanks for fresh air in o/r mappers room !

  Tibor
 

Index: dataset/simpleorm/dataset/SFieldReference.java
=======================================================
============
--- dataset/simpleorm/dataset/SFieldReference.java      (revision 824)
+++ dataset/simpleorm/dataset/SFieldReference.java      Fri Oct 10 00:45:42 CEST 2008
@@ -243,7 +243,10 @@
             int kv = 0;
             for (SFieldScalar fkey : getForeignKeyMetas()) { // Guarenteed to be in order of pkey
                 Object fkValue = rinst.getObject(fkey); 
-                if (fkValue == null)  return null; // if any scalar key is null then reference is null.
+                if (fkValue == null)  {
+                  rinst.setRawArrayValue(this, result); // For next time.
+                  return null; // if any scalar key is null then reference is null.
+                }
                 keyValues[kv] = fkValue ;
                 kv++;
             }
@@ -264,9 +267,10 @@
                     }
                     result = ses.findOrCreate(referencedRecordMeta, 
referencedRecordMeta.fieldsForMode(selectMode), queryMode, keyValu
es);
                     // if (result.isNewRow()) throw exception?
+                    
+                }
-                    rinst.setRawArrayValue(this, result); // For next time.
-                }
+              rinst.setRawArrayValue(this, result); // For next time.
+    }
-               }
                return result;
        }
 


------------------------------------

Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/SimpleORM/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/SimpleORM/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:[email protected] 
    mailto:[email protected]

<*> To unsubscribe from this group, send an email to:
    [email protected]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.