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
Nested ClassesModifier and TypeClassDescriptionprotected static interface -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final BinaryHashingServiceprotected final org.slf4j.Logger -
Constructor Summary
ConstructorsConstructorDescriptionAbstractBinaryAccessProvider(org.slf4j.Logger log, BinaryHashingService binaryHashingService) -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract voidconfigureSqlBuilder(SqlBuilder.InsertSqlBuilder sqlBuilder) protected abstract Binary.StorecreateBinaryStore(String hash) protected PreparedStatementcreateStatementToLoadBinary(String hash, Connection connection) protected <T> TdoWithSingleResult(ResultSet resultSet, AbstractBinaryAccessProvider.SqlFunction<T> function) Set<com.google.common.hash.HashCode> findUnreferencedBinaries(Connection connection, @Nullable Integer limit) protected abstract voidhandleBinaryData(Binary data, PreparedStatement statement, int index) loadBinary(com.google.common.hash.HashCode hashCode, long size, String mimeType, String fileExtension) create aBinaryinstance 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 storebooleanremoveBinary(com.google.common.hash.HashCode hashCode, Connection connection) remove a binary from storageprotected booleanremoveBinarySearchText(String hashCode, Connection connection) com.google.common.hash.HashCodestoreBinary(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:BinaryAccessProviderload an object from the store- Specified by:
loadBinaryin interfaceBinaryAccessProvider- Parameters:
hashCode- hash/id of the file to loadconnection-Connectionto 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:BinaryAccessProvidercreate aBinaryinstance without executing an sql query, this method should be used if the data from _nice_binary has already been loaded.- Specified by:
loadBinaryin interfaceBinaryAccessProvider
-
createBinaryStore
-
storeBinary
Description copied from interface:BinaryAccessProvidersave an object into the store- Specified by:
storeBinaryin interfaceBinaryAccessProvider- Parameters:
binary- the object to saveconnection-Connectionto 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:BinaryAccessProviderremove a binary from storage- Specified by:
removeBinaryin interfaceBinaryAccessProvider- Parameters:
hashCode- the hash of the object to removeconnection-Connectionto use for database operations
-
removeBinarySearchText
-
findUnreferencedBinaries
public Set<com.google.common.hash.HashCode> findUnreferencedBinaries(Connection connection, @Nullable @Nullable Integer limit) - Specified by:
findUnreferencedBinariesin 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
-