KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jalisto > se > impl > lock > ObjectTransactionnalState


1 /*
2  * Jalisto - JAva LIght STOrage
3  * Copyright (C) 2000-2005 Xcalia http://www.xcalia.com
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
18  *
19  * Xcalia
20  * 71, rue Desnouettes
21  * 75014 Paris - France
22  * http://www.xcalia.com
23  */

24 package org.objectweb.jalisto.se.impl.lock;
25
26 import org.objectweb.jalisto.se.api.internal.DataWrapper;
27
28 public class ObjectTransactionnalState {
29
30     public ObjectTransactionnalState(int currentAction, DataWrapper currentValue, short update) {
31         this.currentAction = currentAction;
32         this.currentValue = currentValue;
33         this.update = update;
34     }
35
36
37     public int getCurrentAction() {
38         return currentAction;
39     }
40
41     public boolean isReadAction() {
42         return (currentAction == READ_ACTION);
43     }
44
45     public boolean isCreateAction() {
46         return (currentAction == CREATE_ACTION);
47     }
48
49
50     public DataWrapper getCurrentValue() {
51         return currentValue;
52     }
53
54     public void setValue(int action, DataWrapper currentValue) {
55         if ((action != READ_ACTION) || (currentAction == READ_ACTION)) {
56             this.currentValue = currentValue;
57             currentAction = action;
58         }
59     }
60
61
62     public void update() {
63         update++;
64     }
65
66     public short getUpdate() {
67         return update;
68     }
69
70     public void setUpdate(short update) {
71         if (update != (short) -1) {
72             this.update = update;
73         }
74     }
75
76
77     public String JavaDoc toString() {
78         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
79         sb.append("ITImage : ").append(getActionAsString(currentAction)).append(", ");
80         sb.append(currentValue).append(", update=").append(update);
81         return sb.toString();
82     }
83
84     private String JavaDoc getActionAsString(int action) {
85         if (action == NO_ACTION) {
86             return "no_action";
87         } else if (action == NEW_OID_ACTION) {
88             return "new_action";
89         } else if (action == CREATE_ACTION) {
90             return "create_action";
91         } else if (action == UPDATE_ACTION) {
92             return "update_action";
93         } else if (action == DELETE_ACTION) {
94             return "delete_action";
95         } else {
96             return "read_action";
97         }
98     }
99
100
101     private DataWrapper currentValue;
102     private int currentAction;
103     private short update;
104
105
106     public static final int NO_ACTION = 0;
107     public static final int NEW_OID_ACTION = 1;
108     public static final int CREATE_ACTION = 2;
109     public static final int UPDATE_ACTION = 3;
110     public static final int DELETE_ACTION = 4;
111     public static final int READ_ACTION = 5;
112 }
113
Popular Tags