1 21 22 package org.dbunit.dataset; 23 24 import org.dbunit.dataset.datatype.DataType; 25 26 import java.sql.DatabaseMetaData ; 27 28 35 public class Column 36 { 37 40 public static final Nullable NO_NULLS = new Nullable("noNulls"); 41 44 public static final Nullable NULLABLE = new Nullable("nullable"); 45 48 public static final Nullable NULLABLE_UNKNOWN = new Nullable("nullableUnknown"); 49 50 private final String _columnName; 51 private final DataType _dataType; 52 private final String _sqlTypeName; 53 private final Nullable _nullable; 54 55 61 public Column(String columnName, DataType dataType) 62 { 63 _columnName = columnName; 64 _dataType = dataType; 65 _nullable = NULLABLE_UNKNOWN; 66 _sqlTypeName = dataType.toString(); 67 } 68 69 72 public Column(String columnName, DataType dataType, Nullable nullable) 73 { 74 _columnName = columnName; 75 _dataType = dataType; 76 _sqlTypeName = dataType.toString(); 77 _nullable = nullable; 78 } 79 80 83 public Column(String columnName, DataType dataType, String sqlTypeName, 84 Nullable nullable) 85 { 86 _columnName = columnName; 87 _dataType = dataType; 88 _sqlTypeName = sqlTypeName; 89 _nullable = nullable; 90 } 91 92 95 public String getColumnName() 96 { 97 return _columnName; 98 } 99 100 103 public DataType getDataType() 104 { 105 return _dataType; 106 } 107 108 111 public String getSqlTypeName() 112 { 113 return _sqlTypeName; 114 } 115 116 119 public Nullable getNullable() 120 { 121 return _nullable; 122 } 123 124 133 public static Nullable nullableValue(int nullable) 134 { 135 switch (nullable) 136 { 137 case DatabaseMetaData.columnNoNulls: 138 return NO_NULLS; 139 140 case DatabaseMetaData.columnNullable: 141 return NULLABLE; 142 143 case DatabaseMetaData.columnNullableUnknown: 144 return NULLABLE_UNKNOWN; 145 146 default: 147 throw new IllegalArgumentException ("Unknown constant value " 148 + nullable); 149 } 150 } 151 152 157 public static Nullable nullableValue(boolean nullable) 158 { 159 return nullable ? NULLABLE : NO_NULLS; 160 } 161 162 165 public String toString() 166 { 167 return "(" + _columnName + ", " + _dataType + ", " + _nullable + ")"; 168 } 170 171 public boolean equals(Object o) 172 { 173 if (this == o) return true; 174 if (!(o instanceof Column)) return false; 175 176 final Column column = (Column)o; 177 178 if (!_columnName.equals(column._columnName)) return false; 179 if (!_dataType.equals(column._dataType)) return false; 180 if (!_nullable.equals(column._nullable)) return false; 181 if (!_sqlTypeName.equals(column._sqlTypeName)) return false; 182 183 return true; 184 } 185 186 public int hashCode() 187 { 188 int result; 189 result = _columnName.hashCode(); 190 result = 29 * result + _dataType.hashCode(); 191 result = 29 * result + _sqlTypeName.hashCode(); 192 result = 29 * result + _nullable.hashCode(); 193 return result; 194 } 195 196 public static class Nullable 197 { 198 199 private final String _name; 200 201 private Nullable(String name) 202 { 203 _name = name; 204 } 205 206 209 public String toString() 210 { 211 return _name; 212 } 213 } 214 215 } 216 217 218 219 220 221 222 223 224 | Popular Tags |