001 /* 002 * Copyright 2007-2015 UnboundID Corp. 003 * All Rights Reserved. 004 */ 005 /* 006 * Copyright (C) 2015 UnboundID Corp. 007 * 008 * This program is free software; you can redistribute it and/or modify 009 * it under the terms of the GNU General Public License (GPLv2 only) 010 * or the terms of the GNU Lesser General Public License (LGPLv2.1 only) 011 * as published by the Free Software Foundation. 012 * 013 * This program is distributed in the hope that it will be useful, 014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 016 * GNU General Public License for more details. 017 * 018 * You should have received a copy of the GNU General Public License 019 * along with this program; if not, see <http://www.gnu.org/licenses>. 020 */ 021 package com.unboundid.ldap.sdk.unboundidds.controls; 022 023 024 025 import com.unboundid.asn1.ASN1OctetString; 026 import com.unboundid.ldap.sdk.Control; 027 import com.unboundid.ldap.sdk.LDAPException; 028 import com.unboundid.ldap.sdk.ResultCode; 029 import com.unboundid.ldap.sdk.unboundidds.extensions. 030 StartBatchedTransactionExtendedRequest; 031 import com.unboundid.util.NotMutable; 032 import com.unboundid.util.ThreadSafety; 033 import com.unboundid.util.ThreadSafetyLevel; 034 035 import static com.unboundid.ldap.sdk.unboundidds.controls.ControlMessages.*; 036 import static com.unboundid.util.Validator.*; 037 038 039 040 /** 041 * <BLOCKQUOTE> 042 * <B>NOTE:</B> This class is part of the Commercial Edition of the UnboundID 043 * LDAP SDK for Java. It is not available for use in applications that 044 * include only the Standard Edition of the LDAP SDK, and is not supported for 045 * use in conjunction with non-UnboundID products. 046 * </BLOCKQUOTE> 047 * This class provides an implementation of the batched transaction 048 * specification request control, which may be used to indicate that the 049 * associated add, delete, modify, modify DN, or password modify operation is 050 * part of a batched transaction. The transaction should be created with the 051 * start batched transaction extended operation, which will obtain a transaction 052 * ID, and the transaction may be committed or aborted using the end batched 053 * transaction extended operation. 054 * <BR><BR> 055 * See the documentation for the {@link StartBatchedTransactionExtendedRequest} 056 * class for an example of processing a batched transaction. 057 */ 058 @NotMutable() 059 @ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE) 060 public final class BatchedTransactionSpecificationRequestControl 061 extends Control 062 { 063 /** 064 * The OID (1.3.6.1.4.1.30221.2.5.1) for the batched transaction specification 065 * request control. 066 */ 067 public static final String BATCHED_TRANSACTION_SPECIFICATION_REQUEST_OID = 068 "1.3.6.1.4.1.30221.2.5.1"; 069 070 071 072 /** 073 * The serial version UID for this serializable class. 074 */ 075 private static final long serialVersionUID = -6817702055586260189L; 076 077 078 079 // The transaction ID for the associated transaction. 080 private final ASN1OctetString transactionID; 081 082 083 084 // This is an ugly hack to prevent checkstyle from complaining about the 085 // import for the StartBatchedTransactionExtendedRequest class. It is used 086 // by the @link element in the javadoc, but checkstyle apparently doesn't 087 // recognize that so we just need to use it in some way in this class to 088 // placate checkstyle. 089 static 090 { 091 final StartBatchedTransactionExtendedRequest r = null; 092 } 093 094 095 096 /** 097 * Creates a new batched transaction specification request control with the 098 * provided transaction ID. 099 * 100 * @param transactionID The transaction ID for the associated transaction, 101 * as obtained from the start batched transaction 102 * extended operation. It must not be {@code null}. 103 */ 104 public BatchedTransactionSpecificationRequestControl( 105 final ASN1OctetString transactionID) 106 { 107 super(BATCHED_TRANSACTION_SPECIFICATION_REQUEST_OID, true, 108 new ASN1OctetString(transactionID.getValue())); 109 110 this.transactionID = transactionID; 111 } 112 113 114 115 /** 116 * Creates a new batched transaction specification request control which is 117 * decoded from the provided generic control. 118 * 119 * @param control The generic control to be decoded as a batched transaction 120 * specification request control. 121 * 122 * @throws LDAPException If the provided control cannot be decoded as a 123 * batched transaction specification request control. 124 */ 125 public BatchedTransactionSpecificationRequestControl(final Control control) 126 throws LDAPException 127 { 128 super(control); 129 130 transactionID = control.getValue(); 131 if (transactionID == null) 132 { 133 throw new LDAPException(ResultCode.DECODING_ERROR, 134 ERR_TXN_REQUEST_CONTROL_NO_VALUE.get()); 135 } 136 } 137 138 139 140 /** 141 * Retrieves the transaction ID for the associated transaction. 142 * 143 * @return The transaction ID for the associated transaction. 144 */ 145 public ASN1OctetString getTransactionID() 146 { 147 return transactionID; 148 } 149 150 151 152 /** 153 * {@inheritDoc} 154 */ 155 @Override() 156 public String getControlName() 157 { 158 return INFO_CONTROL_NAME_BATCHED_TXN_REQUEST.get(); 159 } 160 161 162 163 /** 164 * {@inheritDoc} 165 */ 166 @Override() 167 public void toString(final StringBuilder buffer) 168 { 169 buffer.append("BatchedTransactionSpecificationRequestControl(" + 170 "transactionID='"); 171 buffer.append(transactionID.stringValue()); 172 buffer.append("')"); 173 } 174 }