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 Object getValue(int index) {
18 return m_values[index];
21 public String getString(int index) throws TypeMismatchException {
22 checkType(index, Column.Type.VARCHAR);
23 return (String)m_values[index];
26 public int getInt(int index) throws TypeMismatchException
28 checkType(index, Column.Type.INTEGER);
29 Number num = (Number)m_values[index];
30 return num.intValue();
33 public Long getLong(int index) throws TypeMismatchException
35 checkType(index, Column.Type.INTEGER);
36 if (null == m_values[index]) {
40 Number num = (Number)m_values[index];
41 return num.longValue();
44 public java.util.Date getDate(int index) throws TypeMismatchException
46 checkType(index, Column.Type.TIMESTAMPTZ);
47 return (java.util.Date)m_values[index];
51 public String toString()
53 StringBuilder sb = new StringBuilder("[");
54 for (int idx = 0; idx < m_columns.length; ++idx) {
58 sb.append("" + m_columns[idx].getName() + "=" + m_values[idx]);
64 protected void checkType(int index, Column.Type type) throws TypeMismatchException {
65 Column column = m_columns[index];
66 Column.Type columnType = column.getType();
68 if (columnType.equals(Column.Type.TIMESTAMPTZ)) {
69 // Special case: TIMESTAMPTZ is stored as an INTEGER
70 if ( Column.Type.TIMESTAMPTZ.equals(type)
71 || Column.Type.INTEGER.equals(type) )
77 if (columnType.equals(type)) {
81 String msg = "Column " + column.getName()
82 + " is of type " + column.getType().name()
83 + " which cannot be coerced to type " + type.name() + ".";
84 throw new TypeMismatchException(msg);