Work toward improving solidity. Add a few more unit tests, and some toString()
[cfb.git] / prod / net / jaekl / cfb / db / Row.java
index f25b0ae0bd93432e4b2378248794ad2545ca5939..2200aa1def770bde6b4a75fa3039e2ab9cdcc7b1 100644 (file)
@@ -12,6 +12,11 @@ public class Row {
        }
        
        public int getNumColumns() { return m_columns.length; }
+       public Column getColumn(int idx) { return m_columns[idx]; }
+       
+       public Object getValue(int index) {
+               return m_values[index];
+       }
        
        public String getString(int index) throws TypeMismatchException {
                checkType(index, Column.Type.VARCHAR);
@@ -25,24 +30,51 @@ public class Row {
                return num.intValue();
        }
        
-       public long getLong(int index) throws TypeMismatchException
+       public Long getLong(int index) throws TypeMismatchException
        {
                checkType(index, Column.Type.INTEGER);
+               if (null == m_values[index]) {
+                       return null;
+               }
+               
                Number num = (Number)m_values[index];
                return num.longValue();
        }
        
        public java.util.Date getDate(int index) throws TypeMismatchException
        {
-               checkType(index, Column.Type.INTEGER);
-               long milliseconds = (Long)m_values[index];
-               java.util.Date date = new java.util.Date(milliseconds);
-               return date;
+               checkType(index, Column.Type.TIMESTAMPTZ);
+               return (java.util.Date)m_values[index];
+       }
+       
+       @Override
+       public String toString() 
+       {
+               StringBuilder sb = new StringBuilder("[");
+               for (int idx = 0; idx < m_columns.length; ++idx) {
+                       if (idx > 0) {
+                               sb.append(", ");
+                       }
+                       sb.append("" + m_columns[idx].getName() + "=" + m_values[idx]);
+               }
+               sb.append("]");
+               return sb.toString();
        }
        
        protected void checkType(int index, Column.Type type) throws TypeMismatchException {
                Column column = m_columns[index];
-               if (column.getType().equals(type)) {
+               Column.Type columnType = column.getType();
+               
+               if (columnType.equals(Column.Type.TIMESTAMPTZ)) {
+                       // Special case:  TIMESTAMPTZ is stored as an INTEGER
+                       if (   Column.Type.TIMESTAMPTZ.equals(type)
+                               || Column.Type.INTEGER.equals(type)     )
+                       {
+                               return;
+                       }
+               }
+               
+               if (columnType.equals(type)) {
                        return;
                }