1 package org.hibernate; 3 4 import java.io.Serializable ; 5 import java.util.HashMap ; 6 import java.util.Map ; 7 8 19 public final class LockMode implements Serializable { 20 private final int level; 21 private final String name; 22 private static final Map INSTANCES = new HashMap (); 23 24 private LockMode(int level, String name) { 25 this.level=level; 26 this.name=name; 27 } 28 public String toString() { 29 return name; 30 } 31 37 public boolean greaterThan(LockMode mode) { 38 return level > mode.level; 39 } 40 46 public boolean lessThan(LockMode mode) { 47 return level < mode.level; 48 } 49 57 public static final LockMode NONE = new LockMode(0, "NONE"); 58 63 public static final LockMode READ = new LockMode(5, "READ"); 64 68 public static final LockMode UPGRADE = new LockMode(10, "UPGRADE"); 69 75 public static final LockMode UPGRADE_NOWAIT = new LockMode(10, "UPGRADE_NOWAIT"); 76 81 public static final LockMode WRITE = new LockMode(10, "WRITE"); 82 83 static { 84 INSTANCES.put( NONE.name, NONE ); 85 INSTANCES.put( READ.name, READ ); 86 INSTANCES.put( UPGRADE.name, UPGRADE ); 87 INSTANCES.put( UPGRADE_NOWAIT.name, UPGRADE_NOWAIT ); 88 INSTANCES.put( WRITE.name, WRITE ); 89 } 90 91 private Object readResolve() { 92 return INSTANCES.get(name); 93 } 94 95 } 96 97 98 99 100 101 102 | Popular Tags |