1 21 package oracle.toplink.essentials.internal.ejb.cmp3.metadata.columns; 23 24 import java.lang.reflect.AnnotatedElement ; 25 26 import javax.persistence.Column; 27 import javax.persistence.AttributeOverride; 28 29 import oracle.toplink.essentials.internal.ejb.cmp3.metadata.accessors.MetadataAccessor; 30 import oracle.toplink.essentials.internal.helper.DatabaseField; 31 32 38 public class MetadataColumn { 39 protected String m_attributeName; 40 protected DatabaseField m_databaseField; 41 protected AnnotatedElement m_annotatedElement; 42 43 public static final int DEFAULT_SCALE = 0; 44 public static final int DEFAULT_LENGTH = 255; 45 public static final int DEFAULT_PRECISION = 0; 46 47 public static final String DEFAULT_NAME = ""; 48 public static final String DEFAULT_TABLE = ""; 49 public static final String DEFAULT_COLUMN_DEFINITION = ""; 50 51 public static final boolean DEFAULT_UNIQUE = false; 52 public static final boolean DEFAULT_NULLABLE = true; 53 public static final boolean DEFAULT_UPDATABLE = true; 54 public static final boolean DEFAULT_INSERTABLE = true; 55 56 60 public MetadataColumn(AttributeOverride attributeOverride, AnnotatedElement annotatedElement) { 61 this(attributeOverride.column(), attributeOverride.name(), annotatedElement); 62 } 63 64 68 public MetadataColumn(Column column, MetadataAccessor accessor) { 69 this(column, accessor.getAttributeName(), accessor.getAnnotatedElement()); 70 } 71 72 75 public MetadataColumn(Column column, String attributeName, AnnotatedElement annotatedElement) { 76 this(attributeName, annotatedElement); 77 78 if (column != null) { 79 m_databaseField.setUnique(column.unique()); 81 m_databaseField.setNullable(column.nullable()); 82 m_databaseField.setUpdatable(column.updatable()); 83 m_databaseField.setInsertable(column.insertable()); 84 85 m_databaseField.setScale(column.scale()); 86 m_databaseField.setLength(column.length()); 87 m_databaseField.setPrecision(column.precision()); 88 89 m_databaseField.setName(column.name()); 90 m_databaseField.setTableName(column.table()); 91 m_databaseField.setColumnDefinition(column.columnDefinition()); 92 } 93 } 94 95 99 public MetadataColumn(String attributeName, AnnotatedElement annotatedElement) { 100 m_attributeName = attributeName; 101 m_annotatedElement = annotatedElement; 102 m_databaseField = new DatabaseField(); 103 104 m_databaseField.setUnique(DEFAULT_UNIQUE); 106 m_databaseField.setNullable(DEFAULT_NULLABLE); 107 m_databaseField.setUpdatable(DEFAULT_UPDATABLE); 108 m_databaseField.setInsertable(DEFAULT_INSERTABLE); 109 110 m_databaseField.setScale(DEFAULT_SCALE); 111 m_databaseField.setLength(DEFAULT_LENGTH); 112 m_databaseField.setPrecision(DEFAULT_PRECISION); 113 114 m_databaseField.setName(DEFAULT_NAME); 115 m_databaseField.setTableName(DEFAULT_TABLE); 116 m_databaseField.setColumnDefinition(DEFAULT_COLUMN_DEFINITION); 117 } 118 119 122 public AnnotatedElement getAnnotatedElement() { 123 return m_annotatedElement; 124 } 125 126 129 public String getAttributeName() { 130 return m_attributeName; 131 } 132 133 136 public DatabaseField getDatabaseField() { 137 return m_databaseField; 138 } 139 140 143 public String getUpperCaseAttributeName() { 144 return m_attributeName.toUpperCase(); 145 } 146 147 150 public boolean loadedFromXML() { 151 return false; 152 } 153 } 154 | Popular Tags |