SBarnes wrote:If a business logic object is created and saved in the save of a Jiwa collection item and there is a transaction in progress will everything be covered by the same transaction i.e. if any part of the save fails then the business logic save will get rolled back as well?
Yes - provided that collection item save was invoked by some process which started a transaction.
We designed around the save of the business logic being what starts a new transaction if one is not already started and the collection items all use the current transaction. So if using our business logic and only ever invoking the iSave of a business logic object (as opposed to the iSave of any collection items) when everything should work as expected.
The basic pattern we follow is as follows:
- Code: Select all
With Manager.Database
Try
If .SQLTransaction Is Nothing Then
' flag that we created the transaction, so we know if we should be the ones to .commit or .rollback later.
.BeginNewTransaction()
weStartedTransaction = True
End If
OnSaveStart
... Save code in here
OnSaveEnding()
If weStartedTransaction Then
.SQLTransaction.Commit()
.SQLTransaction.Dispose()
.SQLTransaction = Nothing
End If
OnSaveEnd()
Catch ex As Exception
If weStartedTransaction AndAlso .SQLTransaction IsNot Nothing Then
If .SQLTransaction.Connection IsNot Nothing Then
.SQLTransaction.Rollback()
End If
.SQLTransaction.Dispose()
.SQLTransaction = Nothing
End If
Throw
Finally
If weStartedTransaction Then
.SQLTransaction = Nothing
End If
End Try
End With
SBarnes wrote:there may be a thread safety issue with the Sales Order Business Logic Object because if I try to in the save of a Jiwa Collection Item try and create a credit note the following line throws an exception about indexes and collections and values being out of bounds as soon as there is more than one object in the collection
That shouldn't happen - we do something similar to that with recurring orders - the iSave method of the recurring Batch Line creates a new sales order business logic and adds lines to it and saves it.
How would I reproduce this? I'm guessing you've created your own business logic with a collection and within the iSave of the items of the collection is where you're creating and saving a credit note - would that be accurate?
Mike