| 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.engine.CastDataProvider; |
| 9 |
import org.h2.value.CompareMode; |
| 10 |
import org.h2.value.TypeInfo; |
| 11 |
import org.h2.value.Value; |
| 12 |
import org.h2.value.ValueNull; |
| 13 |
|
| 14 |
/** |
| 15 |
* The base class for rows stored in a table, and for partial rows stored in the |
| 16 |
* index. |
| 17 |
*/ |
| 18 |
public abstract class SearchRow extends Value { |
| 19 |
|
| 20 |
/** |
| 21 |
* Index of a virtual "_ROWID_" column within a row or a table |
| 22 |
*/ |
| 23 |
public static final int ROWID_INDEX = -1; |
| 24 |
|
| 25 |
/** |
| 26 |
* If the key is this value, then the key is considered equal to all other |
| 27 |
* keys, when comparing. |
| 28 |
*/ |
| 29 |
public static long MATCH_ALL_ROW_KEY = Long.MIN_VALUE + 1; |
| 30 |
|
| 31 |
/** |
| 32 |
* The constant that means "memory usage is unknown and needs to be calculated first". |
| 33 |
*/ |
| 34 |
public static final int MEMORY_CALCULATE = -1; |
| 35 |
|
| 36 |
/** |
| 37 |
* The row key. |
| 38 |
*/ |
| 39 |
protected long key; |
| 40 |
|
| 41 |
/** |
| 42 |
* Get the column count. |
| 43 |
* |
| 44 |
* @return the column count |
| 45 |
*/ |
| 46 |
public abstract int getColumnCount(); |
| 47 |
|
| 48 |
/** |
| 49 |
* Determine if specified column contains NULL |
| 50 |
* @param index column index |
| 51 |
* @return true if NULL |
| 52 |
*/ |
| 53 |
public boolean isNull(int index) { |
| 54 |
return getValue(index) == ValueNull.INSTANCE; |
| 55 |
} |
| 56 |
|
| 57 |
/** |
| 58 |
* Get the value for the column |
| 59 |
* |
| 60 |
* @param index the column number (starting with 0) |
| 61 |
* @return the value |
| 62 |
*/ |
| 63 |
public abstract Value getValue(int index); |
| 64 |
|
| 65 |
/** |
| 66 |
* Set the value for given column |
| 67 |
* |
| 68 |
* @param index the column number (starting with 0) |
| 69 |
* @param v the new value |
| 70 |
*/ |
| 71 |
public abstract void setValue(int index, Value v); |
| 72 |
|
| 73 |
/** |
| 74 |
* Set the unique key of the row. |
| 75 |
* |
| 76 |
* @param key the key |
| 77 |
*/ |
| 78 |
public void setKey(long key) { |
| 79 |
this.key = key; |
| 80 |
} |
| 81 |
|
| 82 |
/** |
| 83 |
* Get the unique key of the row. |
| 84 |
* |
| 85 |
* @return the key |
| 86 |
*/ |
| 87 |
public long getKey() { |
| 88 |
return key; |
| 89 |
} |
| 90 |
|
| 91 |
/** |
| 92 |
* Get the estimated memory used for this row, in bytes. |
| 93 |
* |
| 94 |
* @return the memory |
| 95 |
*/ |
| 96 |
@Override |
| 97 |
public abstract int getMemory(); |
| 98 |
|
| 99 |
/** |
| 100 |
* Copy all relevant values from the source to this row. |
| 101 |
* @param source source of column values |
| 102 |
*/ |
| 103 |
public abstract void copyFrom(SearchRow source); |
| 104 |
|
| 105 |
@Override |
| 106 |
public TypeInfo getType() { |
| 107 |
return TypeInfo.TYPE_ROW_EMPTY; |
| 108 |
} |
| 109 |
|
| 110 |
@Override |
| 111 |
public int getValueType() { |
| 112 |
return Value.ROW; |
| 113 |
} |
| 114 |
|
| 115 |
@Override |
| 116 |
public StringBuilder getSQL(StringBuilder builder, int sqlFlags) { |
| 117 |
builder.append("ROW ("); |
| 118 |
for (int index = 0, count = getColumnCount(); index < count; index++) { |
| 119 |
if (index != 0) { |
| 120 |
builder.append(", "); |
| 121 |
} |
| 122 |
getValue(index).getSQL(builder, sqlFlags); |
| 123 |
} |
| 124 |
return builder.append(')'); |
| 125 |
} |
| 126 |
|
| 127 |
@Override |
| 128 |
public String getString() { |
| 129 |
return getTraceSQL(); |
| 130 |
} |
| 131 |
|
| 132 |
@Override |
| 133 |
public int hashCode() { |
| 134 |
throw new UnsupportedOperationException(); |
| 135 |
} |
| 136 |
|
| 137 |
@Override |
| 138 |
public boolean equals(Object other) { |
| 139 |
throw new UnsupportedOperationException(); |
| 140 |
} |
| 141 |
|
| 142 |
@Override |
| 143 |
public int compareTypeSafe(Value v, CompareMode mode, CastDataProvider provider) { |
| 144 |
throw new UnsupportedOperationException(); |
| 145 |
} |
| 146 |
} |