KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > mdr > storagemodel > transientimpl > CompensatingTransaction


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20
21 package org.netbeans.mdr.storagemodel.transientimpl;
22 import java.util.Map JavaDoc;
23 import java.util.Collection JavaDoc;
24 import java.util.Iterator JavaDoc;
25 import org.netbeans.mdr.persistence.StorageException;
26 /**
27  *
28  * @author Tomas Zezula
29  */

30 public abstract class CompensatingTransaction {
31
32     protected Object JavaDoc key;
33     protected Object JavaDoc oldValue;
34
35     public CompensatingTransaction (Object JavaDoc key, Object JavaDoc oldValue) {
36         this.key = key;
37         this.oldValue = oldValue;
38     }
39
40     public abstract void perform (Object JavaDoc target) throws StorageException;
41
42     
43     public static class AddCTx extends CompensatingTransaction {
44         
45         public AddCTx (Object JavaDoc key, Object JavaDoc oldValue) {
46             super (key, oldValue);
47         }
48         
49         public void perform (Object JavaDoc target) throws StorageException {
50             ((TransactionalIndex)target).removeNoTx (key, oldValue);
51         }
52     }
53     
54     public static class RemoveCTx extends CompensatingTransaction {
55         
56         public RemoveCTx (Object JavaDoc key, Object JavaDoc oldValue) {
57             super (key, oldValue);
58         }
59         
60         public void perform (Object JavaDoc 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 JavaDoc key, Object JavaDoc value, int index) {
70             super (key, value);
71             this.index = index;
72         }
73         
74         public void perform (Object JavaDoc 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 JavaDoc key, Object JavaDoc value, int index) {
85             super (key, value);
86             this.index = index;
87         }
88         
89         public void perform (Object JavaDoc 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 JavaDoc key, Object JavaDoc value) {
97             super (key, value);
98         }
99         
100         public void perform (Object JavaDoc target) {
101             ((Map JavaDoc)target).remove (key);
102         }
103     }
104     
105     public static class DropIndexCTx extends CompensatingTransaction {
106         
107         public DropIndexCTx (Object JavaDoc key, Object JavaDoc value) {
108             super (key, value);
109         }
110         
111         public void perform (Object JavaDoc target) {
112             ((Map JavaDoc)target).put (key, oldValue);
113         }
114     }
115     
116     
117 }
118
Popular Tags