com.unboundid.ldap.sdk.unboundidds.extensions
Class StartInteractiveTransactionExtendedRequest

java.lang.Object
  extended by com.unboundid.ldap.sdk.LDAPRequest
      extended by com.unboundid.ldap.sdk.ExtendedRequest
          extended by com.unboundid.ldap.sdk.unboundidds.extensions.StartInteractiveTransactionExtendedRequest
All Implemented Interfaces:
ProtocolOp, ReadOnlyLDAPRequest, java.io.Serializable

@NotMutable
@ThreadSafety(level=NOT_THREADSAFE)
public final class StartInteractiveTransactionExtendedRequest
extends ExtendedRequest

NOTE: This class is part of the Commercial Edition of the UnboundID LDAP SDK for Java. It is not available for use in applications that include only the Standard Edition of the LDAP SDK, and is not supported for use in conjunction with non-UnboundID products.


NOTE: The use of interactive transactions is discouraged because it can create conditions which are prone to deadlocks between operations that may result in the cancellation of one or both operations. It is strongly recommended that standard LDAP transactions (which may be started using a StartTransactionExtendedRequest) or a multi-update extended operation be used instead. Although they cannot include arbitrary read operations, LDAP transactions and multi-update operations may be used in conjunction with the AssertionRequestControl, PreReadRequestControl, and PostReadRequestControl to incorporate some read capability into a transaction, and in conjunction with the ModificationType.INCREMENT modification type to increment integer values without the need to know the precise value before or after the operation (although the pre-read and/or post-read controls may be used to determine that).
This class provides an implementation of the start interactive transaction extended request. It may be used to begin a transaction that allows multiple operations to be processed as a single atomic unit. Interactive transactions may include read operations, in which case it is guaranteed that no operations outside of the transaction will be allowed to access the associated entries until the transaction has been committed or aborted. The StartInteractiveTransactionExtendedResult that is returned will include a a transaction ID, which should be included in each operation that is part of the transaction using the InteractiveTransactionSpecificationRequestControl. After all requests for the transaction have been submitted to the server, the EndInteractiveTransactionExtendedRequest should be used to commit that transaction, or it may also be used to abort the transaction if it is decided that it is no longer needed.

The start transaction extended request may include an element which indicates the base DN below which all operations will be attempted. This may be used to allow the Directory Server to tailor the transaction to the appropriate backend.

Whenever the client sends a start interactive transaction request to the server, the StartInteractiveTransactionExtendedResult that is returned will include a transaction ID that may be used to identify the transaction for all operations which are to be performed as part of the transaction. This transaction ID should be included in a InteractiveTransactionSpecificationRequestControl attached to each request that is to be processed as part of the transaction. When the transaction has completed, the EndInteractiveTransactionExtendedRequest may be used to commit it, and it may also be used at any time to abort the transaction if it is no longer needed.

Example

The following example demonstrates the process for creating an interactive transaction, processing multiple requests as part of that transaction, and then commits the transaction.
 // Start the interactive transaction and get the transaction ID.
 StartInteractiveTransactionExtendedRequest startTxnRequest =
      new StartInteractiveTransactionExtendedRequest("dc=example,dc=com");
 StartInteractiveTransactionExtendedResult startTxnResult =
      (StartInteractiveTransactionExtendedResult)
      connection.processExtendedOperation(startTxnRequest);
 if (startTxnResult.getResultCode() != ResultCode.SUCCESS)
 {
   throw new LDAPException(startTxnResult);
 }
 ASN1OctetString txnID = startTxnResult.getTransactionID();

 // At this point, we have a valid transaction.  We want to ensure that the
 // transaction is aborted if any failure occurs, so do that in a
 // try-finally block.
 boolean txnFailed = true;
 try
 {
   // Perform a search to find all users in the "Sales" department.
   SearchRequest searchRequest = new SearchRequest("dc=example,dc=com",
        SearchScope.SUB, Filter.createEqualityFilter("ou", "Sales"));
   searchRequest.addControl(
        new InteractiveTransactionSpecificationRequestControl(txnID, true,
             true));

   SearchResult searchResult = connection.search(searchRequest);
   if (searchResult.getResultCode() != ResultCode.SUCCESS)
   {
     throw new LDAPException(searchResult);
   }

   // Iterate through all of the users and assign a new fax number to each
   // of them.
   for (SearchResultEntry e : searchResult.getSearchEntries())
   {
     ModifyRequest modifyRequest = new ModifyRequest(e.getDN(),
          new Modification(ModificationType.REPLACE,
               "facsimileTelephoneNumber", "+1 123 456 7890"));
     modifyRequest.addControl(
          new InteractiveTransactionSpecificationRequestControl(txnID, true,

               true));
     connection.modify(modifyRequest);
   }

   // Commit the transaction.
   ExtendedResult endTxnResult = connection.processExtendedOperation(
        new EndInteractiveTransactionExtendedRequest(txnID, true));
   if (endTxnResult.getResultCode() == ResultCode.SUCCESS)
   {
     txnFailed = false;
   }
 }
 finally
 {
   if (txnFailed)
   {
     connection.processExtendedOperation(
          new EndInteractiveTransactionExtendedRequest(txnID, false));
   }
 }
 

See Also:
Serialized Form

Field Summary
static java.lang.String START_INTERACTIVE_TRANSACTION_REQUEST_OID
          The OID (1.3.6.1.4.1.30221.2.6.3) for the start interactive transaction extended request.
 
Fields inherited from class com.unboundid.ldap.sdk.ExtendedRequest
TYPE_EXTENDED_REQUEST_OID, TYPE_EXTENDED_REQUEST_VALUE
 
