1 55 package org.lateralnz.c3d; 56 57 import java.io.Serializable ; 58 import java.sql.ResultSetMetaData ; 59 import java.sql.SQLException ; 60 import java.sql.Types ; 61 62 public class DCResultSetMetaData implements Serializable , ResultSetMetaData { 63 64 private static final String INDEX_OUT_OF_RANGE = "index out of range"; 65 private static final String STRING_CLASSNAME = java.lang.String .class.getName(); 66 67 private String [] catalogNames; 68 private String [] columnClassNames; 69 private int columnCount; 70 private int[] columnDisplaySizes; 71 private String [] columnLabels; 72 private String [] columnNames; 73 private int[] columnTypes; 74 private String [] columnTypeNames; 75 private int[] precisions; 76 private int[] scales; 77 private String [] schemaNames; 78 private String [] tableNames; 79 private boolean[] autoIncrement; 80 private boolean[] caseSensitive; 81 private boolean[] currency; 82 private int[] nullable; 83 private boolean[] searchable; 84 private boolean[] signed; 85 86 public DCResultSetMetaData() { 87 columnCount = 0; 88 } 89 90 public DCResultSetMetaData(String [] colNames) { 91 columnCount = colNames.length; 92 93 init(); 94 95 for (int i = 0; i < columnCount; i++) { 96 catalogNames[i] = ""; 97 columnClassNames[i] = STRING_CLASSNAME; 98 columnDisplaySizes[i] = 1024; 99 columnLabels[i] = colNames[i]; 100 columnNames[i] = colNames[i]; 101 columnTypes[i] = Types.VARCHAR; 102 columnTypeNames[i] = "varchar"; 103 precisions[i] = 0; 104 scales[i] = 0; 105 schemaNames[i] = ""; 106 tableNames[i] = ""; 107 autoIncrement[i] = false; 108 caseSensitive[i] = true; 109 currency[i] = false; 110 nullable[i] = ResultSetMetaData.columnNoNulls; 111 searchable[i] = false; 112 signed[i] = false; 113 } 114 } 115 116 public DCResultSetMetaData(ResultSetMetaData md) throws SQLException { 117 columnCount = md.getColumnCount(); 118 init(); 119 120 for (int i = 0, j = 1; i < columnCount; i++, j++) { 121 catalogNames[i] = md.getCatalogName(j); 122 columnClassNames[i] = md.getColumnClassName(j); 123 columnDisplaySizes[i] = md.getColumnDisplaySize(j); 124 columnLabels[i] = md.getColumnLabel(j); 125 columnNames[i] = md.getColumnName(j); 126 columnTypes[i] = md.getColumnType(j); 127 columnTypeNames[i] = md.getColumnTypeName(j); 128 precisions[i] = md.getPrecision(j); 129 scales[i] = md.getScale(j); 130 schemaNames[i] = md.getSchemaName(j); 131 tableNames[i] = md.getTableName(j); 132 autoIncrement[i] = md.isAutoIncrement(j); 133 caseSensitive[i] = md.isCaseSensitive(j); 134 currency[i] = md.isCurrency(j); 135 nullable[i] = md.isNullable(j); 136 searchable[i] = md.isSearchable(j); 137 signed[i] = md.isSigned(j); 138 } 139 } 140 141 private void init() { 142 catalogNames = new String [columnCount]; 143 columnClassNames = new String [columnCount]; 144 columnDisplaySizes = new int[columnCount]; 145 columnLabels = new String [columnCount]; 146 columnNames = new String [columnCount]; 147 columnTypes = new int[columnCount]; 148 columnTypeNames = new String [columnCount]; 149 precisions = new int[columnCount]; 150 scales = new int[columnCount]; 151 schemaNames = new String [columnCount]; 152 tableNames = new String [columnCount]; 153 autoIncrement = new boolean[columnCount]; 154 caseSensitive = new boolean[columnCount]; 155 currency = new boolean[columnCount]; 156 nullable = new int[columnCount]; 157 searchable = new boolean[columnCount]; 158 signed = new boolean[columnCount]; 159 } 160 161 public String getCatalogName(int param) throws SQLException { 162 param = param - 1; 163 if (catalogNames == null || param > catalogNames.length) { 164 throw new SQLException (INDEX_OUT_OF_RANGE); 165 } 166 return catalogNames[param]; 167 } 168 169 public String getColumnClassName(int param) throws SQLException { 170 param = param - 1; 171 if (columnClassNames == null || param > columnClassNames.length) { 172 throw new SQLException (INDEX_OUT_OF_RANGE); 173 } 174 return columnClassNames[param]; 175 } 176 177 public int getColumnCount() throws SQLException { 178 return columnCount; 179 } 180 181 public int getColumnDisplaySize(int param) throws SQLException { 182 param = param - 1; 183 if (columnDisplaySizes == null || param > columnDisplaySizes.length) { 184 throw new SQLException (INDEX_OUT_OF_RANGE); 185 } 186 return columnDisplaySizes[param]; 187 } 188 189 public String getColumnLabel(int param) throws SQLException { 190 param = param - 1; 191 if (columnLabels == null || param > columnLabels.length) { 192 throw new SQLException (INDEX_OUT_OF_RANGE); 193 } 194 return columnLabels[param]; 195 } 196 197 public String getColumnName(int param) throws SQLException { 198 param = param - 1; 199 if (columnNames == null || param > columnNames.length) { 200 throw new SQLException (INDEX_OUT_OF_RANGE); 201 } 202 return columnNames[param]; 203 } 204 205 public int getColumnType(int param) throws SQLException { 206 param = param - 1; 207 if (columnTypes == null || param > columnTypes.length) { 208 throw new SQLException (INDEX_OUT_OF_RANGE); 209 } 210 return columnTypes[param]; 211 } 212 213 public String getColumnTypeName(int param) throws SQLException { 214 param = param - 1; 215 if (columnTypeNames == null || param > columnTypeNames.length) { 216 throw new SQLException (INDEX_OUT_OF_RANGE); 217 } 218 return columnTypeNames[param]; 219 } 220 221 public int getPrecision(int param) throws SQLException { 222 param = param - 1; 223 if (precisions == null || param > precisions.length) { 224 throw new SQLException (INDEX_OUT_OF_RANGE); 225 } 226 return precisions[param]; 227 } 228 229 public int getScale(int param) throws SQLException { 230 param = param - 1; 231 if (scales == null || param > scales.length) { 232 throw new SQLException (INDEX_OUT_OF_RANGE); 233 } 234 return scales[param]; 235 } 236 237 public String getSchemaName(int param) throws SQLException { 238 param = param - 1; 239 if (schemaNames == null || param > schemaNames.length) { 240 throw new SQLException (INDEX_OUT_OF_RANGE); 241 } 242 return schemaNames[param]; 243 } 244 245 public String getTableName(int param) throws SQLException { 246 param = param - 1; 247 if (tableNames == null || param > tableNames.length) { 248 throw new SQLException (INDEX_OUT_OF_RANGE); 249 } 250 return tableNames[param]; 251 } 252 253 public boolean isAutoIncrement(int param) throws SQLException { 254 param = param - 1; 255 if (autoIncrement == null || param > autoIncrement.length) { 256 throw new SQLException (INDEX_OUT_OF_RANGE); 257 } 258 return autoIncrement[param]; 259 } 260 261 public boolean isCaseSensitive(int param) throws SQLException { 262 param = param - 1; 263 if (caseSensitive == null || param > caseSensitive.length) { 264 throw new SQLException (INDEX_OUT_OF_RANGE); 265 } 266 return caseSensitive[param]; 267 } 268 269 public boolean isCurrency(int param) throws SQLException { 270 param = param - 1; 271 if (currency == null || param > currency.length) { 272 throw new SQLException (INDEX_OUT_OF_RANGE); 273 } 274 return currency[param]; 275 } 276 277 public boolean isDefinitelyWritable(int param) throws SQLException { 278 return false; 279 } 280 281 public int isNullable(int param) throws SQLException { 282 param = param - 1; 283 if (nullable == null || param > nullable.length) { 284 throw new SQLException (INDEX_OUT_OF_RANGE); 285 } 286 return nullable[param]; 287 } 288 289 public boolean isReadOnly(int param) throws SQLException { 290 return true; 291 } 292 293 public boolean isSearchable(int param) throws SQLException { 294 param = param - 1; 295 if (searchable == null || param > searchable.length) { 296 throw new SQLException (INDEX_OUT_OF_RANGE); 297 } 298 return searchable[param]; 299 } 300 301 public boolean isSigned(int param) throws SQLException { 302 param = param - 1; 303 if (signed == null || param > signed.length) { 304 throw new SQLException (INDEX_OUT_OF_RANGE); 305 } 306 return signed[param]; 307 } 308 309 public boolean isWritable(int param) throws SQLException { 310 return false; 311 } 312 313 } 314 | Popular Tags |