- All Implemented Interfaces:
AutoCloseable,FbBlob,DatabaseListener,ExceptionListenable,TransactionListener
- Direct Known Subclasses:
AbstractFbWireBlob
- Since:
- 3.0
- Author:
- Mark Rotteveel
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static enumState of the blob.Nested classes/interfaces inherited from interface org.firebirdsql.gds.ng.FbBlob
FbBlob.SeekMode -
Field Summary
FieldsFields inherited from interface org.firebirdsql.gds.ng.FbBlob
NO_BLOB_ID -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractFbBlob(FbDatabase database, FbTransaction transaction, BlobParameterBuffer blobParameterBuffer) -
Method Summary
Modifier and TypeMethodDescriptionfinal voidaddExceptionListener(ExceptionListener listener) Adds an exception listener to this object.final voidcancel()Cancels an output blob (which means its contents will be thrown away).protected abstract voidInternal implementation ofcancel().protected voidprotected voidChecks if the blob is open.protected final voidprotected final voidprotected final voidprotected final voidClears the deferred exception.protected final voidfinal voidclose()Closes the blob.protected abstract voidInternal implementation ofclose().protected BlobLengthProcessorvoiddetached(FbDatabase database) Called when thedatabaseconnection has been detachedvoiddetaching(FbDatabase database) Called before thedatabasewill be detached.protected final voidfinal intget(byte[] b, int off, int len) Reads content from the blob intobstarting atoffforlenbytes.final intget(byte[] b, int off, int len, float minFillFactor) Variant ofFbBlob.get(byte[], int, int)to exert some control over the number of requests performed.protected abstract intget(byte[] b, int off, int len, int minLen) Default implementation forget(byte[], int, int)andget(byte[], int, int, float).<T> TgetBlobInfo(byte[] requestItems, int bufferLength, InfoProcessor<T> infoProcessor) Request blob info.protected BlobParameterBufferprotected byte[]The known blob info items for the connected server as a blob info request buffer.intThe maximum segment size allowed by the protocol forFbBlob.getSegment(int)andFbBlob.putSegment(byte[]).protected final AbstractFbBlob.BlobStategetState()The current blob state.protected FbTransactionprotected final booleanfinal booleanisEof()final booleanisOpen()longlength()Requests the blob length from the server.voidputSegment(byte[] segment) Writes a segment of blob data.protected final voidregisterDeferredException(SQLException deferredException) Registers an exception as a deferred exception.protected abstract voidRelease Java resources held.final voidremoveExceptionListener(ExceptionListener listener) Removes an exception listener to this object.protected final voidresetEof()Resets the eof state of the blob to false (not eof).protected final voidsetEof()Marks this blob as EOF (end of file).protected final voidsetState(AbstractFbBlob.BlobState newState) Sets the state of the blob to the specified value.protected final voidIf a deferred exception is registered it is cleared and thrown.voidtransactionStateChanged(FbTransaction transaction, TransactionState newState, TransactionState previousState) Signals that the transaction state changed.protected final voidIf a deferred exception is registered, it is cleared and set as a next exception ontarget.protected final voidvalidateBufferLength(byte[] b, int off, int len) Validates requested offset (off) and length (len) against the array (b).voidwarningReceived(FbDatabase database, SQLWarning warning) Called when a warning was received for thedatabaseconnection.protected final LockCloseablewithLock()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.firebirdsql.gds.ng.FbBlob
getBlobId, getBlobInfo, getHandle, getSegment, isOutput, open, put, seek
-
Field Details
-
exceptionListenerDispatcher
-
-
Constructor Details
-
AbstractFbBlob
protected AbstractFbBlob(FbDatabase database, FbTransaction transaction, BlobParameterBuffer blobParameterBuffer) throws SQLException - Throws:
SQLException
-
-
Method Details
-
isOpen
public final boolean isOpen() -
isEof
public final boolean isEof() -
setEof
protected final void setEof()Marks this blob as EOF (end of file).For an output blob this is a no-op (as those are never end of file, unless explicitly closed)
-
resetEof
protected final void resetEof()Resets the eof state of the blob to false (not eof).This method should only be called by subclasses of this class.
-
setState
Sets the state of the blob to the specified value.This method should only be called by subclasses of this class.
- Parameters:
newState- new value of state- Since:
- 5.0.7
-
getState
The current blob state.- Returns:
- current blob state
- Since:
- 5.0.7
-
close
Description copied from interface:FbBlobCloses the blob.Closing an already closed blob is a no-op.
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceFbBlob- Throws:
SQLException- If the transaction is not active, or a database connection error occurred
-
closeImpl
Internal implementation ofclose(). The implementation does not need to check for attached database and active transaction, nor does it need to mark this blob as closed.- Throws:
SQLException
-
cancel
Description copied from interface:FbBlobCancels an output blob (which means its contents will be thrown away).Calling cancel on an input blob will close it. Contrary to
FbBlob.close(), calling cancel on an already closed (or cancelled) blob will throw anSQLException.- Specified by:
cancelin interfaceFbBlob- Throws:
SQLException- If the blob has already been closed, the transaction is not active, or a database connection error occurred.
-
cancelImpl
Internal implementation ofcancel(). The implementation does not need to check for attached database and active transaction, nor does it need to mark this blob as closed.- Throws:
SQLException
-
putSegment
Description copied from interface:FbBlobWrites a segment of blob data.Implementations must handle segment lengths exceeding
FbBlob.getMaximumSegmentSize()by batching. This method should either callput(segment, 0, segment.length), or produce the same effects as that call.Passing a section that is length 0 will throw an
SQLException.- Specified by:
putSegmentin interfaceFbBlob- Parameters:
segment- segment to write- Throws:
SQLException- if this is an input blob, the blob is closed, the transaction is not active, the segment is length 0, or a database connection error occurred- See Also:
-
get
Description copied from interface:FbBlobReads content from the blob intobstarting atoffforlenbytes.Implementations must read the requested number of bytes (
len), unless end-of-blob is reached before the requested number of bytes were read. The return value of this method is the actual number of bytes read.If the implementation cannot perform reads without additional allocation, it should use at most
DatabaseConnectionProperties.getBlobBufferSize()as an internal buffer. If the implementation can perform reads without additional allocation, it is recommended it performs reads using (at most)FbBlob.getMaximumSegmentSize().Contrary to similar methods like
InputStream.read(byte[], int, int), this method returns0when no bytes were read if end-of-blob is reached without reading any bytes, not-1.Given this method attempts to fulfill the entire request for
lenbytes, it may not always be efficient. For example, requests near multiples of the maximum segment size (or blob buffer size) may result in a final request for just a few bytes. This is not a problem if the entire blob is requested at once, but for intermediate buffering it might be better not to do that final request, and instead work with a smaller number of bytes than requested. For those cases, useFbBlob.get(byte[], int, int, float).- Specified by:
getin interfaceFbBlob- Parameters:
b- target byte arrayoff- offset to startlen- number of bytes- Returns:
- actual number of bytes read; this will only be less than
lenwhen end-of-blob was reached - Throws:
SQLException- for database access errors, ifoff < 0,len < 0, or ifoff + len > b.length
-
get
Description copied from interface:FbBlobVariant ofFbBlob.get(byte[], int, int)to exert some control over the number of requests performed.This method will request segments until at least
(int) (minFillFactor * len)bytes have been retrieved, or end-of-blob is reached. This method is intended as an alternative toFbBlob.get(byte[], int, int)where avoiding the potential inefficiencies of that method are preferred over getting all the requestedlenbytes.If the implementation cannot perform reads without additional allocation, it should use at most
DatabaseConnectionProperties.getBlobBufferSize()as an internal buffer. If the implementation can perform reads without additional allocation, it is recommended it performs reads using (at most)FbBlob.getMaximumSegmentSize().Contrary to similar methods like
InputStream.read(byte[], int, int), this method returns0when no bytes were read if end-of-blob is reached without reading any bytes, not-1.- Specified by:
getin interfaceFbBlob- Parameters:
b- target byte arrayoff- offset to startlen- number of bytesminFillFactor- minimum fill factor (0 < minFillFactor <= 1)- Returns:
- actual number of bytes read, this method returns at least
(int) (minFillFactor * len)bytes, unless end-of-blob is reached - Throws:
SQLException- for database access errors, ifoff < 0,len < 0, or ifoff + len > b.length,minFillFactor <= 0, orminFillFactor > 1orminFillFactor is NaN
-
get
Default implementation forget(byte[], int, int)andget(byte[], int, int, float).- Parameters:
b- target byte arrayoff- offset to startlen- number of bytesminLen- minimum number of bytes to fill (must be0 < minLen <= leniflen != 0- Returns:
- actual number of bytes read; is
0iflen == 0, will only be less thanminLenif end-of-blob is reached - Throws:
SQLException- for database access errors, ifoff < 0,len < 0, or ifoff + len > b.length, orlen != 0 && (minLen <= 0 || minLen > len)
-
releaseResources
protected abstract void releaseResources()Release Java resources held. This should not communicate with the Firebird server. -
registerDeferredException
Registers an exception as a deferred exception.This should only be used for exceptions from deferred response that need to be thrown.
- Parameters:
deferredException- deferred exception- Since:
- 5.0.7
-
clearDeferredException
protected final void clearDeferredException()Clears the deferred exception.- Since:
- 5.0.7
-
throwAndClearDeferredException
If a deferred exception is registered it is cleared and thrown.- Throws:
SQLException- the current deferred exception, if any- Since:
- 5.0.7
-
transferDeferredExceptionTo
If a deferred exception is registered, it is cleared and set as a next exception ontarget.- Parameters:
target- the target exception to add the deferred exception to (notnull)- Throws:
NullPointerException- if there is a deferred exception, andtarget == null- Since:
- 5.0.7
-
withLock
- See Also:
-
transactionStateChanged
public void transactionStateChanged(FbTransaction transaction, TransactionState newState, TransactionState previousState) Description copied from interface:TransactionListenerSignals that the transaction state changed.- Specified by:
transactionStateChangedin interfaceTransactionListener- Parameters:
transaction-FbTransactionthat changed state
-
detaching
Description copied from interface:DatabaseListenerCalled before thedatabasewill be detached.This event is intended for cleanup action, implementer should take care that no exceptions are thrown from this method.
- Specified by:
detachingin interfaceDatabaseListener- Parameters:
database- The database object that is detaching
-
detached
Description copied from interface:DatabaseListenerCalled when thedatabaseconnection has been detached- Specified by:
detachedin interfaceDatabaseListener- Parameters:
database- The database object that was detached
-
warningReceived
Description copied from interface:DatabaseListenerCalled when a warning was received for thedatabaseconnection.In implementation it is possible that some warnings are not sent to listeners on the database, but only to listeners on specific connection derived objects (like an
FbStatementimplementation).- Specified by:
warningReceivedin interfaceDatabaseListener- Parameters:
database- Database receiving the warningwarning- Warning
-
isEndingTransaction
protected final boolean isEndingTransaction()- Returns:
trueif the transaction is committing, rolling back or preparing
-
checkTransactionActive
- Throws:
SQLException- when no transaction is set, or the transaction state is notTransactionState.ACTIVE
-
checkDatabaseAttached
- Throws:
SQLException- when no database is set, or the database is not attached
-
checkBlobOpen
Checks if the blob is open.NOTE: Subclasses may perform additional side effects, like queuing a server-side open for a deferred open blob.
- Throws:
SQLException- when the blob is closed.
-
checkBlobClosed
- Throws:
SQLException- When the blob is open.
-
getTransaction
-
clearTransaction
protected final void clearTransaction() -
getDatabase
- Specified by:
getDatabasein interfaceFbBlob- Returns:
- The database connection that created this blob
-
getBlobInfo
public <T> T getBlobInfo(byte[] requestItems, int bufferLength, InfoProcessor<T> infoProcessor) throws SQLException Description copied from interface:FbBlobRequest blob info.- Specified by:
getBlobInfoin interfaceFbBlob- Parameters:
requestItems- Array of info items to requestbufferLength- Response buffer length to useinfoProcessor- Implementation ofInfoProcessorto transform the info response- Returns:
- Transformed info response of type T
- Throws:
SQLException- For errors retrieving or transforming the response.
-
getKnownBlobInfoItems
protected byte[] getKnownBlobInfoItems()The known blob info items for the connected server as a blob info request buffer.- Returns:
- the known blob info items (possibly empty under implementation-specific circumstances)
- Since:
- 7
-
length
Description copied from interface:FbBlobRequests the blob length from the server.- Specified by:
lengthin interfaceFbBlob- Returns:
- Length of the blob.
- Throws:
SQLException- For Errors retrieving the length, or if the blob is not associated with a blob id, or the database is not attached.
-
errorOccurred
NotifiesExceptionListenerDispatcher.errorOccurred(SQLException).If there is a registered deferred exception, it is set as a next exception on
ebefore notification.- Parameters:
e- exception to notify to exception listeners
-
addExceptionListener
Description copied from interface:ExceptionListenableAdds an exception listener to this object.Implementations use
WeakReference.- Specified by:
addExceptionListenerin interfaceExceptionListenable- Parameters:
listener- Listener to register
-
removeExceptionListener
Description copied from interface:ExceptionListenableRemoves an exception listener to this object.- Specified by:
removeExceptionListenerin interfaceExceptionListenable- Parameters:
listener- Listener to remove
-
clearDatabase
protected final void clearDatabase() -
getBlobParameterBuffer
- Returns:
- The blob parameter buffer of this blob.
-
createBlobLengthProcessor
- Returns:
- New instance of
BlobLengthProcessorfor this blob.
-
getMaximumSegmentSize
public int getMaximumSegmentSize()Description copied from interface:FbBlobThe maximum segment size allowed by the protocol forFbBlob.getSegment(int)andFbBlob.putSegment(byte[]).This value is not the segment size (optionally) defined for the column.
- Specified by:
getMaximumSegmentSizein interfaceFbBlob- Returns:
- The maximum segment size allowed for get or put.
-
validateBufferLength
Validates requested offset (off) and length (len) against the array (b).- Parameters:
b- arrayoff- position in arraylen- length fromoff- Throws:
SQLException- ifoff < 0,len < 0, or ifoff + len > b.length- Since:
- 6
-