1 19 20 21 package org.netbeans.mdr.storagemodel.transientimpl; 22 import java.util.Map ; 23 import java.util.Collection ; 24 import java.util.Iterator ; 25 import org.netbeans.mdr.persistence.StorageException; 26 30 public abstract class CompensatingTransaction { 31 32 protected Object key; 33 protected Object oldValue; 34 35 public CompensatingTransaction (Object key, Object oldValue) { 36 this.key = key; 37 this.oldValue = oldValue; 38 } 39 40 public abstract void perform (Object target) throws StorageException; 41 42 43 public static class AddCTx extends CompensatingTransaction { 44 45 public AddCTx (Object key, Object oldValue) { 46 super (key, oldValue); 47 } 48 49 public void perform (Object target) throws StorageException { 50 ((TransactionalIndex)target).removeNoTx (key, oldValue); 51 } 52 } 53 54 public static class RemoveCTx extends CompensatingTransaction { 55 56 public RemoveCTx (Object key, Object oldValue) { 57 super (key, oldValue); 58 } 59 60 public void perform (Object target) throws StorageException { 61 ((TransactionalIndex)target).addNoTx (key, oldValue); 62 } 63 } 64 65 public static class AddOrderedCTx extends AddCTx { 66 67 int index; 68 69 public AddOrderedCTx (Object key, Object value, int index) { 70 super (key, value); 71 this.index = index; 72 } 73 74 public void perform (Object target) throws StorageException { 75 ((TransientMultivaluedOrderedIndex)target).removeNoTx (key, oldValue, index); 76 } 77 78 } 79 80 public static class RemoveOrderedCTx extends RemoveCTx { 81 82 int index; 83 84 public RemoveOrderedCTx (Object key, Object value, int index) { 85 super (key, value); 86 this.index = index; 87 } 88 89 public void perform (Object target) throws StorageException { 90 ((TransientMultivaluedOrderedIndex)target).addNoTx (key, oldValue, index); 91 } 92 } 93 94 public static class CreateIndexCTx extends CompensatingTransaction { 95 96 public CreateIndexCTx (Object key, Object value) { 97 super (key, value); 98 } 99 100 public void perform (Object target) { 101 ((Map )target).remove (key); 102 } 103 } 104 105 public static class DropIndexCTx extends CompensatingTransaction { 106 107 public DropIndexCTx (Object key, Object value) { 108 super (key, value); 109 } 110 111 public void perform (Object target) { 112 ((Map )target).put (key, oldValue); 113 } 114 } 115 116 117 } 118 | Popular Tags |