1 package org.hibernate.cfg.annotations; 3 4 import java.util.Properties ; 5 6 import org.apache.commons.logging.Log; 7 import org.apache.commons.logging.LogFactory; 8 import org.hibernate.annotations.Type; 9 import org.hibernate.cfg.Ejb3Column; 10 import org.hibernate.cfg.Mappings; 11 import org.hibernate.cfg.PropertyHolder; 12 import org.hibernate.mapping.Property; 13 import org.hibernate.mapping.SimpleValue; 14 import org.hibernate.mapping.Value; 15 16 19 public class PropertyBinder { 20 private static Log log = LogFactory.getLog(PropertyBinder.class); 21 private String name; 22 private String returnedClassName; 23 private boolean lazy; 24 private String propertyAccessorName; 25 private Ejb3Column[] columns; 26 private PropertyHolder holder; 27 private String explicitType = ""; 28 private Properties typeParameters; 29 private Mappings mappings; 30 private Value value; 31 private boolean insertable = true; 32 private boolean updatable = true; 33 private String cascade; 34 private Type typeAnn; 35 36 public void setInsertable(boolean insertable) { 37 this.insertable = insertable; 38 } 39 40 public void setUpdatable(boolean updatable) { 41 this.updatable = updatable; 42 } 43 44 45 public void setName(String name) { 46 this.name = name; 47 } 48 49 public void setReturnedClassName(String returnedClassName) { 50 this.returnedClassName = returnedClassName; 51 } 52 53 public void setLazy(boolean lazy) { 54 this.lazy = lazy; 55 } 56 57 public void setPropertyAccessorName(String propertyAccessorName) { 58 this.propertyAccessorName = propertyAccessorName; 59 } 60 61 public void setColumns(Ejb3Column[] columns) { 62 insertable = columns[0].isInsertable(); 63 updatable = columns[0].isUpdatable(); 64 this.columns = columns; 66 } 67 68 public void setHolder(PropertyHolder holder) { 69 this.holder = holder; 70 } 71 72 public void setExplicitType(String explicitType) { 73 this.explicitType = explicitType; 74 } 75 76 public void setExplicitType(Type typeAnn) { 77 this.typeAnn = typeAnn; 78 } 79 80 81 public void setTypeParameters(Properties typeParameters) { 82 this.typeParameters = typeParameters; 83 } 84 85 public void setValue(Value value) { 86 this.value = value; 87 } 88 89 public void setCascade(String cascadeStrategy) { 90 this.cascade = cascadeStrategy; 91 } 92 93 public void setMappings(Mappings mappings) { 94 this.mappings = mappings; 95 } 96 97 private void validateBind() { 98 } 100 101 private void validateMake() { 102 } 104 105 public Property bind() { 106 validateBind(); 107 if (log.isDebugEnabled()) { 108 log.debug("binding property " + name + " with lazy=" + lazy); 109 } 110 String containerClassName = holder == null ? null : holder.getClassName(); 111 SimpleValueBinder value = new SimpleValueBinder(); 112 value.setPropertyName(name); 113 value.setReturnedClassName(returnedClassName); 114 value.setColumns(columns); 115 value.setPersistentClassName(containerClassName); 116 if (typeAnn != null) { 117 value.setExplicitType(typeAnn); 118 } 119 else { 120 value.setExplicitType(explicitType); 121 value.setTypeParameters(typeParameters); 122 } 123 value.setMappings(mappings); 124 SimpleValue propertyValue = value.make(); 125 setValue(propertyValue); 126 Property prop = make(); 127 columns[0].addPropertyToMappingContainer(prop); 128 return prop; 129 } 130 131 public Property make() { 132 validateMake(); 133 log.debug("Building property " + name); 134 Property prop = new Property(); 135 prop.setName(name); 136 prop.setValue(value); 137 prop.setInsertable(insertable); 138 prop.setUpdateable(updatable); 139 prop.setLazy(lazy); 140 prop.setCascade(cascade); 141 prop.setPropertyAccessorName(propertyAccessorName); 142 log.debug("Cascading " + name + " with " + cascade); 143 return prop; 144 } 145 } 146 | Popular Tags |