1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.shardingsphere.infra.merge.result.impl.memory;
19
20 import com.google.common.base.Preconditions;
21 import lombok.RequiredArgsConstructor;
22 import org.apache.shardingsphere.infra.executor.sql.execute.result.query.QueryResult;
23
24 import java.sql.SQLException;
25
26
27
28
29 @RequiredArgsConstructor
30 public final class MemoryQueryResultRow {
31
32 private final Object[] data;
33
34 public MemoryQueryResultRow(final QueryResult queryResult) throws SQLException {
35 data = load(queryResult);
36 }
37
38 private Object[] load(final QueryResult queryResult) throws SQLException {
39 int columnCount = queryResult.getMetaData().getColumnCount();
40 Object[] result = new Object[columnCount];
41 for (int i = 0; i < columnCount; i++) {
42 result[i] = queryResult.getValue(i + 1, Object.class);
43 }
44 return result;
45 }
46
47
48
49
50
51
52
53 public Object getCell(final int columnIndex) {
54 Preconditions.checkArgument(columnIndex > 0 && columnIndex < data.length + 1);
55 return data[columnIndex - 1];
56 }
57
58
59
60
61
62
63
64 public void setCell(final int columnIndex, final Object value) {
65 Preconditions.checkArgument(columnIndex > 0 && columnIndex < data.length + 1);
66 data[columnIndex - 1] = value;
67 }
68 }