| 1 |
/* |
| 2 |
* Copyright 2004-2023 H2 Group. Multiple-Licensed under the MPL 2.0, |
| 3 |
* and the EPL 1.0 (https://h2database.com/html/license.html). |
| 4 |
* Initial Developer: H2 Group |
| 5 |
*/ |
| 6 |
package org.h2.result; |
| 7 |
|
| 8 |
import org.h2.value.Value; |
| 9 |
import org.h2.value.ValueBigint; |
| 10 |
|
| 11 |
/** |
| 12 |
* Class Sparse. |
| 13 |
* <UL> |
| 14 |
* <LI> 11/16/19 7:35 PM initial creation |
| 15 |
* </UL> |
| 16 |
* |
| 17 |
* @author <a href='mailto:[email protected]'>Andrei Tokar</a> |
| 18 |
*/ |
| 19 |
public final class Sparse extends DefaultRow { |
| 20 |
private final int columnCount; |
| 21 |
private final int[] map; |
| 22 |
|
| 23 |
Sparse(int columnCount, int capacity, int[] map) { |
| 24 |
super(new Value[capacity]); |
| 25 |
this.columnCount = columnCount; |
| 26 |
this.map = map; |
| 27 |
} |
| 28 |
|
| 29 |
@Override |
| 30 |
public int getColumnCount() { |
| 31 |
return columnCount; |
| 32 |
} |
| 33 |
|
| 34 |
@Override |
| 35 |
public Value getValue(int i) { |
| 36 |
if (i == ROWID_INDEX) { |
| 37 |
return ValueBigint.get(getKey()); |
| 38 |
} |
| 39 |
int index = map[i]; |
| 40 |
return index > 0 ? super.getValue(index - 1) : null; |
| 41 |
} |
| 42 |
|
| 43 |
@Override |
| 44 |
public void setValue(int i, Value v) { |
| 45 |
if (i == ROWID_INDEX) { |
| 46 |
setKey(v.getLong()); |
| 47 |
} |
| 48 |
int index = map[i]; |
| 49 |
if (index > 0) { |
| 50 |
super.setValue(index - 1, v); |
| 51 |
} |
| 52 |
} |
| 53 |
|
| 54 |
@Override |
| 55 |
public void copyFrom(SearchRow source) { |
| 56 |
setKey(source.getKey()); |
| 57 |
for (int i = 0; i < map.length; i++) { |
| 58 |
int index = map[i]; |
| 59 |
if (index > 0) { |
| 60 |
super.setValue(index - 1, source.getValue(i)); |
| 61 |
} |
| 62 |
} |
| 63 |
} |
| 64 |
} |