Clerk Class

 

Writes records of transactional actions to a log.

Namespace:   System.EnterpriseServices.CompensatingResourceManager
Assembly:  System.EnterpriseServices (in System.EnterpriseServices.dll)

System::Object
  System.EnterpriseServices.CompensatingResourceManager::Clerk

public ref class Clerk sealed 

NameDescription
System_CAPS_pubmethodClerk(String^, String^, CompensatorOptions)

Initializes a new instance of the Clerk class.

System_CAPS_pubmethodClerk(Type^, String^, CompensatorOptions)

Initializes a new instance of the Clerk class.

NameDescription
System_CAPS_pubpropertyLogRecordCount

Gets the number of log records.

System_CAPS_pubpropertyTransactionUOW

Gets a value representing the transaction unit of work (UOW).

NameDescription
System_CAPS_pubmethodEquals(Object^)

Determines whether the specified object is equal to the current object.(Inherited from Object.)

System_CAPS_protmethodFinalize()

Frees the resources of the current Clerk before it is reclaimed by the garbage collector.(Overrides Object::Finalize().)

System_CAPS_pubmethodForceLog()

Forces all log records to disk.

System_CAPS_pubmethodForceTransactionToAbort()

Performs an immediate abort call on the transaction.

System_CAPS_pubmethodForgetLogRecord()

Does not deliver the last log record that was written by this instance of this interface.

System_CAPS_pubmethodGetHashCode()

Serves as the default hash function. (Inherited from Object.)

System_CAPS_pubmethodGetType()

Gets the Type of the current instance.(Inherited from Object.)

System_CAPS_pubmethodToString()

Returns a string that represents the current object.(Inherited from Object.)

System_CAPS_pubmethodWriteLogRecord(Object^)

Writes unstructured log records to the log.

Each clerk is associated with a compensator, which is called back to perform actions during the two-phase commit of the transaction.

The following code example demonstrates the use of this class.

// A CRM Worker
[Transaction]
public ref class Account : public ServicedComponent
{

    // A data member for the account file name.
private:
    String^ filenameValue;

public:
    property String^ Filename
    {
        String^ get()
        {
            return filenameValue;
        }
        void set( String^ value )
        {
            filenameValue = value;
        }
    }

    // A boolean data member that determines whether to commit or abort the 
    // transaction.
private:
    bool allowCommitValue;

public:
    property bool AllowCommit
    {
        bool get()
        {
            return allowCommitValue;
        }
        void set( bool value )
        {
            allowCommitValue = value;
        }
    }

    // Debit the account, 
public:
    void DebitAccount(int amount)
    {

        // Create a new clerk using the AccountCompensator class.
        Clerk^ clerk = gcnew Clerk(AccountCompensator::typeid,
            "An account transaction compensator", CompensatorOptions::AllPhases);

        // Create a record of previous account status, and deliver it to the
        // clerk.
        int balance = ReadAccountBalance(Filename);

        array<Object^>^ record = gcnew array<Object^>(2);
        record[0] = Filename;
        record[1] = balance;

        clerk->WriteLogRecord(record);
        clerk->ForceLog();

        // Perform the transaction
        balance -= amount;

        Console::WriteLine("{0}: {1}", Filename, balance);

        WriteAccountBalance(Filename, balance);

        // Commit or abort the transaction 
        if (AllowCommit)
        {
            ContextUtil::SetComplete();
        }
        else
        {
            ContextUtil::SetAbort();
        }

    }

};

The following code example demonstrates the corresponding Compensator class.

#using "System.EnterpriseServices.dll"

using namespace System;

[assembly: System::Reflection::AssemblyKeyFile("CrmServer.key")];

int main ()
{

    // Create a new account object. The object is created in a COM+ server application.
    Account^ account = gcnew Account();

    // Transactionally debit the account.
    try
    {
        account->Filename = System::IO::Path::GetFullPath("JohnDoe");
        account->AllowCommit = true;
        account->DebitAccount(3);
    }
    finally
    {
        delete account;
    }

}

.NET Framework
Available since 1.1

Any public static ( Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Return to top
Show: