1 package org.hibernate.engine; 3 4 import java.io.Serializable ; 5 6 import org.apache.commons.logging.Log; 7 import org.apache.commons.logging.LogFactory; 8 9 17 public class IdentifierValue { 18 19 private static final Log log = LogFactory.getLog(IdentifierValue.class); 20 21 private final Serializable value; 22 23 26 public static final IdentifierValue ANY = new IdentifierValue() { 27 public final Boolean isUnsaved(Serializable id) { 28 log.trace("id unsaved-value strategy ANY"); 29 return Boolean.TRUE; 30 } 31 public Serializable getDefaultValue(Serializable currentValue) { 32 return currentValue; 33 } 34 public String toString() { 35 return "SAVE_ANY"; 36 } 37 }; 38 39 42 public static final IdentifierValue NONE = new IdentifierValue() { 43 public final Boolean isUnsaved(Serializable id) { 44 log.trace("id unsaved-value strategy NONE"); 45 return Boolean.FALSE; 46 } 47 public Serializable getDefaultValue(Serializable currentValue) { 48 return currentValue; 49 } 50 public String toString() { 51 return "SAVE_NONE"; 52 } 53 }; 54 55 59 public static final IdentifierValue NULL = new IdentifierValue() { 60 public final Boolean isUnsaved(Serializable id) { 61 log.trace("id unsaved-value strategy NULL"); 62 return id==null ? Boolean.TRUE : Boolean.FALSE; 63 } 64 public Serializable getDefaultValue(Serializable currentValue) { 65 return null; 66 } 67 public String toString() { 68 return "SAVE_NULL"; 69 } 70 }; 71 72 75 public static final IdentifierValue UNDEFINED = new IdentifierValue() { 76 public final Boolean isUnsaved(Serializable id) { 77 log.trace("id unsaved-value strategy UNDEFINED"); 78 return null; 79 } 80 public Serializable getDefaultValue(Serializable currentValue) { 81 return null; 82 } 83 public String toString() { 84 return "UNDEFINED"; 85 } 86 }; 87 88 protected IdentifierValue() { 89 this.value = null; 90 } 91 92 96 public IdentifierValue(Serializable value) { 97 this.value = value; 98 } 99 100 103 public Boolean isUnsaved(Serializable id) { 104 if ( log.isTraceEnabled() ) log.trace("id unsaved-value: " + value); 105 return id==null || id.equals(value) ? Boolean.TRUE : Boolean.FALSE; 106 } 107 108 public Serializable getDefaultValue(Serializable currentValue) { 109 return value; 110 } 111 112 public String toString() { 113 return "identifier unsaved-value: " + value; 114 } 115 } | Popular Tags |