1 22 23 28 29 package org.xquark.mapper.dbms; 30 31 import org.xquark.jdbc.typing.ColumnMetaDataImpl; 32 import org.xquark.jdbc.typing.TypeMap; 33 34 38 public class ColumnSpec 39 { 40 private static final String RCSRevision = "$Revision: 1.3 $"; 41 private static final String RCSName = "$Name: $"; 42 43 44 protected String name; 45 protected int JDBCType; 46 protected long size = -1; 47 protected int prec = -1; 48 protected int scale = -1; 49 protected short paramSize = -1; 50 protected short paramPrec = -1; 51 protected short paramScale = -1; 52 53 54 protected boolean key = false; 55 protected boolean nullable = true; 56 57 public ColumnSpec() {} 61 62 66 public ColumnSpec(String name, int JDBCType, long size) 67 { 68 set(name, JDBCType, size); 69 } 70 71 75 public ColumnSpec(String name, int JDBCType, int prec, int scale) 76 { 77 set(name, JDBCType, prec, scale); 78 } 79 80 84 public ColumnSpec(String name, int JDBCType, boolean key) 85 { 86 set(name, JDBCType, key); 87 } 88 89 93 public void setName(String name) 94 { 95 this.name = name; 96 } 97 98 public void set(String name, int JDBCType, long size) 99 { 100 this.name = name; 101 this.JDBCType = JDBCType; 102 this.size = size; 103 } 104 105 public void set(String name, int JDBCType, int prec, int scale) 106 { 107 set(name, JDBCType, size); 108 this.prec = prec; 109 this.scale = scale; 110 } 111 112 117 public void set(String name, int JDBCType, boolean key) 118 { 119 this.name = name; 120 this.JDBCType = JDBCType; 121 setKeyRole(key); 122 } 123 124 public void setDataType(String type) 125 { 126 JDBCType = TypeMap.parseJDBCType(type); 127 } 128 129 132 public void setKeyRole(boolean key) 133 { 134 this.key = key; 135 } 136 137 public void setSize(long size, short param) 138 { 139 this.size = size; 140 paramSize = param; 141 } 142 143 public void setPrecision(int prec, short param) 144 { 145 this.prec = prec; 146 paramPrec = param; 147 } 148 149 public void setScale(int scale, short param) 150 { 151 this.scale = scale; 152 paramScale = param; 153 } 154 155 public void setNullable(boolean nullable) 156 { 157 this.nullable = nullable; 158 } 159 160 161 public String getName() 162 { 163 return name; 164 } 165 166 public int getDataType() 167 { 168 return JDBCType; 169 } 170 171 172 public boolean isPrimaryKey() 173 { 174 return key; 175 } 176 177 public boolean isNullable() 178 { 179 return nullable; 180 } 181 182 public long getSize(long[] sizeParameters) 183 { 184 if (paramSize >= 0 && sizeParameters[paramSize] >= 0) 185 return sizeParameters[paramSize]; 186 else 187 return size; 188 } 189 190 public int getPrecision(long[] sizeParameters) 191 { 192 if (paramPrec >= 0 && sizeParameters[paramPrec] >= 0) 193 return (int)sizeParameters[paramPrec]; 194 else 195 return prec; 196 } 197 198 public int getScale(long[] sizeParameters) 199 { 200 if (paramScale >= 0 && sizeParameters[paramScale] >= 0) 201 return (int)sizeParameters[paramScale]; 202 else 203 return scale; 204 } 205 206 209 public String getCreationString(TypeMap typeMap) 210 { 211 return name + ' ' + ColumnMetaDataImpl.getTypeCreationString(JDBCType, typeMap, size, prec,scale); 212 } 213 214 217 public String getTypeCreationString(TypeMap typeMap) 218 { 219 return ColumnMetaDataImpl.getTypeCreationString(JDBCType, typeMap, size, prec,scale); 220 } 221 222 } 223 | Popular Tags |