4 import java.util.HashSet;
6 import javax.script.ScriptException;
7 import java.lang.NullPointerException;
10 class PendingTransaction {
12 static final byte Equal = Guard.Equal;
13 static final byte NotEqual = Guard.NotEqual;
15 private Set<KeyValue> keyValueUpdateSet;
18 public PendingTransaction() {
19 keyValueUpdateSet = new HashSet<KeyValue>();
24 * Add a new key value to the updates
27 public void addKV(KeyValue newKV) {
29 // Make sure there are no duplicates
30 for (KeyValue kv : keyValueUpdateSet) {
31 if (kv.getKey().equals(newKV.getKey())) {
33 // Remove key if we are adding a newer version of the same key
34 keyValueUpdateSet.remove(kv);
39 // Add the key to the hash set
40 keyValueUpdateSet.add(newKV);
44 * Get the key value update set
47 public Set<KeyValue> getKVUpdates() {
48 return keyValueUpdateSet;
55 public Guard getGuard() {
60 * Add a guard to this transaction
63 public void addGuard(Guard _guard) {
68 * Evaluate the guard expression for a given transaction using a set of key value pairs.
71 public boolean evaluate(Set<KeyValue> kvSet) throws ScriptException, NullPointerException {
73 // Evaluate the guard using the current KV Set
74 return guard.evaluate(kvSet);
78 * Add a boolean expression to the guard.
81 public void setGuardExpression(String expr) {
82 guard.setGuardExpression(expr);
86 * Trampoline static method.
89 public static String createExpression(IoTString keyName, IoTString keyValue, byte op) {
90 return Guard.createExpression(keyName, keyValue, op);