1 18 package org.objectweb.perseus.persistence.api; 19 20 24 public class WorkingSetLifeCycle { 25 26 public final static byte ACTIVE_ACTION = 1; 27 public final static byte BEGIN_TX_ACTION = 2; 28 public final static byte COMMIT_ACTION = 3; 29 public final static byte ROLLBACK_ACTION = 4; 30 public final static byte CLOSE_ACTION = 5; 31 public final static byte PREPARE_ACTION = 6; 32 public final static byte PREPARE_OK_ACTION = 7; 33 public final static byte PREPARE_FAIL_ACTION = 8; 34 35 public static final String actionToString(byte action) { 36 switch (action) { 37 case ACTIVE_ACTION: return "ACTIVE_ACTION"; 38 case BEGIN_TX_ACTION: return "BEGIN_TX_ACTION"; 39 case PREPARE_ACTION: return "PREPARE_ACTION"; 40 case PREPARE_OK_ACTION: return "PREPARE_OK_ACTION"; 41 case PREPARE_FAIL_ACTION: return "PREPARE_FAIL_ACTION"; 42 case COMMIT_ACTION: return "COMMIT_ACTION"; 43 case ROLLBACK_ACTION: return "ROLLBACK_ACTION"; 44 case CLOSE_ACTION: return "CLOSE_ACTION"; 45 default: return "UNKNOWN ACTION(" + action + ")"; 46 } 47 } 48 49 public static final String statusToString(byte status) { 50 switch(status){ 51 case WorkingSet.CTX_ACTIVE: return "CTX_ACTIVE"; 52 case TransactionalWorkingSet.CTX_ACTIVE_TRANSACTIONAL: return "CTX_ACTIVE_TRANSACTIONAL"; 53 case TransactionalWorkingSet.CTX_PREPARED: return "CTX_PREPARED"; 54 case TransactionalWorkingSet.CTX_PREPARED_OK: return "CTX_PREPARED_OK"; 55 case TransactionalWorkingSet.CTX_PREPARED_FAIL: return "CTX_PREPARED_FAIL"; 56 case TransactionalWorkingSet.CTX_COMMITTED: return "CTX_COMMITTED"; 57 case TransactionalWorkingSet.CTX_ABORTED: return "CTX_ABORTED"; 58 case WorkingSet.CTX_CLOSED: return "CTX_CLOSED"; 59 default: return "UNKNOWN STATUS(" + status + ")"; 60 } 61 } 62 63 public static byte getNextStatus(byte status, byte action) 64 throws PersistenceException { 65 switch (status) { 66 case WorkingSet.CTX_ACTIVE: 67 switch (action) { 68 case ACTIVE_ACTION: 69 return WorkingSet.CTX_ACTIVE; 70 case BEGIN_TX_ACTION: 71 return TransactionalWorkingSet.CTX_ACTIVE_TRANSACTIONAL; 72 case CLOSE_ACTION: 73 return WorkingSet.CTX_CLOSED; 74 case PREPARE_ACTION: 75 return TransactionalWorkingSet.CTX_PREPARED; 76 case COMMIT_ACTION: return TransactionalWorkingSet.CTX_COMMITTED; 78 case ROLLBACK_ACTION: return TransactionalWorkingSet.CTX_ABORTED; 80 default: 81 throw new PersistenceException("Illegal action on a transaction" 82 + " ( " + statusToString(status) 83 + ", " + actionToString(action) + ")"); 84 } 85 86 case TransactionalWorkingSet.CTX_ACTIVE_TRANSACTIONAL: 87 switch (action) { 88 case PREPARE_ACTION: 89 return TransactionalWorkingSet.CTX_PREPARED; 90 case COMMIT_ACTION: return TransactionalWorkingSet.CTX_COMMITTED; 92 case ROLLBACK_ACTION: return TransactionalWorkingSet.CTX_ABORTED; 94 default: 95 throw new PersistenceException("Illegal action on a transaction" 96 + " ( " + statusToString(status) 97 + ", " + actionToString(action) + ")"); 98 } 99 100 case TransactionalWorkingSet.CTX_PREPARED: 101 switch (action) { 102 case PREPARE_FAIL_ACTION: 103 return TransactionalWorkingSet.CTX_PREPARED_FAIL; 104 case PREPARE_OK_ACTION: 105 return TransactionalWorkingSet.CTX_PREPARED_OK; 106 default: 107 throw new PersistenceException("Illegal action on a transaction" 108 + " ( " + statusToString(status) 109 + ", " + actionToString(action) + ")"); 110 } 111 112 case TransactionalWorkingSet.CTX_PREPARED_OK: 113 switch (action) { 114 case COMMIT_ACTION: 115 return TransactionalWorkingSet.CTX_COMMITTED; 116 case ROLLBACK_ACTION: 117 return TransactionalWorkingSet.CTX_ABORTED; 118 case CLOSE_ACTION: 119 return TransactionalWorkingSet.CTX_CLOSED; 120 default: 121 throw new PersistenceException("Illegal action on a transaction" 122 + " ( " + statusToString(status) 123 + ", " + actionToString(action) + ")"); 124 } 125 126 case TransactionalWorkingSet.CTX_PREPARED_FAIL: 127 switch (action) { 128 case ROLLBACK_ACTION: 129 return TransactionalWorkingSet.CTX_ABORTED; 130 case CLOSE_ACTION: 131 return TransactionalWorkingSet.CTX_CLOSED; 132 default: 133 throw new PersistenceException("Illegal action on a transaction" 134 + " ( " + statusToString(status) 135 + ", " + actionToString(action) + ")"); 136 } 137 138 case TransactionalWorkingSet.CTX_COMMITTED: 139 case TransactionalWorkingSet.CTX_ABORTED: 140 switch (action) { 141 case BEGIN_TX_ACTION: 142 return TransactionalWorkingSet.CTX_ACTIVE_TRANSACTIONAL; 143 case PREPARE_ACTION: 144 return TransactionalWorkingSet.CTX_PREPARED; 145 case COMMIT_ACTION: return TransactionalWorkingSet.CTX_COMMITTED; 147 case ROLLBACK_ACTION: return TransactionalWorkingSet.CTX_ABORTED; 149 case CLOSE_ACTION: 150 return WorkingSet.CTX_CLOSED; 151 default: 152 throw new PersistenceException("Illegal action on a transaction" 153 + " ( " + statusToString(status) 154 + ", " + actionToString(action) + ")"); 155 } 156 157 case WorkingSet.CTX_CLOSED: 158 switch (action) { 159 case ACTIVE_ACTION: 160 return WorkingSet.CTX_ACTIVE; 161 case CLOSE_ACTION: 162 return WorkingSet.CTX_CLOSED; 163 case BEGIN_TX_ACTION: 164 return TransactionalWorkingSet.CTX_ACTIVE_TRANSACTIONAL; 165 default: 166 throw new PersistenceException("Illegal action on a transaction" 167 + " ( " + statusToString(status) 168 + ", " + actionToString(action) + ")"); 169 } 170 171 default: 172 throw new PersistenceException("Illegal action on a transaction" 173 + " ( " + statusToString(status) 174 + ", " + actionToString(action) + ")"); 175 } 176 } 177 178 } 179 | Popular Tags |