1 17 18 package com.finalist.jaggenerator; 19 20 import org.apache.commons.logging.Log; 21 import org.apache.commons.logging.LogFactory; 22 23 import java.io.Serializable ; 24 25 29 public class Column implements Serializable { 30 static Log log = LogFactory.getLog(Column.class); 31 32 private String name; 33 34 35 private String sqlType; 36 37 38 private int precision; 39 40 41 private int scale; 42 43 44 private int length; 45 46 47 private boolean primaryKey; 48 49 50 private boolean nullable; 51 52 53 54 public Column() { 55 } 56 57 58 62 public String getName() { 63 return this.name; 64 } 65 66 67 71 public void setName(String name) { 72 this.name = name; 73 } 74 75 76 80 public void setSqlType(String sqlType) { 81 82 if (sqlType != null) { 84 int index = sqlType.indexOf("("); 85 if (index != -1) { 86 this.sqlType = sqlType.substring(0, index); 87 int index2 = sqlType.indexOf(")"); 89 if (index2 != -1) { 90 int index3 = sqlType.indexOf(","); 92 if (index3 != -1) { 93 String scale = sqlType.substring(index + 1, index3).trim(); 95 String precision = sqlType.substring(index3 + 1, index2).trim(); 96 int sc = 0; 97 int pr = 0; 98 try { 99 sc = Integer.parseInt(scale); 100 pr = Integer.parseInt(precision); 101 } catch (Exception e) { 102 log.warn("Error while parsing scale or precision for type " + sqlType); 103 } 104 setScale(sc); 105 setPrecision(pr); 106 } else { 107 String scale = sqlType.substring(index + 1, index2).trim(); 109 int sc = 0; 110 try { 111 sc = Integer.parseInt(scale); 112 } catch (Exception e) { 113 log.warn("Error while parsing scale for type " + sqlType); 114 } 115 setScale(sc); 116 117 } 118 } 119 } else { 120 this.sqlType = sqlType; 121 } 122 123 } 124 } 125 126 127 131 public int getPrecision() { 132 return this.precision; 133 } 134 135 136 140 public void setPrecision(int precision) { 141 this.precision = precision; 142 } 143 144 145 149 public int getScale() { 150 return this.scale; 151 } 152 153 154 158 public void setScale(int scale) { 159 this.scale = scale; 160 } 161 162 163 167 public int getLength() { 168 return this.length; 169 } 170 171 172 176 public void setLength(int length) { 177 this.length = length; 178 } 179 180 181 185 public String getSqlType() { 186 return this.sqlType; 187 } 188 189 190 194 public boolean isPrimaryKey() { 195 return this.primaryKey; 196 } 197 198 199 203 public void setPrimaryKey(boolean value) { 204 this.primaryKey = value; 205 } 206 207 212 public boolean isNullable() { 213 return nullable; 214 } 215 216 220 public void setNullable(boolean nullable) { 221 this.nullable = nullable; 222 } 223 224 225 public String toString() { 226 return "Column(name=" + name + ", sqlType=" + sqlType + ", precision=" + precision + 227 ", scale=" + scale + ", length=" + length + ", primaryKey=" + primaryKey + ", nullable=" + nullable + ")"; 228 } 229 230 231 } 232 | Popular Tags |