public class H2BinaryDatabase extends Object implements BinaryDatabase
BinaryDatabase using H2 database| Constructor and Description |
|---|
H2BinaryDatabase(@NonNull UUID serverId)
Construct a
BinaryDatabase for a specific server. |
| Modifier and Type | Method and Description |
|---|---|
Duration |
addBinary(@NonNull UUID binaryId,
@NonNull InputStream stream)
Save a binary stream to the database
|
void |
close()
Cleanup method
Delete binaries, close the database and shutdown the
cleaner worker |
Duration |
extendBinaryExpiration(@NonNull UUID binaryId)
Extend the binary expiration duration by
BINARY_EXTEND_DURATION |
Binary |
getBinary(@NonNull UUID binaryId)
Retrieve a binary from the database
|
BinaryInfo |
getBinaryInfo(@NonNull UUID binaryId)
Retrieve a binary
binary info |
void |
removeAllBinaries()
Remove the BINARIES table and hence all binaries from the database
|
void |
removeBinary(@NonNull UUID binaryId)
Remove the specified binary from the database
|
void |
reserveBytes(long length)
Reserve the required resources to store a binary of the specified length
|
public H2BinaryDatabase(@NonNull @NonNull UUID serverId) throws SQLException
BinaryDatabase for a specific server.
The default credentials are database user database password
The default binary expiration is secondsserverId - The server UUIDSQLException - raised if the SQL_INIT query failspublic void close()
cleaner workerclose in interface AutoCloseablepublic Binary getBinary(@NonNull @NonNull UUID binaryId) throws BinaryDatabaseException
getBinary in interface BinaryDatabasebinaryId - the binary identifierBinaryDatabaseException - if the binary does not exist or the database connection failedpublic BinaryInfo getBinaryInfo(@NonNull @NonNull UUID binaryId) throws BinaryDatabaseException
binary infogetBinaryInfo in interface BinaryDatabasebinaryId - the binary identifierBinaryDatabaseException - if the binary does not exist or the database connection failedpublic Duration addBinary(@NonNull @NonNull UUID binaryId, @NonNull @NonNull InputStream stream) throws BinaryDatabaseException
addBinary in interface BinaryDatabasebinaryId - the binary identifierstream - The data stream to save in the databaseBinaryDatabaseException - if the binary could not be savedpublic Duration extendBinaryExpiration(@NonNull @NonNull UUID binaryId) throws BinaryDatabaseException
BINARY_EXTEND_DURATIONextendBinaryExpiration in interface BinaryDatabasebinaryId - The binary identifierBinaryDatabaseException - if the binary could not be extendedpublic void removeAllBinaries()
throws BinaryDatabaseException
removeAllBinaries in interface BinaryDatabaseBinaryDatabaseException - If the removal of the binaries failedpublic void removeBinary(@NonNull @NonNull UUID binaryId) throws BinaryDatabaseException
removeBinary in interface BinaryDatabasebinaryId - The binary identifier to removeBinaryDatabaseException - If to binary removal failedpublic void reserveBytes(long length)
throws BinaryDatabaseException
BinaryDatabasereserveBytes in interface BinaryDatabaselength - The length of binary to storeBinaryDatabaseExceptionCopyright © 2022 SiLA Java Developers. All rights reserved.