Transactions - SmartPlant Foundation - IM Update 44 - Customization & Programming - Hexagon

SmartPlant Foundation Customization

Language
English
Product
SmartPlant Foundation
Search by Category
Customization & Programming
SmartPlant Foundation / SDx Version
10

The server has native support for extended transactions through the internal loader. Whether data comes from load files or Client API calls, extended transactions can be built and committed or rolled back as a single unit.

Through the Client API, this functionality is exposed very simply through the IObjectDictionary that we've already been using. Above we talked about Containers and where best to use them; the container dictionary inherits from the IObjectDictionary so the same applies. If in doubt, use containers because they prevent data corruption.

To begin a transaction, create a ContainerObjectDictionary and begin adding changes to that container. To commit the transaction, you simply call the Commit method on the container. If the container passes validation, the server will commit all the changes as one database transaction. Otherwise, the entire transaction will be rolled back and an Exception will be returned. To discard the changes at the client, of course, just discard the container and let the garbage collector clean up. The code for a transaction looks like this.

Dim lcolTransaction As New ContainerObjectDictionary(Me.SPFSession)

' Add creates, updates and deletes to the container here.

lcolTransaction.Commit()

SmartPlant Foundation 2014 and later supports committing asynchronously. This takes your container and submits the request to the server. Using this method you will not have to wait for the server to process the container; however, you won’t get any information back as to whether it was successful or not.