1 28 package com.caucho.db.jdbc; 29 30 import com.caucho.db.sql.Data; 31 import com.caucho.db.table.Column; 32 33 import java.sql.SQLException ; 34 import java.sql.Statement ; 35 import java.util.ArrayList ; 36 37 40 public class GeneratedKeysResultSet extends AbstractResultSet { 41 private ArrayList <Data> _keys = new ArrayList <Data>(); 42 43 private Statement _stmt; 44 private int _row; 45 46 49 public void init(Statement stmt) 50 { 51 _stmt = stmt; 52 _row = 0; 53 } 54 55 58 public void init() 59 { 60 _row = 0; 61 } 62 63 66 public java.sql.Statement getStatement() 67 throws SQLException 68 { 69 return _stmt; 70 } 71 72 public java.sql.ResultSetMetaData getMetaData() 73 throws SQLException 74 { 75 return null; 76 } 77 78 public boolean next() 79 throws SQLException 80 { 81 return _row++ == 0; 82 } 83 84 public boolean wasNull() 85 throws SQLException 86 { 87 return false; 88 } 89 90 93 public int findColumn(String columnName) 94 throws SQLException 95 { 96 for (int i = 0; i < _keys.size(); i++) { 97 Column column = _keys.get(i).getColumn(); 98 99 if (column.getName().equals(columnName)) 100 return i + 1; 101 } 102 103 throw new SQLException (L.l("`{0}' is an unknown column.", columnName)); 104 } 105 106 109 public void setColumn(int index, Column column) 110 { 111 Data data = addData(index); 112 113 data.setColumn(column); 114 } 115 116 119 public String getString(int columnIndex) 120 throws SQLException 121 { 122 Data data = _keys.get(columnIndex - 1); 123 124 return data.getString(); 125 } 126 127 130 public void setString(int columnIndex, String value) 131 throws SQLException 132 { 133 Data data = addData(columnIndex); 134 135 data.setString(value); 136 } 137 138 141 public int getInt(int columnIndex) 142 throws SQLException 143 { 144 Data data = _keys.get(columnIndex - 1); 145 146 return data.getInt(); 147 } 148 149 152 public void setInt(int columnIndex, int value) 153 throws SQLException 154 { 155 Data data = addData(columnIndex); 156 157 data.setInt(value); 158 } 159 160 163 public long getLong(int columnIndex) 164 throws SQLException 165 { 166 Data data = _keys.get(columnIndex - 1); 167 168 return data.getLong(); 169 } 170 171 174 public void setLong(int columnIndex, long value) 175 throws SQLException 176 { 177 Data data = addData(columnIndex); 178 179 data.setLong(value); 180 } 181 182 185 private Data addData(int columnIndex) 186 { 187 for (int i = _keys.size(); i < columnIndex; i++) 188 _keys.add(new Data()); 189 190 return _keys.get(columnIndex - 1); 191 } 192 193 public void close() 194 { 195 _stmt = null; 196 } 197 } 198 | Popular Tags |