Constructor Summary
StartInteractiveTransactionExtendedRequest()
          Creates a new start interactive transaction extended request with no base DN.
StartInteractiveTransactionExtendedRequest(ExtendedRequest extendedRequest)
          Creates a new start interactive transaction extended request from the provided generic extended request.
StartInteractiveTransactionExtendedRequest(java.lang.String baseDN)
          Creates a new start interactive transaction extended request.
StartInteractiveTransactionExtendedRequest(java.lang.String baseDN, Control[] controls)
          Creates a new start interactive transaction extended request.
 
Method Summary
 StartInteractiveTransactionExtendedRequest duplicate()
          Creates a new instance of this LDAP request that may be modified without impacting this request.
 StartInteractiveTransactionExtendedRequest duplicate(Control[] controls)
          Creates a new instance of this LDAP request that may be modified without impacting this request.
 java.lang.String getBaseDN()
          Retrieves the base DN for this start interactive transaction extended request, if available.
 java.lang.String getExtendedRequestName()
          Retrieves the user-friendly name for the extended request, if available.
 StartInteractiveTransactionExtendedResult process(LDAPConnection connection, int depth)
          Sends this extended request to the directory server over the provided connection and returns the associated response.
 void toString(java.lang.StringBuilder buffer)
          Appends a string representation of this request to the provided buffer.
 
Methods inherited from class com.unboundid.ldap.sdk.ExtendedRequest
encodeProtocolOp, getLastMessageID, getOID, getOperationType, getProtocolOpType, getValue, hasValue, responseReceived, writeTo
 
Methods inherited from class com.unboundid.ldap.sdk.LDAPRequest
followReferrals, getControl, getControlList, getControls, getIntermediateResponseListener, getResponseTimeoutMillis, hasControl, hasControl, setFollowReferrals, setIntermediateResponseListener, setResponseTimeoutMillis, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

START_INTERACTIVE_TRANSACTION_REQUEST_OID

public static final java.lang.String START_INTERACTIVE_TRANSACTION_REQUEST_OID
The OID (1.3.6.1.4.1.30221.2.6.3) for the start interactive transaction extended request.

See Also:
Constant Field Values
Constructor Detail

StartInteractiveTransactionExtendedRequest

public StartInteractiveTransactionExtendedRequest()
Creates a new start interactive transaction extended request with no base DN.


StartInteractiveTransactionExtendedRequest

public StartInteractiveTransactionExtendedRequest(java.lang.String baseDN)
Creates a new start interactive transaction extended request.

Parameters:
baseDN - The base DN to use for the request. It may be null if no base DN should be provided.

StartInteractiveTransactionExtendedRequest

public StartInteractiveTransactionExtendedRequest(java.lang.String baseDN,
                                                  Control[] controls)
Creates a new start interactive transaction extended request.

Parameters:
baseDN - The base DN to use for the request. It may be null if no base DN should be provided.
controls - The set of controls to include in the request.

StartInteractiveTransactionExtendedRequest

public StartInteractiveTransactionExtendedRequest(ExtendedRequest extendedRequest)
                                           throws LDAPException
Creates a new start interactive transaction extended request from the provided generic extended request.

Parameters:
extendedRequest - The generic extended request to use to create this start interactive transaction extended request.
Throws:
LDAPException - If a problem occurs while decoding the request.
Method Detail

getBaseDN

public java.lang.String getBaseDN()
Retrieves the base DN for this start interactive transaction extended request, if available.

Returns:
The base DN for this start interactive transaction extended request, or null if none was provided.

process

public StartInteractiveTransactionExtendedResult process(LDAPConnection connection,
                                                         int depth)
                                                  throws LDAPException
Sends this extended request to the directory server over the provided connection and returns the associated response.

Overrides:
process in class ExtendedRequest
Parameters:
connection - The connection to use to communicate with the directory server.
depth - The current referral depth for this request. It should always be one for the initial request, and should only be incremented when following referrals.
Returns:
An LDAP result object that provides information about the result of the extended operation processing.
Throws:
LDAPException - If a problem occurs while sending the request or reading the response.

duplicate

public StartInteractiveTransactionExtendedRequest duplicate()
Creates a new instance of this LDAP request that may be modified without impacting this request.. Subclasses should override this method to return a duplicate of the appropriate type.

Specified by:
duplicate in interface ReadOnlyLDAPRequest
Overrides:
duplicate in class ExtendedRequest
Returns:
A new instance of this LDAP request that may be modified without impacting this request.

duplicate

public StartInteractiveTransactionExtendedRequest duplicate(Control[] controls)
Creates a new instance of this LDAP request that may be modified without impacting this request. The provided controls will be used for the new request instead of duplicating the controls from this request.. Subclasses should override this method to return a duplicate of the appropriate type.

Specified by:
duplicate in interface ReadOnlyLDAPRequest
Overrides:
duplicate in class ExtendedRequest
Parameters:
controls - The set of controls to include in the duplicate request.
Returns:
A new instance of this LDAP request that may be modified without impacting this request.

getExtendedRequestName

public java.lang.String getExtendedRequestName()
Retrieves the user-friendly name for the extended request, if available. If no user-friendly name has been defined, then the OID will be returned.

Overrides:
getExtendedRequestName in class ExtendedRequest
Returns:
The user-friendly name for this extended request, or the OID if no user-friendly name is available.

toString

public void toString(java.lang.StringBuilder buffer)
Appends a string representation of this request to the provided buffer.

Specified by:
toString in interface ProtocolOp
Specified by:
toString in interface ReadOnlyLDAPRequest
Overrides:
toString in class ExtendedRequest
Parameters:
buffer - The buffer to which to append a string representation of this request.