| 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.BufferedInputStream; |
| 9 |
import java.io.InputStream; |
| 10 |
|
| 11 |
import org.h2.engine.SessionRemote; |
| 12 |
import org.h2.store.DataHandler; |
| 13 |
import org.h2.store.LobStorageRemoteInputStream; |
| 14 |
|
| 15 |
/** |
| 16 |
* A implementation of the LOB data used on the client side of a remote H2 |
| 17 |
* connection. Fetches the underlying on data from the server. |
| 18 |
*/ |
| 19 |
public final class LobDataFetchOnDemand extends LobData { |
| 20 |
|
| 21 |
private SessionRemote handler; |
| 22 |
|
| 23 |
/** |
| 24 |
* If the LOB is managed by the one the LobStorageBackend classes, these are |
| 25 |
* the unique key inside that storage. |
| 26 |
*/ |
| 27 |
private final int tableId; |
| 28 |
|
| 29 |
private final long lobId; |
| 30 |
|
| 31 |
/** |
| 32 |
* If this is a client-side ValueLobDb object returned by a ResultSet, the |
| 33 |
* hmac acts a security cookie that the client can send back to the server |
| 34 |
* to ask for data related to this LOB. |
| 35 |
*/ |
| 36 |
private final byte[] hmac; |
| 37 |
|
| 38 |
public LobDataFetchOnDemand(DataHandler handler, int tableId, long lobId, byte[] hmac) { |
| 39 |
this.hmac = hmac; |
| 40 |
this.handler = (SessionRemote) handler; |
| 41 |
this.tableId = tableId; |
| 42 |
this.lobId = lobId; |
| 43 |
} |
| 44 |
|
| 45 |
/** |
| 46 |
* Check if this value is linked to a specific table. For values that are |
| 47 |
* kept fully in memory, this method returns false. |
| 48 |
* |
| 49 |
* @return true if it is |
| 50 |
*/ |
| 51 |
@Override |
| 52 |
public boolean isLinkedToTable() { |
| 53 |
throw new IllegalStateException(); |
| 54 |
} |
| 55 |
|
| 56 |
/** |
| 57 |
* Get the current table id of this lob. |
| 58 |
* |
| 59 |
* @return the table id |
| 60 |
*/ |
| 61 |
public int getTableId() { |
| 62 |
return tableId; |
| 63 |
} |
| 64 |
|
| 65 |
public long getLobId() { |
| 66 |
return lobId; |
| 67 |
} |
| 68 |
|
| 69 |
@Override |
| 70 |
public InputStream getInputStream(long precision) { |
| 71 |
return new BufferedInputStream(new LobStorageRemoteInputStream(handler, lobId, hmac)); |
| 72 |
} |
| 73 |
|
| 74 |
@Override |
| 75 |
public DataHandler getDataHandler() { |
| 76 |
return handler; |
| 77 |
} |
| 78 |
|
| 79 |
@Override |
| 80 |
public String toString() { |
| 81 |
return "lob-table: table: " + tableId + " id: " + lobId; |
| 82 |
} |
| 83 |
|
| 84 |
} |