| 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.value.lob; |
| 7 |
|
| 8 |
import java.io.IOException; |
| 9 |
import java.io.InputStream; |
| 10 |
|
| 11 |
import org.h2.message.DbException; |
| 12 |
import org.h2.store.DataHandler; |
| 13 |
import org.h2.value.ValueLob; |
| 14 |
|
| 15 |
/** |
| 16 |
* LOB data stored in database. |
| 17 |
*/ |
| 18 |
public final class LobDataDatabase extends LobData { |
| 19 |
|
| 20 |
private final DataHandler handler; |
| 21 |
|
| 22 |
/** |
| 23 |
* If the LOB is managed by the one the LobStorageBackend classes, these are |
| 24 |
* the unique key inside that storage. |
| 25 |
*/ |
| 26 |
private final int tableId; |
| 27 |
|
| 28 |
private final long lobId; |
| 29 |
|
| 30 |
public LobDataDatabase(DataHandler handler, int tableId, long lobId) { |
| 31 |
this.handler = handler; |
| 32 |
this.tableId = tableId; |
| 33 |
this.lobId = lobId; |
| 34 |
} |
| 35 |
|
| 36 |
@Override |
| 37 |
public void remove(ValueLob value) { |
| 38 |
if (handler != null) { |
| 39 |
handler.getLobStorage().removeLob(value); |
| 40 |
} |
| 41 |
} |
| 42 |
|
| 43 |
/** |
| 44 |
* Check if this value is linked to a specific table. For values that are |
| 45 |
* kept fully in memory, this method returns false. |
| 46 |
* |
| 47 |
* @return true if it is |
| 48 |
*/ |
| 49 |
@Override |
| 50 |
public boolean isLinkedToTable() { |
| 51 |
return tableId >= 0; |
| 52 |
} |
| 53 |
|
| 54 |
/** |
| 55 |
* Get the current table id of this lob. |
| 56 |
* |
| 57 |
* @return the table id |
| 58 |
*/ |
| 59 |
public int getTableId() { |
| 60 |
return tableId; |
| 61 |
} |
| 62 |
|
| 63 |
public long getLobId() { |
| 64 |
return lobId; |
| 65 |
} |
| 66 |
|
| 67 |
@Override |
| 68 |
public InputStream getInputStream(long precision) { |
| 69 |
try { |
| 70 |
return handler.getLobStorage().getInputStream(lobId, tableId, precision); |
| 71 |
} catch (IOException e) { |
| 72 |
throw DbException.convertIOException(e, toString()); |
| 73 |
} |
| 74 |
} |
| 75 |
|
| 76 |
@Override |
| 77 |
public DataHandler getDataHandler() { |
| 78 |
return handler; |
| 79 |
} |
| 80 |
|
| 81 |
@Override |
| 82 |
public String toString() { |
| 83 |
return "lob-table: table: " + tableId + " id: " + lobId; |
| 84 |
} |
| 85 |
} |