]>
Commit | Line | Data |
---|---|---|
11fdf7f2 TL |
1 | // Copyright (c) 2011-present, Facebook, Inc. All rights reserved. |
2 | // This source code is licensed under both the GPLv2 (found in the | |
3 | // COPYING file in the root directory) and Apache 2.0 License | |
4 | // (found in the LICENSE.Apache file in the root directory). | |
5 | package org.rocksdb; | |
6 | ||
7 | /** | |
8 | * The transaction db write policy. | |
9 | */ | |
10 | public enum TxnDBWritePolicy { | |
11 | /** | |
12 | * Write only the committed data. | |
13 | */ | |
14 | WRITE_COMMITTED((byte)0x00), | |
15 | ||
16 | /** | |
17 | * Write data after the prepare phase of 2pc. | |
18 | */ | |
19 | WRITE_PREPARED((byte)0x1), | |
20 | ||
21 | /** | |
22 | * Write data before the prepare phase of 2pc. | |
23 | */ | |
24 | WRITE_UNPREPARED((byte)0x2); | |
25 | ||
26 | private byte value; | |
27 | ||
28 | TxnDBWritePolicy(final byte value) { | |
29 | this.value = value; | |
30 | } | |
31 | ||
32 | /** | |
33 | * <p>Returns the byte value of the enumerations value.</p> | |
34 | * | |
35 | * @return byte representation | |
36 | */ | |
37 | public byte getValue() { | |
38 | return value; | |
39 | } | |
40 | ||
41 | /** | |
42 | * <p>Get the TxnDBWritePolicy enumeration value by | |
43 | * passing the byte identifier to this method.</p> | |
44 | * | |
45 | * @param byteIdentifier of TxnDBWritePolicy. | |
46 | * | |
47 | * @return TxnDBWritePolicy instance. | |
48 | * | |
49 | * @throws IllegalArgumentException If TxnDBWritePolicy cannot be found for | |
50 | * the provided byteIdentifier | |
51 | */ | |
52 | public static TxnDBWritePolicy getTxnDBWritePolicy(final byte byteIdentifier) { | |
53 | for (final TxnDBWritePolicy txnDBWritePolicy : TxnDBWritePolicy.values()) { | |
54 | if (txnDBWritePolicy.getValue() == byteIdentifier) { | |
55 | return txnDBWritePolicy; | |
56 | } | |
57 | } | |
58 | ||
59 | throw new IllegalArgumentException( | |
60 | "Illegal value provided for TxnDBWritePolicy."); | |
61 | } | |
62 | } |