001/*
002 * Copyright 2014-2018 Ping Identity Corporation
003 * All Rights Reserved.
004 */
005/*
006 * Copyright (C) 2015-2018 Ping Identity Corporation
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 */
021package com.unboundid.ldap.sdk.unboundidds.controls;
022
023
024
025import com.unboundid.util.StaticUtils;
026import com.unboundid.util.ThreadSafety;
027import com.unboundid.util.ThreadSafetyLevel;
028
029
030
031/**
032 * This enum defines the options that may be specified for the transaction
033 * commit durability when using the transaction settings request control.
034 * <BR>
035 * <BLOCKQUOTE>
036 *   <B>NOTE:</B>  This class, and other classes within the
037 *   {@code com.unboundid.ldap.sdk.unboundidds} package structure, are only
038 *   supported for use against Ping Identity, UnboundID, and
039 *   Nokia/Alcatel-Lucent 8661 server products.  These classes provide support
040 *   for proprietary functionality or for external specifications that are not
041 *   considered stable or mature enough to be guaranteed to work in an
042 *   interoperable way with other types of LDAP servers.
043 * </BLOCKQUOTE>
044 *
045 * @see TransactionSettingsRequestControl
046 */
047@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
048public enum TransactionSettingsCommitDurability
049{
050  /**
051   * Indicates that the commit should be non-synchronous.  Atomicity,
052   * consistency, and isolation will be maintained for the transaction, but
053   * there is no guarantee that the record of the transaction will be written
054   * to disk by the time operation processing is complete and the response has
055   * been returned to the client.  In the event of a JVM, operating system, or
056   * hardware failure before the transaction record is actually flushed to disk,
057   * then changes that are part of that transaction could be rolled back when
058   * the server is started back up.
059   */
060  NON_SYNCHRONOUS(0),
061
062
063
064  /**
065   * Indicates that the commit should be partially synchronous.  Atomicity,
066   * consistency, and isolation will be maintained for the transaction, and a
067   * record of the transaction will be written to disk during the commit, but
068   * that transaction record will not be synchronously flushed.  In the event of
069   * an operating system or hardware failure before the transaction record is
070   * actually flushed to disk, then changes that are part of that transaction
071   * could be rolled back when the server is started back up.
072   */
073  PARTIALLY_SYNCHRONOUS(1),
074
075
076
077  /**
078   * Indicates that the commit should be fully synchronous.  Atomicity,
079   * consistency, isolation, and durability will be maintained for the
080   * transaction, and a record of the transaction will be flushed to disk before
081   * the commit is completed.  In the event of a JVM, operating system, or
082   * hardware failure, then any changes that are part of that transaction will
083   * still be reflected in the database when the server is started back up (as
084   * long as the database files are still intact).
085   */
086  FULLY_SYNCHRONOUS(2);
087
088
089
090  // The integer value for this commit durability.
091  private final int intValue;
092
093
094
095  /**
096   * Creates a new transaction settings commit durability with the provided
097   * integer value.
098   *
099   * @param  intValue  The integer value for this commit durability.
100   */
101  TransactionSettingsCommitDurability(final int intValue)
102  {
103    this.intValue = intValue;
104  }
105
106
107
108  /**
109   * Retrieves the integer value for this transaction settings commit durability
110   * value.
111   *
112   * @return  The integer value for this transaction settings commit durability
113   *          value.
114   */
115  public int intValue()
116  {
117    return intValue;
118  }
119
120
121
122  /**
123   * Retrieves the commit durability value with the specified integer value.
124   *
125   * @param  intValue  The integer value for the commit durability to retrieve.
126   *
127   * @return  The commit durability value with the specified integer value, or
128   *          {@code null} if there is no such commit durability value.
129   */
130  public static TransactionSettingsCommitDurability valueOf(final int intValue)
131  {
132    for (final TransactionSettingsCommitDurability v : values())
133    {
134      if (v.intValue == intValue)
135      {
136        return v;
137      }
138    }
139
140    return null;
141  }
142
143
144
145  /**
146   * Retrieves the transaction settings commit durability with the specified
147   * name.
148   *
149   * @param  name  The name of the transaction settings commit durability to
150   *               retrieve.  It must not be {@code null}.
151   *
152   * @return  The requested transaction settings commit durability, or
153   *          {@code null} if no such durability is defined.
154   */
155  public static TransactionSettingsCommitDurability forName(final String name)
156  {
157    switch (StaticUtils.toLowerCase(name))
158    {
159      case "nonsynchronous":
160      case "non-synchronous":
161      case "non_synchronous":
162        return NON_SYNCHRONOUS;
163      case "partiallysynchronous":
164      case "partially-synchronous":
165      case "partially_synchronous":
166        return PARTIALLY_SYNCHRONOUS;
167      case "fullysynchronous":
168      case "fully-synchronous":
169      case "fully_synchronous":
170        return FULLY_SYNCHRONOUS;
171      default:
172        return null;
173    }
174  }
175}