Class AbstractBinaryAccessProvider
java.lang.Object
ch.tocco.nice2.persist.core.spi.binary.AbstractBinaryAccessProvider
- All Implemented Interfaces:
BinaryAccessProvider
- Direct Known Subclasses:
S3AccessProvider
Abstract implementation of
BinaryAccessProvider
that handles reading/writing the
_nice_binary table. Subclasses can modify the statement which inserts new rows into _nice_binary
(to add additional columns for example).
The persistence of the actual binary is handled by the subclasses.-
Nested Class Summary
Modifier and TypeClassDescriptionprotected static interface
-
Field Summary
Modifier and TypeFieldDescriptionprotected final BinaryHashingService
protected final org.slf4j.Logger
-
Constructor Summary
ConstructorDescriptionAbstractBinaryAccessProvider
(org.slf4j.Logger log, BinaryHashingService binaryHashingService) -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract void
configureSqlBuilder
(SqlBuilder.InsertSqlBuilder sqlBuilder) protected abstract Binary.Store
createBinaryStore
(String hash) protected PreparedStatement
createStatementToLoadBinary
(String hash, Connection connection) protected <T> T
doWithSingleResult
(ResultSet resultSet, AbstractBinaryAccessProvider.SqlFunction<T> function) Set
<com.google.common.hash.HashCode> findUnreferencedBinaries
(Connection connection, @Nullable Integer limit) protected abstract void
handleBinaryData
(Binary data, PreparedStatement statement, int index) loadBinary
(com.google.common.hash.HashCode hashCode, long size, String mimeType, String fileExtension) create aBinary
instance without executing an sql query, this method should be used if the data from _nice_binary has already been loaded.loadBinary
(com.google.common.hash.HashCode hashCode, Connection connection) load an object from the storeboolean
removeBinary
(com.google.common.hash.HashCode hashCode, Connection connection) remove a binary from storageprotected boolean
removeBinarySearchText
(String hashCode, Connection connection) com.google.common.hash.HashCode
storeBinary
(Binary binary, Connection connection) save an object into the store
-
Field Details
-
log
protected final org.slf4j.Logger log -
binaryHashingService
-
-
Constructor Details
-
AbstractBinaryAccessProvider
public AbstractBinaryAccessProvider(org.slf4j.Logger log, BinaryHashingService binaryHashingService)
-
-
Method Details
-
loadBinary
Description copied from interface:BinaryAccessProvider
load an object from the store- Specified by:
loadBinary
in interfaceBinaryAccessProvider
- Parameters:
hashCode
- hash/id of the file to loadconnection
-Connection
to use for database operations- Returns:
- the object
-
loadBinary
public Binary loadBinary(com.google.common.hash.HashCode hashCode, long size, String mimeType, String fileExtension) Description copied from interface:BinaryAccessProvider
create aBinary
instance without executing an sql query, this method should be used if the data from _nice_binary has already been loaded.- Specified by:
loadBinary
in interfaceBinaryAccessProvider
-
createBinaryStore
-
storeBinary
Description copied from interface:BinaryAccessProvider
save an object into the store- Specified by:
storeBinary
in interfaceBinaryAccessProvider
- Parameters:
binary
- the object to saveconnection
-Connection
to use for database operations- Returns:
- the hash/id of the saved object
-
configureSqlBuilder
-
handleBinaryData
protected abstract void handleBinaryData(Binary data, PreparedStatement statement, int index) throws SQLException - Throws:
SQLException
-
removeBinary
Description copied from interface:BinaryAccessProvider
remove a binary from storage- Specified by:
removeBinary
in interfaceBinaryAccessProvider
- Parameters:
hashCode
- the hash of the object to removeconnection
-Connection
to use for database operations
-
removeBinarySearchText
-
findUnreferencedBinaries
public Set<com.google.common.hash.HashCode> findUnreferencedBinaries(Connection connection, @Nullable @Nullable Integer limit) - Specified by:
findUnreferencedBinaries
in interfaceBinaryAccessProvider
- Returns:
- all binary hashes that are no longer referenced and may be removed
-
createStatementToLoadBinary
protected PreparedStatement createStatementToLoadBinary(String hash, Connection connection) throws SQLException - Throws:
SQLException
-
doWithSingleResult
protected <T> T doWithSingleResult(ResultSet resultSet, AbstractBinaryAccessProvider.SqlFunction<T> function) throws SQLException - Throws:
SQLException
-