Meaning of the Return Value of Mapper.save?

113 views
Skip to first unread message

Christoph Knabe

unread,
Mar 9, 2011, 6:23:42 AM3/9/11
to Lift
I could not find any source for the purpose of the Boolean return
value of method Mapper.save .

With ScalaTest I wrote a JUnit-like test case for the return value,
but it found only situations in which save returns true. I did not
succeed to make it return false.

I looked into MetaMapper.save, but did not understand, how the ret
values there are computed.

If someone please could give me a hint about the meaning, I would
amend the appropriate Wiki page.


/**Tests the Boolean return value of the Mapper method save.*/
@Test def mapperSave {
val testFac: Faculty =
Faculty.create.name("TestFaculty1").kuerzel("Test FB 1");
{
val saved = testFac.save()
assert(saved === true, "Faculty newly inserted into database")
}
{
val saved = testFac.save()
assert(saved === true, "Faculty was not modified")
}
{
val saved = testFac.kuerzel("Test FB 1").save()
assert(saved === true, "Faculty was identically modified")
}
{
val saved = testFac.kuerzel("Test FB I").save()
assert(saved === true, "Faculty was modified, thus updated in
database")
}
{
//Modify ID after saving:
intercept[Exception]{testFac.id(99999).save()}
}
}

Richard Dallaway

unread,
Mar 9, 2011, 7:00:01 AM3/9/11
to lif...@googlegroups.com, Christoph Knabe
Exploring Lift says: "returns a boolean to indicate whether the save was successful or not" (section 8.1, PDF dated Jan 16, 2011)


--
You received this message because you are subscribed to the Google Groups "Lift" group.
To post to this group, send email to lif...@googlegroups.com.
To unsubscribe from this group, send email to liftweb+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/liftweb?hl=en.


Christoph Knabe

unread,
Mar 9, 2011, 9:52:07 AM3/9/11
to Lift
@Richard

Thanks to your explanation.

Nevertheless I did not succeed to reproduce a return value of false.
As you see in the upper example, when I erroneously called save
(changing the ID in an already saved entity), save threw an Exception.

So may be, the Boolean return code is no longer used, and save throws
an Exception, if it cannot save the entity object?

Did you ever observe a false return value?

If so, one would have to always check the return value.

David Pollak

unread,
Mar 9, 2011, 10:49:38 AM3/9/11
to lif...@googlegroups.com
I believe I had the Boolean return value for save to make it like ActiveRecord.  I do not know how save could be false.  Don't bother checking.
 

--
You received this message because you are subscribed to the Google Groups "Lift" group.
To post to this group, send email to lif...@googlegroups.com.
To unsubscribe from this group, send email to liftweb+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/liftweb?hl=en.




--
Lift, the simply functional web framework http://liftweb.net
Beginning Scala http://www.apress.com/book/view/1430219890
Follow me: http://twitter.com/dpp
Blog: http://goodstuff.im
Surf the harmonics
Reply all
Reply to author
Forward
0 new messages