Re: isDirty
"tibor_ml" <[email protected]>
| Newsgroups | gmane.comp.java.orm.simpleorm |
|---|---|
| Message-ID | <[email protected]> |
I was working against branches/simpleorm-3.2, not against trunk. I did fresh checkout of 3.2 and tried my test again. I don't know what I screwed up before, but I can't reproduce isDirty problem now. I am doing some generic data replicator, so my usage of SimpleORM is probably not very common. Here is code that I had problem with also and what my patch fixed for me ( for 3.2 branch): // ( department 200 is department of employee200 in database ) Department dep200 = ses.find(Department.DEPARTMENT, "200"); Employee employee = ses.find(Employee.EMPLOYEE, "300"); employee.findReference( Employee.DEPARTMENT); employee.isValid(Employee.DEPARTMENT); // returns false !!! I am switching to trunk now, and I see changes there, thanks. Tibor --- In [email protected], Anthony Berglas <anthony@...> wrote: > > Hello Tibor, > > I have added your changes to the code. They are a slight improvement > but they do not fix your obscure but valid bug, nor would I expect them to. > > I suspect that you have not diffed the right files/versions. > > I have also added your code to BasicTests. The fact that you took > the trouble to create the extra test is *excellent*. It still fails > though, so I have commented out the last assert with "THIS FAILS". > > Please check out from subversion, do a diff, let me know what you > find. If you fix it, I'll add the fix soon, otherwise I'll put it on > my TODO list. > > If you are interested in making carefully considered changes with > unit tests we can consider making you another commiter. (I always > review the committed code anyway.) > > It is nice not being at the mercy of a mailing list, isn't it. > > Thanks, > > Anthony > > > > At 11:22 PM 12/10/2008, tibor_ml wrote: > > >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; > >} > > > > > > > > Dr Anthony Berglas, anthony@... Mobile: +61 4 4838 8874 > Just because it is possible to push twigs along the ground with ones nose > does not necessarily mean that is the best way to collect firewood. > ------------------------------------ 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/