1 28 29 package com.caucho.db.jdbc; 30 31 import java.io.InputStream ; 32 import java.sql.ResultSetMetaData ; 33 import java.sql.SQLException ; 34 import java.sql.Statement ; 35 import java.util.ArrayList ; 36 import java.util.regex.Pattern ; 37 38 class DummyResultSet extends AbstractResultSet { 39 private static Pattern _csvRegexp; 40 41 private ArrayList <DummyColumn> _dummyColumns = new ArrayList <DummyColumn>(); 42 private ArrayList <DummyRow> _dummyRows = new ArrayList <DummyRow>(); 43 private int i; 44 45 static { 46 try { 47 _csvRegexp = Pattern.compile(":"); 48 } catch (Exception e) { 49 } 50 } 51 52 public void addColumn(String name, int type) 53 { 54 _dummyColumns.add(new DummyColumn(name, type)); 55 } 56 57 public int getColumnCount() 58 { 59 return _dummyColumns.size(); 60 } 61 62 public void startRow() 63 { 64 DummyRow row = new DummyRow(); 65 66 _dummyRows.add(row); 67 } 68 69 public DummyResultSet add(String data) 70 { 71 DummyRow row = _dummyRows.get(_dummyRows.size() - 1); 72 73 row.add(data); 74 75 return this; 76 } 77 78 public DummyResultSet add(int data) 79 { 80 DummyRow row = _dummyRows.get(_dummyRows.size() - 1); 81 82 row.add(String.valueOf(data)); 83 84 return this; 85 } 86 87 public DummyResultSet add() 88 { 89 DummyRow row = _dummyRows.get(_dummyRows.size() - 1); 90 91 row.add(""); 92 93 return this; 94 } 95 96 public void addRow(String csv) 97 { 98 startRow(); 99 String []values; 100 synchronized (_csvRegexp) { 101 values = _csvRegexp.split(csv); 102 } 103 104 for (int i = 0; i < values.length; i++) 105 add(values[i]); 106 } 107 108 protected InputStream getInputStream(int columnIndex) 109 { 110 throw new UnsupportedOperationException (); 111 } 112 113 protected long getDateAsLong(int columnIndex) 114 { 115 return 0; 116 } 117 118 public int findColumn(String name) 119 { 120 for (int i = 0; i < _dummyColumns.size(); i++) { 121 DummyColumn column = _dummyColumns.get(i); 122 123 if (column.getColumnName().equals(name)) 124 return i; 125 } 126 127 return -1; 128 } 129 130 public boolean wasNull() 131 { 132 return false; 133 } 134 135 public String getString(int column) 136 { 137 DummyRow row = _dummyRows.get(i); 138 139 return row.getString(column); 140 } 141 142 public ResultSetMetaData getMetaData() 143 { 144 return null; 145 } 146 147 public Statement getStatement() 148 { 149 return null; 150 } 151 152 public boolean next() 153 throws SQLException 154 { 155 if (_dummyRows.size() <= i) 156 return false; 157 158 i++; 159 160 return true; 161 } 162 163 static class DummyColumn { 164 String _name; 165 int _type; 166 167 DummyColumn(String name, int type) 168 { 169 _name = name; 170 _type = type; 171 } 172 173 public String getColumnName() 174 { 175 return _name; 176 } 177 178 public int getColumnType() 179 { 180 return _type; 181 } 182 183 public String getColumnTypeName() 184 { 185 return "VARCHAR"; 186 } 187 } 188 189 static class DummyRow { 190 private ArrayList <String > _values = new ArrayList <String >(); 191 192 DummyRow() 193 { 194 } 195 196 void add(String data) 197 { 198 _values.add(data); 199 } 200 201 protected String getString(int columnIndex) 202 { 203 return _values.get(columnIndex); 204 } 205 } 206 } 207 | Popular Tags |