. .


ST 4U 168: Transactions with GLORP

December 9, 2011 10:37:58.282

Today's Smalltalk 4 You goes through deleting objects using Glorp - which requires us to specify a primary key in our table mapping. The initial setup used is described here. If you have trouble viewing it here in the browser, you can also navigate directly to YouTube. To watch now, click on the image below:


If you have trouble viewing that directly, you can click here to download the video directly. If you need the video in a Windows Media format, then download that here.

You can also watch it on YouTube:

Today we'll look at how to wrap statements that will change a database in a transaction using GLORP. As the example, we'll revisit deleting. Recall that the following code implicitly wraps the #delete: in a commit:

"deleting - uses a transaction for is"
myEmp := session readOneOf: Emp where: [:each | each firstName = 'Wilma4'].
session delete: myEmp.

If you want to control that completely, simply put the entire sequence into a transaction, using #beginUnitOfWork

"specify a unit of work so we can rollback"
session beginUnitOfWork.
foundEmp := session readOneOf: Emp where: [:each | each firstName = 'Wilma4'].
session delete: foundPerson.
session rollbackUnitOfWork.

That will rollback the deletion. If you wanted to commit it, use #commitUnitOfWork instead. That's all there is to it.

Need more help? There's a screencast for other topics like this which you may want to watch. Questions? Try the "Chat with James" Google gadget over in the sidebar.

Technorati Tags: , ,

[st4u168-iPhone.m4v ( Size: 2557281 )]

posted by James Robertson

 Share Tweet This