1 17 package org.apache.ws.jaxme.sqls.impl; 18 19 import org.apache.ws.jaxme.sqls.BinaryColumn; 20 import org.apache.ws.jaxme.sqls.Column; 21 import org.apache.ws.jaxme.sqls.StringColumn; 22 import org.apache.ws.jaxme.sqls.Table; 23 24 27 public abstract class AbstractColumn implements Column, StringColumn, BinaryColumn { 28 private final Column.Name name; 29 private final Column.Type type; 30 private boolean nullable; 31 private Long length; 32 private Object customData; 33 34 protected AbstractColumn(Column.Name pName, Column.Type pType) { 35 if (pName == null) { 36 throw new NullPointerException ("The column name must not be null."); 37 } 38 if (pType == null) { 39 throw new NullPointerException ("The column type must not be null."); 40 } 41 name = pName; 42 type = pType; 43 } 44 45 public Column.Name getName() { return name; } 46 public Column.Type getType() { return type; } 47 public boolean isNullable() { return nullable; } 48 public void setNullable(boolean pNullable) { nullable = pNullable; } 49 50 51 public boolean equals(Object o) { 52 if (o == null || !(o instanceof Column)) { 53 return false; 54 } 55 Column other = (Column) o; 56 Table table = getTable(); 57 if (table == null) { 58 if (other.getTable() != null) { 59 return false; 60 } 61 } else { 62 if (!table.equals(other.getTable())) { 63 return false; 64 } 65 } 66 return getName().equals(other.getName()); 67 } 68 69 public int hashCode() { 70 return getTable().hashCode() + getName().hashCode(); 71 } 72 73 public boolean hasFixedLength() { 74 Column.Type myType = getType(); 75 if (Column.Type.CHAR.equals(myType) || 76 Column.Type.BINARY.equals(myType)) { 77 return true; 78 } else if (Column.Type.VARCHAR.equals(myType) 79 || Column.Type.VARBINARY.equals(myType) 80 || Column.Type.BLOB.equals(myType) 81 || Column.Type.OTHER.equals(myType) 82 || Column.Type.CLOB.equals(myType)) { 83 return false; 84 } else { 85 throw new IllegalStateException ("Invalid data type for fixed length."); 86 } 87 } 88 89 public boolean isStringColumn() { 90 Column.Type myType = getType(); 91 return Column.Type.CHAR.equals(myType) || Column.Type.VARCHAR.equals(myType) || 92 Column.Type.CLOB.equals(myType); 93 } 94 95 public boolean isBinaryColumn() { 96 Column.Type myType = getType(); 97 return Column.Type.BINARY.equals(myType) || Column.Type.VARBINARY.equals(myType) || 98 Column.Type.BLOB.equals(myType) || Column.Type.OTHER.equals(myType); 99 } 100 101 public void setLength(Long pLength) { 102 length = pLength; 103 } 104 105 public void setLength(long pLength) { 106 setLength(new Long (pLength)); 107 } 108 109 public Long getLength() { 110 return length; 111 } 112 113 public Object getCustomData() { 114 return customData; 115 } 116 117 public void setCustomData(Object pCustomData) { 118 customData = pCustomData; 119 } 120 } 121 | Popular Tags |