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);
}
Aggregations