| 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 java.util.Arrays; |
| 9 |
|
| 10 |
import org.h2.value.Value; |
| 11 |
|
| 12 |
/** |
| 13 |
* Represents a row in a table. |
| 14 |
*/ |
| 15 |
public abstract class Row extends SearchRow { |
| 16 |
|
| 17 |
/** |
| 18 |
* Creates a new row. |
| 19 |
* |
| 20 |
* @param data values of columns, or null |
| 21 |
* @param memory used memory |
| 22 |
* @return the allocated row |
| 23 |
*/ |
| 24 |
public static Row get(Value[] data, int memory) { |
| 25 |
return new DefaultRow(data, memory); |
| 26 |
} |
| 27 |
|
| 28 |
/** |
| 29 |
* Creates a new row with the specified key. |
| 30 |
* |
| 31 |
* @param data values of columns, or null |
| 32 |
* @param memory used memory |
| 33 |
* @param key the key |
| 34 |
* @return the allocated row |
| 35 |
*/ |
| 36 |
public static Row get(Value[] data, int memory, long key) { |
| 37 |
Row r = new DefaultRow(data, memory); |
| 38 |
r.setKey(key); |
| 39 |
return r; |
| 40 |
} |
| 41 |
|
| 42 |
/** |
| 43 |
* Get values. |
| 44 |
* |
| 45 |
* @return values |
| 46 |
*/ |
| 47 |
public abstract Value[] getValueList(); |
| 48 |
|
| 49 |
/** |
| 50 |
* Check whether values of this row are equal to values of other row. |
| 51 |
* |
| 52 |
* @param other |
| 53 |
* the other row |
| 54 |
* @return {@code true} if values are equal, |
| 55 |
* {@code false} otherwise |
| 56 |
*/ |
| 57 |
public boolean hasSameValues(Row other) { |
| 58 |
return Arrays.equals(getValueList(), other.getValueList()); |
| 59 |
} |
| 60 |
|
| 61 |
/** |
| 62 |
* Check whether this row and the specified row share the same underlying |
| 63 |
* data with values. This method must return {@code false} when values are |
| 64 |
* not equal and may return either {@code true} or {@code false} when they |
| 65 |
* are equal. This method may be used only for optimizations and should not |
| 66 |
* perform any slow checks, such as equality checks for all pairs of values. |
| 67 |
* |
| 68 |
* @param other |
| 69 |
* the other row |
| 70 |
* @return {@code true} if rows share the same underlying data, |
| 71 |
* {@code false} otherwise or when unknown |
| 72 |
*/ |
| 73 |
public boolean hasSharedData(Row other) { |
| 74 |
return false; |
| 75 |
} |
| 76 |
|
| 77 |
} |