/
TransactionType.java
64 lines (50 loc) · 1.53 KB
/
TransactionType.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*
* Copyright (C) 2015 Archie L. Cobbs. All rights reserved.
*/
package io.permazen.kv.xodus;
import com.google.common.base.Preconditions;
import java.util.function.Function;
import jetbrains.exodus.env.Environment;
import jetbrains.exodus.env.Transaction;
/**
* Xodus transaction types.
*/
public enum TransactionType implements Function<Environment, Transaction> {
/**
* Read-only transaction.
*
* @see Environment#beginReadonlyTransaction
*/
READ_ONLY(true, false, Environment::beginReadonlyTransaction),
/**
* Normal read-write transaction.
*
* @see Environment#beginTransaction
*/
READ_WRITE(false, false, Environment::beginTransaction),
/**
* Exclusive read-write transaction.
*
* @see Environment#beginExclusiveTransaction
*/
READ_WRITE_EXCLUSIVE(false, true, Environment::beginExclusiveTransaction);
private final boolean readOnly;
private final boolean exclusive;
private final Function<Environment, Transaction> creator;
TransactionType(boolean readOnly, boolean exclusive, Function<Environment, Transaction> creator) {
this.readOnly = readOnly;
this.exclusive = exclusive;
this.creator = creator;
}
public boolean isReadOnly() {
return this.readOnly;
}
public boolean isExclusive() {
return this.exclusive;
}
@Override
public Transaction apply(Environment env) {
Preconditions.checkArgument(env != null, "null env");
return this.creator.apply(env);
}
}