Search in sources :

Example 16 with StartTransactionExtendedRequest

use of com.unboundid.ldap.sdk.extensions.StartTransactionExtendedRequest in project ldapsdk by pingidentity.

the class TransactionExtendedOperationHandler method handleStartTransaction.

/**
 * Performs the appropriate processing for a start transaction extended
 * request.
 *
 * @param  handler    The in-memory request handler that received the request.
 * @param  messageID  The message ID for the associated request.
 * @param  request    The extended request that was received.
 *
 * @return  The result for the extended operation processing.
 */
@NotNull()
private static StartTransactionExtendedResult handleStartTransaction(@NotNull final InMemoryRequestHandler handler, final int messageID, @NotNull final ExtendedRequest request) {
    // If there is already an active transaction on the associated connection,
    // then make sure it gets aborted.
    final Map<String, Object> connectionState = handler.getConnectionState();
    final ObjectPair<?, ?> existingTxnInfo = (ObjectPair<?, ?>) connectionState.remove(STATE_VARIABLE_TXN_INFO);
    if (existingTxnInfo != null) {
        final ASN1OctetString txnID = (ASN1OctetString) existingTxnInfo.getFirst();
        try {
            handler.getClientConnection().sendUnsolicitedNotification(new AbortedTransactionExtendedResult(txnID, ResultCode.CONSTRAINT_VIOLATION, ERR_TXN_EXTOP_TXN_ABORTED_BY_NEW_START_TXN.get(txnID.stringValue()), null, null, null));
        } catch (final LDAPException le) {
            Debug.debugException(le);
            return new StartTransactionExtendedResult(new ExtendedResult(le));
        }
    }
    // request.
    try {
        new StartTransactionExtendedRequest(request);
    } catch (final LDAPException le) {
        Debug.debugException(le);
        return new StartTransactionExtendedResult(messageID, ResultCode.PROTOCOL_ERROR, le.getMessage(), null, null, null, null);
    }
    // Create a new object with information to use for the transaction.  It will
    // include the transaction ID and a list of LDAP messages that are part of
    // the transaction.  Store it in the connection state.
    final ASN1OctetString txnID = new ASN1OctetString(String.valueOf(TXN_ID_COUNTER.getAndIncrement()));
    final List<LDAPMessage> requestList = new ArrayList<>(10);
    final ObjectPair<ASN1OctetString, List<LDAPMessage>> txnInfo = new ObjectPair<>(txnID, requestList);
    connectionState.put(STATE_VARIABLE_TXN_INFO, txnInfo);
    // Return the response to the client.
    return new StartTransactionExtendedResult(messageID, ResultCode.SUCCESS, INFO_TXN_EXTOP_CREATED_TXN.get(txnID.stringValue()), null, null, txnID, null);
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) LDAPMessage(com.unboundid.ldap.protocol.LDAPMessage) ArrayList(java.util.ArrayList) ASN1OctetString(com.unboundid.asn1.ASN1OctetString) LDAPException(com.unboundid.ldap.sdk.LDAPException) StartTransactionExtendedResult(com.unboundid.ldap.sdk.extensions.StartTransactionExtendedResult) AbortedTransactionExtendedResult(com.unboundid.ldap.sdk.extensions.AbortedTransactionExtendedResult) ExtendedResult(com.unboundid.ldap.sdk.ExtendedResult) EndTransactionExtendedResult(com.unboundid.ldap.sdk.extensions.EndTransactionExtendedResult) StartTransactionExtendedResult(com.unboundid.ldap.sdk.extensions.StartTransactionExtendedResult) StartTransactionExtendedRequest(com.unboundid.ldap.sdk.extensions.StartTransactionExtendedRequest) ArrayList(java.util.ArrayList) List(java.util.List) ObjectPair(com.unboundid.util.ObjectPair) AbortedTransactionExtendedResult(com.unboundid.ldap.sdk.extensions.AbortedTransactionExtendedResult) NotNull(com.unboundid.util.NotNull)

Aggregations

StartTransactionExtendedRequest (com.unboundid.ldap.sdk.extensions.StartTransactionExtendedRequest)16 StartTransactionExtendedResult (com.unboundid.ldap.sdk.extensions.StartTransactionExtendedResult)16 ASN1OctetString (com.unboundid.asn1.ASN1OctetString)15 LDAPConnection (com.unboundid.ldap.sdk.LDAPConnection)15 LDAPConnectionOptions (com.unboundid.ldap.sdk.LDAPConnectionOptions)14 TestUnsolicitedNotificationHandler (com.unboundid.ldap.sdk.TestUnsolicitedNotificationHandler)14 Test (org.testng.annotations.Test)14 EndTransactionExtendedResult (com.unboundid.ldap.sdk.extensions.EndTransactionExtendedResult)13 TransactionSpecificationRequestControl (com.unboundid.ldap.sdk.controls.TransactionSpecificationRequestControl)12 EndTransactionExtendedRequest (com.unboundid.ldap.sdk.extensions.EndTransactionExtendedRequest)12 AddRequest (com.unboundid.ldap.sdk.AddRequest)9 DeleteRequest (com.unboundid.ldap.sdk.DeleteRequest)5 ModifyDNRequest (com.unboundid.ldap.sdk.ModifyDNRequest)5 ModifyRequest (com.unboundid.ldap.sdk.ModifyRequest)5 Control (com.unboundid.ldap.sdk.Control)4 PostReadRequestControl (com.unboundid.ldap.sdk.controls.PostReadRequestControl)4 PreReadRequestControl (com.unboundid.ldap.sdk.controls.PreReadRequestControl)4 LDAPException (com.unboundid.ldap.sdk.LDAPException)3 PostReadResponseControl (com.unboundid.ldap.sdk.controls.PostReadResponseControl)3 PreReadResponseControl (com.unboundid.ldap.sdk.controls.PreReadResponseControl)3