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 if (null == m_values[index]) {
36 Number num = (Number)m_values[index];
37 return num.longValue();
40 public java.util.Date getDate(int index) throws TypeMismatchException
42 checkType(index, Column.Type.TIMESTAMPTZ);
43 return (java.util.Date)m_values[index];
46 protected void checkType(int index, Column.Type type) throws TypeMismatchException {
47 Column column = m_columns[index];
48 Column.Type columnType = column.getType();
50 if (columnType.equals(Column.Type.TIMESTAMPTZ)) {
51 // Special case: TIMESTAMPTZ is stored as an INTEGER
52 if ( Column.Type.TIMESTAMPTZ.equals(type)
53 || Column.Type.INTEGER.equals(type) )
59 if (columnType.equals(type)) {
63 String msg = "Column " + column.getName()
64 + " is of type " + column.getType().name()
65 + " which cannot be coerced to type " + type.name() + ".";
66 throw new TypeMismatchException(msg);