1 package net.jaekl.cfb.db;
8 public Row(Column[] columns, Object[] values)
10 m_columns = columns.clone();
11 m_values = values.clone();
14 public int getNumColumns() { return m_columns.length; }
15 public Column getColumn(int idx) { return m_columns[idx]; }
17 public String getString(int index) throws TypeMismatchException {
18 checkType(index, Column.Type.VARCHAR);
19 return (String)m_values[index];
22 public int getInt(int index) throws TypeMismatchException
24 checkType(index, Column.Type.INTEGER);
25 Number num = (Number)m_values[index];
26 return num.intValue();
29 public long getLong(int index) throws TypeMismatchException
31 checkType(index, Column.Type.INTEGER);
32 Number num = (Number)m_values[index];
33 return num.longValue();
36 public java.util.Date getDate(int index) throws TypeMismatchException
38 checkType(index, Column.Type.INTEGER);
39 long milliseconds = (Long)m_values[index];
40 java.util.Date date = new java.util.Date(milliseconds);
44 protected void checkType(int index, Column.Type type) throws TypeMismatchException {
45 Column column = m_columns[index];
46 if (column.getType().equals(type)) {
50 String msg = "Column " + column.getName()
51 + " is of type " + column.getType().name()
52 + " which cannot be coerced to type " + type.name() + ".";
53 throw new TypeMismatchException(msg);