Your browser does not support JavaScript and this site utilizes JavaScript to build content and provide links to additional information. You should either enable JavaScript in your browser settings or use a browser that supports JavaScript in order to take full advantage of this site.
1 8 9 package com.sleepycat.je; 10 11 import com.sleepycat.je.txn.Locker; 12 import com.sleepycat.je.txn.Txn; 13 import com.sleepycat.je.utilint.PropUtil; 14 15 19 public class Transaction { 20 21 private Txn txn; 22 private Environment env; 23 private long id; 24 private String name; 25 26 29 Transaction(Environment env, Txn txn) { 30 this.env = env; 31 this.txn = txn; 32 33 37 this.id = txn.getId(); 38 } 39 40 44 public void abort() 45 throws DatabaseException { 46 47 try { 48 checkEnv(); 49 env.removeReferringHandle(this); 50 txn.abort(false); 52 53 txn = null; 54 } catch (Error E) { 55 DbInternal.envGetEnvironmentImpl(env).invalidate(E); 56 throw E; 57 } 58 } 59 60 64 public long getId() 65 throws DatabaseException { 66 67 return id; 68 } 69 70 74 public void commit() 75 throws DatabaseException { 76 77 try { 78 checkEnv(); 79 env.removeReferringHandle(this); 80 txn.commit(); 81 82 txn = null; 83 } catch (Error E) { 84 DbInternal.envGetEnvironmentImpl(env).invalidate(E); 85 throw E; 86 } 87 } 88 89 93 public void commitSync() 94 throws DatabaseException { 95 96 doCommit(Txn.TXN_SYNC); 97 } 98 99 103 public void commitNoSync() 104 throws DatabaseException { 105 106 doCommit(Txn.TXN_NOSYNC); 107 } 108 109 113 public void commitWriteNoSync() 114 throws DatabaseException { 115 116 doCommit(Txn.TXN_WRITE_NOSYNC); 117 } 118 119 private void doCommit(byte commitType) 120 throws DatabaseException { 121 122 try { 123 checkEnv(); 124 env.removeReferringHandle(this); 125 txn.commit(commitType); 126 127 128 txn = null; 129 } catch (Error E) { 130 DbInternal.envGetEnvironmentImpl(env).invalidate(E); 131 throw E; 132 } 133 } 134 135 139 public void setTxnTimeout(long timeOut) 140 throws DatabaseException { 141 142 checkEnv(); 143 txn.setTxnTimeout(PropUtil.microsToMillis(timeOut)); 144 } 145 146 150 public void setLockTimeout(long timeOut) 151 throws DatabaseException { 152 153 checkEnv(); 154 txn.setLockTimeout(PropUtil.microsToMillis(timeOut)); 155 } 156 157 161 public void setName(String name) { 162 this.name = name; 163 } 164 165 169 public String getName() { 170 return name; 171 } 172 173 public int hashCode() { 174 return (int) id; 175 } 176 177 public boolean equals(Object o) { 178 if (o == null) { 179 return false; 180 } 181 182 if (!(o instanceof Transaction)) { 183 return false; 184 } 185 186 if (((Transaction) o).id == id) { 187 return true; 188 } 189 190 return false; 191 } 192 193 public String toString() { 194 StringBuffer sb = new StringBuffer (); 195 sb.append("<Transaction id=\""); 196 sb.append(id).append("\""); 197 if (name != null) { 198 sb.append(" name=\""); 199 sb.append(name).append("\""); 200 } 201 sb.append(">"); 202 return sb.toString(); 203 } 204 205 210 Locker getLocker() 211 throws DatabaseException { 212 213 if (txn == null) { 214 throw new DatabaseException("Transaction " + id + 215 " has been closed and is no longer"+ 216 " usable."); 217 } else { 218 return txn; 219 } 220 } 221 222 225 226 Txn getTxn() { 227 return txn; 228 } 229 230 233 private void checkEnv() 234 throws RunRecoveryException { 235 236 env.getEnvironmentImpl().checkIfInvalid(); 237 } 238 } 239
| Popular Tags
|