1 16 17 package org.springframework.transaction.support; 18 19 import org.springframework.transaction.NestedTransactionNotSupportedException; 20 import org.springframework.transaction.SavepointManager; 21 import org.springframework.transaction.TransactionException; 22 import org.springframework.transaction.TransactionStatus; 23 import org.springframework.transaction.TransactionUsageException; 24 25 46 public abstract class AbstractTransactionStatus implements TransactionStatus { 47 48 private boolean rollbackOnly = false; 49 50 private boolean completed = false; 51 52 private Object savepoint; 53 54 55 59 public void setRollbackOnly() { 60 this.rollbackOnly = true; 61 } 62 63 70 public boolean isRollbackOnly() { 71 return (isLocalRollbackOnly() || isGlobalRollbackOnly()); 72 } 73 74 79 public boolean isLocalRollbackOnly() { 80 return this.rollbackOnly; 81 } 82 83 88 public boolean isGlobalRollbackOnly() { 89 return false; 90 } 91 92 95 public void setCompleted() { 96 this.completed = true; 97 } 98 99 public boolean isCompleted() { 100 return this.completed; 101 } 102 103 104 108 112 protected void setSavepoint(Object savepoint) { 113 this.savepoint = savepoint; 114 } 115 116 119 protected Object getSavepoint() { 120 return this.savepoint; 121 } 122 123 public boolean hasSavepoint() { 124 return (this.savepoint != null); 125 } 126 127 132 public void createAndHoldSavepoint() throws TransactionException { 133 setSavepoint(getSavepointManager().createSavepoint()); 134 } 135 136 139 public void rollbackToHeldSavepoint() throws TransactionException { 140 if (!hasSavepoint()) { 141 throw new TransactionUsageException("No savepoint associated with current transaction"); 142 } 143 getSavepointManager().rollbackToSavepoint(getSavepoint()); 144 setSavepoint(null); 145 } 146 147 150 public void releaseHeldSavepoint() throws TransactionException { 151 if (!hasSavepoint()) { 152 throw new TransactionUsageException("No savepoint associated with current transaction"); 153 } 154 getSavepointManager().releaseSavepoint(getSavepoint()); 155 setSavepoint(null); 156 } 157 158 159 163 169 public Object createSavepoint() throws TransactionException { 170 return getSavepointManager().createSavepoint(); 171 } 172 173 180 public void rollbackToSavepoint(Object savepoint) throws TransactionException { 181 getSavepointManager().rollbackToSavepoint(savepoint); 182 } 183 184 190 public void releaseSavepoint(Object savepoint) throws TransactionException { 191 getSavepointManager().releaseSavepoint(savepoint); 192 } 193 194 200 protected SavepointManager getSavepointManager() { 201 throw new NestedTransactionNotSupportedException("This transaction does not support savepoints"); 202 } 203 204 } 205 | Popular Tags |