001/*
002 * Copyright 2025 Ping Identity Corporation
003 * All Rights Reserved.
004 */
005/*
006 * Copyright 2025 Ping Identity Corporation
007 *
008 * Licensed under the Apache License, Version 2.0 (the "License");
009 * you may not use this file except in compliance with the License.
010 * You may obtain a copy of the License at
011 *
012 *    http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing, software
015 * distributed under the License is distributed on an "AS IS" BASIS,
016 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017 * See the License for the specific language governing permissions and
018 * limitations under the License.
019 */
020/*
021 * Copyright (C) 2025 Ping Identity Corporation
022 *
023 * This program is free software; you can redistribute it and/or modify
024 * it under the terms of the GNU General Public License (GPLv2 only)
025 * or the terms of the GNU Lesser General Public License (LGPLv2.1 only)
026 * as published by the Free Software Foundation.
027 *
028 * This program is distributed in the hope that it will be useful,
029 * but WITHOUT ANY WARRANTY; without even the implied warranty of
030 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
031 * GNU General Public License for more details.
032 *
033 * You should have received a copy of the GNU General Public License
034 * along with this program; if not, see <http://www.gnu.org/licenses>.
035 */
036package com.unboundid.ldap.sdk.unboundidds.controls;
037
038
039
040import java.io.Serializable;
041
042import com.unboundid.util.Mutable;
043import com.unboundid.util.NotNull;
044import com.unboundid.util.Nullable;
045import com.unboundid.util.ThreadSafety;
046import com.unboundid.util.ThreadSafetyLevel;
047
048
049
050/**
051 * This class defines a number of properties for use in conjunction with the
052 * {@link TransactionSettingsRequestControl}.
053 * <BR>
054 * <BLOCKQUOTE>
055 *   <B>NOTE:</B>  This class, and other classes within the
056 *   {@code com.unboundid.ldap.sdk.unboundidds} package structure, are only
057 *   supported for use against Ping Identity, UnboundID, and
058 *   Nokia/Alcatel-Lucent 8661 server products.  These classes provide support
059 *   for proprietary functionality or for external specifications that are not
060 *   considered stable or mature enough to be guaranteed to work in an
061 *   interoperable way with other types of LDAP servers.
062 * </BLOCKQUOTE>
063 */
064@Mutable()
065@ThreadSafety(level=ThreadSafetyLevel.NOT_THREADSAFE)
066public final class TransactionSettingsReqeustControlProperties
067       implements Serializable
068{
069  /**
070   * The serial version UID for this serializable class.
071   */
072  private static final long serialVersionUID = -1124435803639477902L;
073
074
075
076  // Indicates whether the settings in this control should be considered when
077  // the operation is replicated to other servers in the topology.
078  private boolean replicateControl;
079
080  // Indicates whether to return a response control.
081  private boolean returnResponseControl;
082
083  // The number of times to retry if a lock conflict exception is encountered.
084  @Nullable private Integer retryAttempts;
085
086  // The backend lock timeout, in milliseconds.
087  @Nullable private Long backendLockTimeoutMillis;
088
089  // The maximum transaction lock timeout, in milliseconds.
090  @Nullable private Long maxTxnLockTimeoutMillis;
091
092  // The minimum transaction lock timeout, in milliseconds.
093  @Nullable private Long minTxnLockTimeoutMillis;
094
095  // The requested transaction name.
096  @Nullable private String transactionName;
097
098  // The behavior to use with regard to requesting the exclusive backend lock.
099  @Nullable private TransactionSettingsBackendLockBehavior
100       backendExclusiveLockBehavior;
101
102  // The behavior to use with regard to requesting the single-writer backend
103  // lock.
104  @Nullable private TransactionSettingsBackendLockBehavior
105       singleWriterLockBehavior;
106
107  // The requested commit durability setting.
108  @Nullable private TransactionSettingsCommitDurability commitDurability;
109
110  // The behavior to use with regard to requesting the scoped lock.
111  @Nullable private TransactionSettingsScopedLockDetails scopedLockDetails;
112
113
114
115  /**
116   * Creates a new set of properties with all default values.
117   */
118  public TransactionSettingsReqeustControlProperties()
119  {
120    replicateControl = false;
121    returnResponseControl = false;
122    retryAttempts = null;
123    backendLockTimeoutMillis = null;
124    maxTxnLockTimeoutMillis = null;
125    minTxnLockTimeoutMillis = null;
126    transactionName = null;
127    backendExclusiveLockBehavior = null;
128    singleWriterLockBehavior = null;
129    commitDurability = null;
130    scopedLockDetails = null;
131  }
132
133
134
135  /**
136   * Retrieves the name to assign to the associated transaction, if specified.
137   *
138   * @return  The name to assign to the associated transaction, or {@code null}
139   *          if none has been specified.
140   */
141  @Nullable()
142  public String getTransactionName()
143  {
144    return transactionName;
145  }
146
147
148
149  /**
150   * Specifies the name to assign to the associated transaction.
151   *
152   * @param  transactionName  The name to assign to the associated transaction,
153   *                          or {@code null} if no transaction name should be
154   *                          used.
155   */
156  public void setTransactionName(@Nullable final String transactionName)
157  {
158    this.transactionName = transactionName;
159  }
160
161
162
163  /**
164   * Retrieves the commit durability that should be used for the associated
165   * transaction, if specified.
166   *
167   * @return  The commit durability that should be used for the associated
168   *          transaction, or {@code null} if none has been specified and the
169   *          server should determine the commit durability.
170   */
171  @Nullable()
172  public TransactionSettingsCommitDurability getCommitDurability()
173  {
174    return commitDurability;
175  }
176
177
178
179  /**
180   * Specifies the commit durability that should be used for the associated
181   * transaction.
182   *
183   * @param  commitDurability  The commit durability that should be used for
184   *                           the associated transaction.  It may be
185   *                           {@code null} if the server should determine the
186   *                           commit durability.
187   */
188  public void setCommitDurability(
189       @Nullable final TransactionSettingsCommitDurability
190            commitDurability)
191  {
192    this.commitDurability = commitDurability;
193  }
194
195
196
197  /**
198   * Retrieves the backend exclusive lock behavior that should be used for the
199   * associated transaction, if specified.
200   *
201   * @return  The backend exclusive lock behavior that should be used for the
202   *          associated transaction, or {@code null} if none has been specified
203   *          and the server should determine the backend exclusive lock
204   *          behavior.
205   */
206  @Nullable()
207  public TransactionSettingsBackendLockBehavior
208              getBackendExclusiveLockBehavior()
209  {
210    return backendExclusiveLockBehavior;
211  }
212
213
214
215  /**
216   * Specifies the backend exclusive lock behavior that should be used for the
217   * associated transaction.
218   *
219   * @param  backendExclusiveLockBehavior  The backend exclusive lock behavior
220   *                                       that should be used for the
221   *                                       associated transaction.  It may be
222   *                                       {@code null} if the server should
223   *                                       determine the backend exclusive
224   *                                       lock behavior.
225   */
226  public void setBackendExclusiveLockBehavior(
227       @Nullable final TransactionSettingsBackendLockBehavior
228            backendExclusiveLockBehavior)
229  {
230    this.backendExclusiveLockBehavior = backendExclusiveLockBehavior;
231  }
232
233
234
235  /**
236   * Retrieves the single-writer lock behavior that should be used for the
237   * associated transaction, if specified.
238   *
239   * @return  The single-writer lock behavior that should be used for the
240   *          associated transaction, or {@code null} if none has been specified
241   *          and the server should determine the backend exclusive lock
242   *          behavior.
243   */
244  @Nullable()
245  public TransactionSettingsBackendLockBehavior getSingleWriterLockBehavior()
246  {
247    return singleWriterLockBehavior;
248  }
249
250
251
252  /**
253   * Specifies the single-writer lock behavior that should be used for the
254   * associated transaction.
255   *
256   * @param  singleWriterLockBehavior  The single-writer lock behavior that
257   *                                   should be used for the associated
258   *                                   transaction.  It may be {@code null} if
259   *                                   the server should determine the
260   *                                   single-writer lock behavior.
261   */
262  public void setSingleWriterLockBehavior(
263       @Nullable final TransactionSettingsBackendLockBehavior
264            singleWriterLockBehavior)
265  {
266    this.singleWriterLockBehavior = singleWriterLockBehavior;
267  }
268
269
270
271  /**
272   * Retrieves details about the conditions under which to attempt to acquire a
273   * scoped lock, if any.
274   *
275   * @return  Details about the conditions under which to attempt to acquire a
276   *          scoped lock, or {@code null} if no attempt should be made to
277   *          acquire a scoped lock.
278   */
279  @Nullable()
280  public TransactionSettingsScopedLockDetails getScopedLockDetails()
281  {
282    return scopedLockDetails;
283  }
284
285
286
287  /**
288   * Specifies details about the conditions under which to attempt to acquire a
289   * scoped lock.
290   *
291   * @param  scopedLockDetails  Details about the conditions under which to
292   *                            attempt to acquire a scoped lock.  It may be
293   *                            {@code null} if no attempt should be made to
294   *                            acquire a scoped lock.
295   */
296  public void setScopedLockDetails(
297       @Nullable final TransactionSettingsScopedLockDetails scopedLockDetails)
298  {
299    this.scopedLockDetails = scopedLockDetails;
300  }
301
302
303
304  /**
305   * Retrieves the maximum length of time (in milliseconds) that the server
306   * may block while attempting to acquire the backend exclusive, single-writer,
307   * or scoped lock, if applicable.
308   *
309   * @return  The backend lock timeout (in milliseconds) that should be used for
310   *          the associated transaction, or {@code null} if none has been
311   *          specified and the server should determine the backend lock
312   *          timeout.
313   */
314  @Nullable()
315  public Long getBackendLockTimeoutMillis()
316  {
317    return backendLockTimeoutMillis;
318  }
319
320
321
322  /**
323   * Specifies the maximum length of time (in milliseconds) that the server
324   * may block while attempting to acquire the backend exclusive, single-writer,
325   * or scoped lock.
326   *
327   * @param  backendLockTimeoutMillis  The maximum length of time (in
328   *                                   milliseconds) that the server may block
329   *                                   while attempting to acquire the backend
330   *                                   exclusive, single-writer, or scoped lock.
331   *                                   It may be {@code null} if the server
332   *                                   should automatically determine the
333   *                                   backend lock timeout.
334   */
335  public void setBackendLockTimeoutMillis(
336       @Nullable final Long backendLockTimeoutMillis)
337  {
338    this.backendLockTimeoutMillis = backendLockTimeoutMillis;
339  }
340
341
342
343  /**
344   * Retrieves the maximum number of times that the transaction may be retried
345   * if the initial attempt fails due to a lock conflict, if specified.
346   *
347   * @return  The maximum number of times that the transaction may be retried if
348   *          the initial attempt fails due to a lock conflict, or {@code null}
349   *          if none has been specified and the server should determine the
350   *          number of retry attempts.
351   */
352  @Nullable()
353  public Integer getRetryAttempts()
354  {
355    return retryAttempts;
356  }
357
358
359
360  /**
361   * Specifies the maximum number of times that the transaction may be retried
362   * if the initial attempt fails due to a lock conflict.
363   *
364   * @param  retryAttempts  The maximum number of times that the transaction may
365   *                        be retried if the initial attempt fails due to a
366   *                        lock conflict.  It may be {@code null} if the server
367   *                        should determine the number of retry attempts.
368   */
369  public void setRetryAttempts(@Nullable final Integer retryAttempts)
370  {
371    this.retryAttempts = retryAttempts;
372  }
373
374
375
376  /**
377   * Retrieves the minimum transaction lock timeout (in milliseconds) that
378   * should be used for the associated transaction, if specified.  This is the
379   * timeout value that will be used for the first attempt.  Any subsequent
380   * attempts will have a lock timeout that is between the minimum and maximum
381   * timeout value.
382   *
383   * @return  The minimum lock timeout (in milliseconds) that should
384   *          be used for the associated transaction, or {@code null} if none
385   *          has been specified and the server should determine the minimum
386   *          transaction lock timeout.
387   */
388  @Nullable()
389  public Long getMinTxnLockTimeoutMillis()
390  {
391    return minTxnLockTimeoutMillis;
392  }
393
394
395
396  /**
397   * Specifies the minimum transaction lock timeout (in milliseconds) that
398   * should be used for the associated transaction.  This is the timeout value
399   * that will be used for the first attempt.  Any subsequent attempts will have
400   * a lock timeout that is between the minimum and maximum timeout value.
401   *
402   * @param  minTxnLockTimeoutMillis  The minimum lock timeout (in milliseconds)
403   *                                  that should be used for the associated
404   *                                  transaction.  It may be {@code null} if
405   *                                  the server should determine the minimum
406   *                                  transaction lock timeout.
407   */
408  public void setMinTxnLockTimeoutMillis(
409       @Nullable final Long minTxnLockTimeoutMillis)
410  {
411    this.minTxnLockTimeoutMillis = minTxnLockTimeoutMillis;
412  }
413
414
415
416  /**
417   * Retrieves the maximum transaction lock timeout (in milliseconds) that
418   * should be used for the associated transaction, if specified.  The timeout
419   * to be used for any retries will be between the minimum and maximum lock
420   * timeout values.
421   *
422   * @return  The maximum lock timeout (in milliseconds) that should
423   *          be used for the associated transaction, or {@code null} if none
424   *          has been specified and the server should determine the maximum
425   *          transaction lock timeout.
426   */
427  @Nullable()
428  public Long getMaxTxnLockTimeoutMillis()
429  {
430    return maxTxnLockTimeoutMillis;
431  }
432
433
434
435  /**
436   * Specifies the maximum transaction lock timeout (in milliseconds) that
437   * should be used for the associated transaction.  The timeout to be used for
438   * any retries will be between the minimum and maximum lock timeout values.
439   *
440   * @param maxTxnLockTimeoutMillis  The maximum lock timeout (in milliseconds)
441   *                                 that should be used for the associated
442   *                                 transaction.  It may be {@code null} if the
443   *                                 server should determine the maximum
444   *                                 transaction lock timeout.
445   */
446  public void setMaxTxnLockTimeoutMillis(
447       @Nullable final Long maxTxnLockTimeoutMillis)
448  {
449    this.maxTxnLockTimeoutMillis = maxTxnLockTimeoutMillis;
450  }
451
452
453
454  /**
455   * Indicates whether the settings in this control should be considered when
456   * the operation is replicated to other servers in the topology.
457   *
458   * @return  {@code true} if the control settings should be replicated, or
459   *          {@code false} if not.
460   */
461  public boolean replicateControl()
462  {
463    return replicateControl;
464  }
465
466
467
468  /**
469   * Specifies whether the settings in this control should be considered when
470   * the operation is replicated to other servers in the topology.
471   *
472   * @param  replicateControl  Indicates whether the settings in this control
473   *                           should be considered when the operation is
474   *                           replicated to other servers in the topology.
475   */
476  public void setReplicateControl(final boolean replicateControl)
477  {
478    this.replicateControl = replicateControl;
479  }
480
481
482
483  /**
484   * Indicates whether to return a response control with transaction-related
485   * information collected over the course of processing the associated
486   * operation.
487   *
488   * @return  {@code true} if the server should return a response control with
489   *          transaction-related information, or {@code false} if not.
490   */
491  public boolean getReturnResponseControl()
492  {
493    return returnResponseControl;
494  }
495
496
497
498  /**
499   * Indicates whether to return a response control with transaction-related
500   * information collected over the course of processing the associated
501   * operation.
502   *
503   * @param  returnResponseControl  Specifies whether the server should return a
504   *                                response control with transaction-related
505   *                                information.
506   */
507  public void setReturnResponseControl(final boolean returnResponseControl)
508  {
509    this.returnResponseControl = returnResponseControl;
510  }
511
512
513
514  /**
515   * Retrieves a string representation of the transaction settings request
516   * control properties.
517   *
518   * @return  A string representation of the transaction settings request
519   *          control properties.
520   */
521  @NotNull()
522  public String toString()
523  {
524    final StringBuilder buffer = new StringBuilder();
525    toString(buffer);
526    return buffer.toString();
527  }
528
529
530
531  /**
532   * Appends a string representation of the transaction settings request control
533   * properties to the provided buffer.
534   *
535   * @param  buffer  The buffer to which the string representation should be
536   *                 appended.  It must not be {@code null}.
537   */
538  public void toString(@NotNull final StringBuilder buffer)
539  {
540    buffer.append("TransactionSettingsReqeustControlProperties(");
541
542    boolean appended = false;
543    if (transactionName != null)
544    {
545      buffer.append("transactionName='");
546      buffer.append(transactionName);
547      buffer.append('\'');
548      appended = true;
549
550    }
551
552    if (commitDurability != null)
553    {
554      if (appended)
555      {
556        buffer.append(", ");
557      }
558
559      buffer.append("commitDurability='");
560      buffer.append(commitDurability.name());
561      buffer.append('\'');
562      appended = true;
563    }
564
565
566    if (backendExclusiveLockBehavior != null)
567    {
568      if (appended)
569      {
570        buffer.append(", ");
571      }
572
573      buffer.append("backendExclusiveLockBehavior='");
574      buffer.append(backendExclusiveLockBehavior.name());
575      buffer.append('\'');
576      appended = true;
577    }
578
579
580    if (singleWriterLockBehavior != null)
581    {
582      if (appended)
583      {
584        buffer.append(", ");
585      }
586
587      buffer.append("singleWriterLockBehavior='");
588      buffer.append(singleWriterLockBehavior.name());
589      buffer.append('\'');
590      appended = true;
591    }
592
593
594    if (scopedLockDetails != null)
595    {
596      if (appended)
597      {
598        buffer.append(", ");
599      }
600
601      buffer.append("scopedLockDetails=");
602      scopedLockDetails.toString(buffer);
603      appended = true;
604    }
605
606
607    if (backendLockTimeoutMillis != null)
608    {
609      if (appended)
610      {
611        buffer.append(", ");
612      }
613
614      buffer.append("backendLockTimeoutMillis=");
615      buffer.append(backendLockTimeoutMillis);
616      appended = true;
617    }
618
619
620    if (retryAttempts != null)
621    {
622      if (appended)
623      {
624        buffer.append(", ");
625      }
626
627      buffer.append("retryAttempts=");
628      buffer.append(retryAttempts);
629      appended = true;
630    }
631
632
633    if (minTxnLockTimeoutMillis != null)
634    {
635      if (appended)
636      {
637        buffer.append(", ");
638      }
639
640      buffer.append("minTxnLockTimeoutMillis=");
641      buffer.append(minTxnLockTimeoutMillis);
642      appended = true;
643    }
644
645
646    if (maxTxnLockTimeoutMillis != null)
647    {
648      if (appended)
649      {
650        buffer.append(", ");
651      }
652
653      buffer.append("maxTxnLockTimeoutMillis=");
654      buffer.append(maxTxnLockTimeoutMillis);
655      appended = true;
656    }
657
658
659    if (appended)
660    {
661      buffer.append(", ");
662    }
663
664    buffer.append("replicateControl=");
665    buffer.append(replicateControl);
666    buffer.append(", returnResponseControl=");
667    buffer.append(returnResponseControl);
668    buffer.append(')');
669  }
670}