1 3 package jodd.jtx; 4 5 import jodd.util.ObjectUtil; 6 import jodd.util.HashCodeUtil; 7 8 13 public class JtxTransactionMode { 14 15 public JtxTransactionMode() { 16 this.propagation = PROPAGATION_REQUIRED; 17 this.isolation = ISOLATION_DEFAULT; 18 this.readOnlyMode = READ_ONLY; 19 } 20 21 23 public static final int PROPAGATION_REQUIRED = 1; 24 public static final int PROPAGATION_SUPPORTS = 2; 25 public static final int PROPAGATION_MANDATORY = 3; 26 public static final int PROPAGATION_REQUIRES_NEW = 4; 27 public static final int PROPAGATION_NOT_SUPPORTED = 5; 28 public static final int PROPAGATION_NEVER = 6; 29 30 protected int propagation; 31 32 public int getPropagation() { 33 return propagation; 34 } 35 36 public JtxTransactionMode setPropagation(int propagation) { 37 this.propagation = propagation; 38 return this; 39 } 40 41 48 public JtxTransactionMode propagationRequired() { 49 this.propagation = PROPAGATION_REQUIRED; 50 return this; 51 } 52 53 60 public JtxTransactionMode propagationSupports() { 61 this.propagation = PROPAGATION_SUPPORTS; 62 return this; 63 } 64 65 72 public JtxTransactionMode propagationMandatory() { 73 this.propagation = PROPAGATION_MANDATORY; 74 return this; 75 } 76 77 84 public JtxTransactionMode propagationRequiresNew() { 85 this.propagation = PROPAGATION_REQUIRES_NEW; 86 return this; 87 } 88 89 96 public JtxTransactionMode propagationNotSupported() { 97 this.propagation = PROPAGATION_NOT_SUPPORTED; 98 return this; 99 } 100 107 public JtxTransactionMode propagationNever() { 108 this.propagation = PROPAGATION_NEVER; 109 return this; 110 } 111 112 113 115 public static final int ISOLATION_DEFAULT = 0; 116 public static final int ISOLATION_NONE = 1; 117 public static final int ISOLATION_READ_UNCOMMITTED = 2; 118 public static final int ISOLATION_READ_COMMITTED = 3; 119 public static final int ISOLATION_REPEATABLE_READ = 4; 120 public static final int ISOLATION_SERIALIZABLE = 5; 121 122 private int isolation; 123 124 public int getIsolation() { 125 return isolation; 126 } 127 128 public JtxTransactionMode setIsolation(int isolation) { 129 this.isolation = isolation; 130 return this; 131 } 132 133 public JtxTransactionMode isolationNone() { 134 this.isolation = ISOLATION_NONE; 135 return this; 136 } 137 public JtxTransactionMode isolationReadUncommitted() { 138 this.isolation = ISOLATION_READ_UNCOMMITTED; 139 return this; 140 } 141 public JtxTransactionMode isolationReadCommited() { 142 this.isolation = ISOLATION_READ_COMMITTED; 143 return this; 144 } 145 public JtxTransactionMode isolationRepeatableRead() { 146 this.isolation = ISOLATION_REPEATABLE_READ; 147 return this; 148 } 149 public JtxTransactionMode isolationSerializable() { 150 this.isolation = ISOLATION_SERIALIZABLE; 151 return this; 152 } 153 154 155 156 158 public static final boolean READ_ONLY = true; 159 public static final boolean READ_WRITE = false; 160 161 private boolean readOnlyMode = READ_ONLY; 162 163 public boolean isReadOnly() { 164 return readOnlyMode; 165 } 166 167 public JtxTransactionMode setReadOnly(boolean readOnly) { 168 this.readOnlyMode = readOnly; 169 return this; 170 } 171 172 173 175 public boolean equals(Object object) { 176 if (this == object) { 177 return true; 178 } 179 if (ObjectUtil.equalsType(object, this) == false) { 180 return false; 181 } 182 final JtxTransactionMode mode = (JtxTransactionMode) object; 183 184 return (mode.getPropagation() == this.propagation) && 185 (mode.getIsolation() == this.isolation) && 186 (mode.isReadOnly() == this.readOnlyMode); 187 } 188 189 public int hashCode() { 190 int result = HashCodeUtil.SEED; 191 result = HashCodeUtil.hash(result, this.propagation); 192 result = HashCodeUtil.hash(result, this.readOnlyMode); 193 result = HashCodeUtil.hash(result, this.isolation); 194 return result; 195 } 196 197 198 } 199 | Popular Tags |