1 30 31 32 package org.hsqldb.util; 33 34 import java.sql.ResultSet ; 35 import java.sql.SQLException ; 36 import java.util.Vector ; 37 38 44 class TransferResultSet { 45 46 Vector vRows = null; 47 int iRowIdx; 48 int iMaxRowIdx; 49 int iColumnCount; 50 String [] sColumnNames = null; 51 int[] iColumnTypes = null; 52 53 TransferResultSet(ResultSet r) { 54 55 iRowIdx = 0; 56 iMaxRowIdx = 0; 57 iColumnCount = 0; 58 vRows = new Vector (); 59 60 try { 61 while (r.next()) { 62 if (sColumnNames == null) { 63 iColumnCount = r.getMetaData().getColumnCount(); 64 sColumnNames = new String [iColumnCount + 1]; 65 iColumnTypes = new int[iColumnCount + 1]; 66 67 for (int Idx = 0; Idx < iColumnCount; Idx++) { 68 sColumnNames[Idx + 1] = 69 r.getMetaData().getColumnName(Idx + 1); 70 iColumnTypes[Idx + 1] = 71 r.getMetaData().getColumnType(Idx + 1); 72 } 73 74 vRows.addElement(null); 75 } 76 77 iMaxRowIdx++; 78 79 Object [] Values = new Object [iColumnCount + 1]; 80 81 for (int Idx = 0; Idx < iColumnCount; Idx++) { 82 Values[Idx + 1] = r.getObject(Idx + 1); 83 } 84 85 vRows.addElement(Values); 86 } 87 } catch (SQLException SQLE) { 88 iRowIdx = 0; 89 iMaxRowIdx = 0; 90 iColumnCount = 0; 91 vRows = new Vector (); 92 } 93 } 94 95 TransferResultSet() { 96 97 iRowIdx = 0; 98 iMaxRowIdx = 0; 99 iColumnCount = 0; 100 vRows = new Vector (); 101 } 102 103 void addRow(String [] Name, int[] type, Object [] Values, 104 int nbColumns) throws Exception { 105 106 if ((Name.length != type.length) || (Name.length != Values.length) 107 || (Name.length != (nbColumns + 1))) { 108 throw new Exception ("Size of parameter incoherent"); 109 } 110 111 if (sColumnNames == null) { 112 iColumnCount = nbColumns; 113 sColumnNames = Name; 114 iColumnTypes = type; 115 116 vRows.addElement(null); 117 } 118 119 if ((iMaxRowIdx > 0) && (this.getColumnCount() != nbColumns)) { 120 throw new Exception ("Wrong number of columns: " 121 + this.getColumnCount() 122 + " column is expected"); 123 } 124 125 iMaxRowIdx++; 126 127 vRows.addElement(Values); 128 } 129 130 boolean next() { 131 132 iRowIdx++; 133 134 return ((iRowIdx <= iMaxRowIdx) && (iMaxRowIdx > 0)); 135 } 136 137 String getColumnName(int columnIdx) { 138 139 if ((iMaxRowIdx <= 0) || (iMaxRowIdx < iRowIdx)) { 140 return null; 141 } 142 143 return sColumnNames[columnIdx]; 144 } 145 146 int getColumnCount() { 147 148 if ((iMaxRowIdx <= 0) || (iMaxRowIdx < iRowIdx)) { 149 return 0; 150 } 151 152 return iColumnCount; 153 } 154 155 int getColumnType(int columnIdx) { 156 157 if ((iMaxRowIdx <= 0) || (iMaxRowIdx < iRowIdx)) { 158 return 0; 159 } 160 161 return iColumnTypes[columnIdx]; 162 } 163 164 Object getObject(int columnIdx) { 165 166 if ((iMaxRowIdx <= 0) || (iMaxRowIdx < iRowIdx)) { 167 return null; 168 } 169 170 return ((Object []) vRows.elementAt(iRowIdx))[columnIdx]; 171 } 172 } 173 | Popular Tags |