Every destructive operation in the server must be a part of a transaction. Transactions are controlled through a Transaction object exposed through a property on the SPFRequestContext.Instance. The class is SPFTransaction in the SPF.Server namespace. To begin a transaction, simply call
Public Sub Begin()
To end a transaction, you simply call one of the following.
Public Sub Commit()
Public Sub Rollback()
Transactions should be begun and ended within the Server APIs. The reason for this is that the PrimaryMethodDefs may be called as part of other transactions.
A good best-practice template using transactions with exception handling is as follows.
SPFRequestContext.Instance.Transaction.Begin()
Try
' Creates, updates, relates, terminates.
SPFRequestContext.Instance.Transaction.Commit()
Catch lobjException As SPFException
SPFRequestContext.Instance.Transaction.Rollback()
End Try
The transaction is started before the try block is opened. Then, within the try block, the actual work should be performed. At the end of the try block, once all the work has been completed, the transaction should be committed. In the catch block, however, the transaction should be rolled back.
There is a property on Transaction (Public ReadOnly Property InTransaction() As Boolean) that you can use to determine if you are already in a transaction. If that is the case, you would not want to start another.