📘
TimeLine E3
  • TimeLine E3 Documentation
  • Framework
    • Introduction
    • DataSet Definition
    • Window Handling Object
      • Input/Output arguments
      • Open
      • BindDataControls
      • Item Changes
      • Item Search
      • MenuItemClicked
      • Print
      • ModuleOpened (BlueArrow)
      • BlueArrowArguments
      • New Row
      • Delete Row
      • Save
      • Transactions
      • Locking [deprecated]
      • Locking (new)
      • Resizing a response window
      • ParaPanel
      • Adding DMS Tab to a Module
    • BusinessObject
    • Controls
      • BindingFormat
      • LookupGrid and SearchDef
      • ComboBox
      • RadioButton
      • Multiline Textbox
      • xTextBoxSearch
      • xFileBrowse [v16+]
      • DxDispoColumn
      • DxProgressColumn
      • DxTemplateColumn
      • Change control caption programmatically
      • TabControl
      • Navigation
      • Enable controls programmatically
      • Enable a MenuItem programmatically
      • Filter search values
      • Jumping to another module
      • Messages, Notifications, Log, Exceptions, Translation
      • LoggerSink [deprecated]
      • Log
      • OpenFile, FolderBrowsing and SaveFile
      • Execute Actions while displaying an Hourglass
      • Using Progress
      • Async methods with progress bar
      • Wizard
      • Customizing controls using xBehaviors
      • TLProperty.AllowInReadOnly [v16+]
    • DataSet Operations
    • Business-related functionality
      • Getting the next primary key
      • Hybrids
      • Enums
      • Get Current User
    • SQL
    • SQL (using named parameters)
    • Advanced SQL
    • Expression Binding
    • Server-side logic & customization [v16+]
      • Service Hoster
      • Starting / stopping hosted services
      • Changes to scheduled jobs!
      • Business Object Proxies
      • Business Object API
    • Colors in Expression Bindings [v15+]
    • Theming
      • Icons
  • TimeLine Developer (TLD)
    • Debugging in TLD
    • Targets
    • Custom Project Rework [v16+]
  • TimeLine-specific LL functions
  • Stunnel proxy
    • Pre-requisites
    • 1. Initial setup
    • 2. Generate the server/web certificates
    • 3.a. Generating client certificates using the CSR flow
    • 3.b. Generate client certificates from the server console
    • 4. Setting up the E3 client connection
    • 5. Setting up the browser certificates
  • Configuration
    • Configuring the WCF timeout
  • Troubleshooting the E3 Bridge
  • [Deprecated]
    • TimeLine WEB - deprecated in v16+
      • Prerequisites for running the WASM modules on the server
      • Prerequisites for developing WASM modules with TLD
      • Creating a small web module with TLD
      • Terminal Configuration
    • Customization Examples - deprecated in v16+
    • Codestore [deprecated]
    • Configuring the scheduled jobs timeout - deprecated in v16+
Powered by GitBook
On this page
  1. Framework
  2. Window Handling Object

Transactions

xTransaction in WHO with passing down to all BusObjects (BusinessObjects). The WHO should have the responsability for commit/rollback. Each BusinessObject should issue an exception in case of an error and this exception should be caught by the WHO. This will allow multi-level BusinessObjects working together without suppressing the real exception on an intermediary level (by a “parent” BusinessObject).

Each WHO has a property called “TransactionCreate” (preset on TRUE) which:

  • creates a transaction-object (called “Transaction”) when a module is opened and applies it to its BusinessObject

  • the Save method from the base class automatically commits the transaction

  • when the module is closed that transaction calls the dispose method

“TransactionCreate” will be set on FALSE (in the constructor) if the module:

  • does not work with the database

  • is an internal module (xModule)

  • is response module and receives the transaction from the parent context

  • does not require transactions for any other reason

Notice that one response Module could have TransactionCreate set on true, because while opening a module using OpenResponseModule with Transaction as parameter, it will automatically set TransactionCreate on false and will pass the Transaction of the parent.

Each action done in the WHO needs to commit its changes. The handling of the exception is done in the WHO.

Best practice: The BusinessObjects should not return negative values for errors. Instead, exceptions, containing all the details about the error, should be thrown.

Example: Steps to implement for proper transaction management:

In the constructor of the WHO specify that a transaction is needed. This is all that has to be done. This transaction is passed on to the BusObj, which then gives it to its children, and so on…

public wndPers() : base("busPers")
{
    TransactionCreate = true;
}

The Method inside the WHO should look like this:

public virtual void GeneratePers(dsBPartnerCustom.PersRow row)
{
    //     ......
    // GP generieren
    try
    {
        int retVal = BusObj.GenerateBPContact(lrTree.LRTree, row, true);
        Transaction.Commit();
    }
    catch (Exception ex)
    {
        Transaction.Rollback();
        xMessageBox.ShowException(ex, "Fehler beim Erstellen des Geschäftspartners.");     
    }
}

retVal is used to know the result of the action (if all went well), but not for Errors. All errors happening inside GenerateBP pop out as exceptions. Also important here is that first the transaction is rolled back, THEN the message is shown. This way, the user can “study” the message without eventually locking some Database-Rows.

public virtual void GenerateBPContact (LrTree tree, dsBPartnerCustom.PersTelRow row, bool genSubPers = true)
{
		// Inits		
		// ...
		// UnterBP
		
		if (genSubPers)
		{
				foreach (var child in children)
				{
						GenerateBP (tree, child.Info.DataRow, true);
						int unterBP = child.Info.DataRow["nr"].ToInt(0);
				}
		}

    //...
    
    return 1;
}

Notice that GenerateBP(...) is a recursive function and only if ALL BP are created correctly, the WHO-Method will Commit the transaction. If an error occurs, everything is rolled back.

To create a busObj inside a busObj, use the Function „CreateChildBusinessObject”. This way, the transaction is passed on to this new Object.

Example:

var pers = this.CreateChildBusinessObject<busPers>();

Using current object transaction to do other sql operations

try
{
    Sql.Execute(Transaction, "DELETE FROM gebinde WHERE bel_typ = {0} AND bel_nr = {1} AND typ = 10", belTyp, belNr);
}
catch (Exception)
{
    if (Transaction != null)
    {
        Rollback();
    }

    throw;
}

int result = Save();
if (result < 0 && Transaction != null)
{
    Rollback();
}

Note: CurrentTransaction is obsolete, Transaction is the new name of the transaction property

PreviousSaveNextLocking [deprecated]

Last updated 4 years ago