| 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.store; |
| 7 |
|
| 8 |
import java.io.IOException; |
| 9 |
import java.io.InputStream; |
| 10 |
import java.io.Reader; |
| 11 |
import org.h2.engine.SessionRemote; |
| 12 |
import org.h2.value.ValueBlob; |
| 13 |
import org.h2.value.ValueClob; |
| 14 |
import org.h2.value.ValueLob; |
| 15 |
|
| 16 |
/** |
| 17 |
* This factory creates in-memory objects and temporary files. It is used on the |
| 18 |
* client side. |
| 19 |
*/ |
| 20 |
public class LobStorageFrontend implements LobStorageInterface { |
| 21 |
|
| 22 |
/** |
| 23 |
* The table id for session variables (LOBs not assigned to a table). |
| 24 |
*/ |
| 25 |
public static final int TABLE_ID_SESSION_VARIABLE = -1; |
| 26 |
|
| 27 |
/** |
| 28 |
* The table id for temporary objects (not assigned to any object). |
| 29 |
*/ |
| 30 |
public static final int TABLE_TEMP = -2; |
| 31 |
|
| 32 |
/** |
| 33 |
* The table id for result sets. |
| 34 |
*/ |
| 35 |
public static final int TABLE_RESULT = -3; |
| 36 |
|
| 37 |
private final SessionRemote sessionRemote; |
| 38 |
|
| 39 |
public LobStorageFrontend(SessionRemote handler) { |
| 40 |
this.sessionRemote = handler; |
| 41 |
} |
| 42 |
|
| 43 |
@Override |
| 44 |
public void removeLob(ValueLob lob) { |
| 45 |
// not stored in the database |
| 46 |
} |
| 47 |
|
| 48 |
@Override |
| 49 |
public InputStream getInputStream(long lobId, |
| 50 |
long byteCount) throws IOException { |
| 51 |
// this method is only implemented on the server side of a TCP connection |
| 52 |
throw new IllegalStateException(); |
| 53 |
} |
| 54 |
|
| 55 |
@Override |
| 56 |
public InputStream getInputStream(long lobId, int tableId, long byteCount) throws IOException { |
| 57 |
// this method is only implemented on the server side of a TCP |
| 58 |
// connection |
| 59 |
throw new IllegalStateException(); |
| 60 |
} |
| 61 |
|
| 62 |
@Override |
| 63 |
public boolean isReadOnly() { |
| 64 |
return false; |
| 65 |
} |
| 66 |
|
| 67 |
@Override |
| 68 |
public ValueLob copyLob(ValueLob old, int tableId) { |
| 69 |
throw new UnsupportedOperationException(); |
| 70 |
} |
| 71 |
|
| 72 |
@Override |
| 73 |
public void removeAllForTable(int tableId) { |
| 74 |
throw new UnsupportedOperationException(); |
| 75 |
} |
| 76 |
|
| 77 |
@Override |
| 78 |
public ValueBlob createBlob(InputStream in, long maxLength) { |
| 79 |
// need to use a temp file, because the input stream could come from |
| 80 |
// the same database, which would create a weird situation (trying |
| 81 |
// to read a block while writing something) |
| 82 |
return ValueBlob.createTempBlob(in, maxLength, sessionRemote); |
| 83 |
} |
| 84 |
|
| 85 |
/** |
| 86 |
* Create a CLOB object. |
| 87 |
* |
| 88 |
* @param reader the reader |
| 89 |
* @param maxLength the maximum length (-1 if not known) |
| 90 |
* @return the LOB |
| 91 |
*/ |
| 92 |
@Override |
| 93 |
public ValueClob createClob(Reader reader, long maxLength) { |
| 94 |
// need to use a temp file, because the input stream could come from |
| 95 |
// the same database, which would create a weird situation (trying |
| 96 |
// to read a block while writing something) |
| 97 |
return ValueClob.createTempClob(reader, maxLength, sessionRemote); |
| 98 |
} |
| 99 |
} |