1 28 29 package com.caucho.amber.hibernate; 30 31 import com.caucho.bytecode.JMethod; 32 33 import com.caucho.util.L10N; 34 35 import com.caucho.config.ConfigException; 36 37 import com.caucho.amber.type.EntityType; 38 39 import com.caucho.amber.field.AbstractField; 40 import com.caucho.amber.field.PropertyField; 41 42 import com.caucho.amber.table.Column; 43 44 47 public class HibernateProperty extends HibernateField { 48 private static final L10N L = new L10N(HibernateProperty.class); 49 50 private PropertyField _field; 51 private HibernateColumn _column = new HibernateColumn(); 52 53 HibernateProperty(EntityType type) 54 { 55 super(type); 56 57 _field = new PropertyField(type); 58 59 setField(_field); 60 } 61 62 65 public void setName(String name) 66 throws ConfigException 67 { 68 super.setName(name); 69 70 _column.setName(name); 71 72 JMethod getter = _field.getGetterMethod(); 73 74 if (getter != null && getter.getReturnType().isPrimitive()) 75 _column.setNotNull(true); 76 } 77 78 81 protected void setField(AbstractField field) 82 { 83 super.setField(field); 84 85 _field = (PropertyField) field; 86 } 87 88 public HibernateColumn createColumn() 89 { 90 return _column; 91 } 92 93 96 public void setNotNull(boolean isNotNull) 97 { 98 _column.setNotNull(isNotNull); 99 } 100 101 104 public void setLength(int length) 105 { 106 _column.setLength(length); 107 } 108 109 112 public void setSQLType(String sqlType) 113 { 114 _column.setSQLType(sqlType); 115 } 116 117 120 public void setUnique(boolean isUnique) 121 { 122 _column.setUnique(isUnique); 123 } 124 125 128 public void setUniqueKey(String uniqueKey) 129 { 130 _column.setUniqueKey(uniqueKey); 131 } 132 133 136 public void setIndex(String index) 137 { 138 _column.setIndex(index); 139 } 140 141 144 public void setInsert(boolean isInsert) 145 { 146 _field.setInsert(isInsert); 147 } 148 149 152 public void setUpdate(boolean isUpdate) 153 { 154 _field.setUpdate(isUpdate); 155 } 156 157 public void init() 158 throws ConfigException 159 { 160 super.init(); 161 162 _field.setType(getType()); 163 164 Column column = 165 getOwnerType().getTable().createColumn(_column.getName(), getType()); 166 column.setNotNull(_column.getNotNull()); 167 column.setUnique(_column.getUnique()); 168 column.setLength(_column.getLength()); 169 column.setSQLType(_column.getSQLType()); 170 171 _field.setColumn(column); 172 173 getOwnerType().addField(_field); 174 } 175 } 176 | Popular Tags |