Package org.firebirdsql.gds.ng.jna
Class JnaBlob
- java.lang.Object
-
- org.firebirdsql.gds.ng.AbstractFbBlob
-
- org.firebirdsql.gds.ng.jna.JnaBlob
-
- All Implemented Interfaces:
java.lang.AutoCloseable
,FbBlob
,DatabaseListener
,ExceptionListenable
,TransactionListener
public class JnaBlob extends AbstractFbBlob implements FbBlob, DatabaseListener
Implementation ofFbBlob
for native client access.- Since:
- 3.0
- Author:
- Mark Rotteveel
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.firebirdsql.gds.ng.FbBlob
FbBlob.SeekMode
-
-
Field Summary
-
Fields inherited from class org.firebirdsql.gds.ng.AbstractFbBlob
exceptionListenerDispatcher
-
Fields inherited from interface org.firebirdsql.gds.ng.FbBlob
NO_BLOB_ID
-
-
Constructor Summary
Constructors Constructor Description JnaBlob(JnaDatabase database, JnaTransaction transaction, BlobParameterBuffer blobParameterBuffer)
JnaBlob(JnaDatabase database, JnaTransaction transaction, BlobParameterBuffer blobParameterBuffer, long blobId)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
cancelImpl()
Internal implementation ofAbstractFbBlob.cancel()
.protected void
closeImpl()
Internal implementation ofAbstractFbBlob.close()
.long
getBlobId()
byte[]
getBlobInfo(byte[] requestItems, int bufferLength)
Request blob info.JnaDatabase
getDatabase()
int
getHandle()
com.sun.jna.ptr.IntByReference
getJnaHandle()
byte[]
getSegment(int sizeRequested)
Gets a segment of blob data.JnaTransaction
getTransaction()
boolean
isOutput()
void
open()
Opens an existing input blob, or creates an output blob.void
putSegment(byte[] segment)
Writes a segment of blob data.protected void
releaseResources()
Release Java resources held.void
seek(int offset, FbBlob.SeekMode seekMode)
Performs a seek on a blob with the specifiedseekMode
andoffset
.-
Methods inherited from class org.firebirdsql.gds.ng.AbstractFbBlob
addExceptionListener, cancel, checkBlobClosed, checkBlobOpen, checkDatabaseAttached, checkTransactionActive, clearDatabase, clearTransaction, close, createBlobLengthProcessor, detached, detaching, getBlobInfo, getBlobParameterBuffer, getMaximumSegmentSize, getSynchronizationObject, isEndingTransaction, isEof, isOpen, length, removeExceptionListener, resetEof, setEof, setOpen, transactionStateChanged, warningReceived
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.firebirdsql.gds.ng.listeners.DatabaseListener
detached, detaching, warningReceived
-
Methods inherited from interface org.firebirdsql.gds.ng.listeners.ExceptionListenable
addExceptionListener, removeExceptionListener
-
Methods inherited from interface org.firebirdsql.gds.ng.FbBlob
cancel, close, getBlobInfo, getMaximumSegmentSize, getSynchronizationObject, isEof, isOpen, length
-
-
-
-
Constructor Detail
-
JnaBlob
public JnaBlob(JnaDatabase database, JnaTransaction transaction, BlobParameterBuffer blobParameterBuffer)
-
JnaBlob
public JnaBlob(JnaDatabase database, JnaTransaction transaction, BlobParameterBuffer blobParameterBuffer, long blobId)
-
-
Method Detail
-
getDatabase
public JnaDatabase getDatabase()
- Specified by:
getDatabase
in interfaceFbBlob
- Overrides:
getDatabase
in classAbstractFbBlob
- Returns:
- The database connection that created this blob
-
getTransaction
public JnaTransaction getTransaction()
- Overrides:
getTransaction
in classAbstractFbBlob
-
getHandle
public int getHandle()
-
getJnaHandle
public final com.sun.jna.ptr.IntByReference getJnaHandle()
-
getBlobId
public final long getBlobId()
-
open
public void open() throws java.sql.SQLException
Description copied from interface:FbBlob
Opens an existing input blob, or creates an output blob.
-
isOutput
public final boolean isOutput()
-
getSegment
public byte[] getSegment(int sizeRequested) throws java.sql.SQLException
Description copied from interface:FbBlob
Gets a segment of blob data.When
TODO: Consider allowing this and have the implementation handle longer segments by sending multiple (batched?) requests.sizeRequested
exceedsFbBlob.getMaximumSegmentSize()
it is silently reduced to the maximum segment size.- Specified by:
getSegment
in interfaceFbBlob
- Parameters:
sizeRequested
- Requested segment size (> 0).- Returns:
- Retrieved segment (size may be less than requested)
- Throws:
java.sql.SQLException
- If this is an output blob, the blob is closed, the transaction is not active, or a database connection error occurred.
-
putSegment
public void putSegment(byte[] segment) throws java.sql.SQLException
Description copied from interface:FbBlob
Writes a segment of blob data.Implementation must handle segment length exceeding
FbBlob.getMaximumSegmentSize()
by batching. TODO: reconsider and let caller handle that?Passing a section that is length 0 will throw an
SQLException
.- Specified by:
putSegment
in interfaceFbBlob
- Parameters:
segment
- Segment to write- Throws:
java.sql.SQLException
- If this is an input blob, the blob is closed, the transaction is not active, the segment is length 0 or longer than the maximum segment size, or a database connection error occurred.
-
seek
public void seek(int offset, FbBlob.SeekMode seekMode) throws java.sql.SQLException
Description copied from interface:FbBlob
Performs a seek on a blob with the specifiedseekMode
andoffset
.Firebird only supports seek on stream blobs.
- Specified by:
seek
in interfaceFbBlob
- Parameters:
offset
- Offset of the seek, effect depends on value ofseekMode
seekMode
- Value ofFbBlob.SeekMode
- Throws:
java.sql.SQLException
- If the blob is closed, the transaction is not active, or a database error occurred.
-
getBlobInfo
public byte[] getBlobInfo(byte[] requestItems, int bufferLength) throws java.sql.SQLException
Description copied from interface:FbBlob
Request blob info.- Specified by:
getBlobInfo
in interfaceFbBlob
- Parameters:
requestItems
- Array of info items to requestbufferLength
- Response buffer length to use- Returns:
- Response buffer
- Throws:
java.sql.SQLException
-
closeImpl
protected void closeImpl() throws java.sql.SQLException
Description copied from class:AbstractFbBlob
Internal implementation ofAbstractFbBlob.close()
. The implementation does not need to check for attached database and active transaction, nor does it need to mark this blob as closed.- Specified by:
closeImpl
in classAbstractFbBlob
- Throws:
java.sql.SQLException
-
cancelImpl
protected void cancelImpl() throws java.sql.SQLException
Description copied from class:AbstractFbBlob
Internal implementation ofAbstractFbBlob.cancel()
. The implementation does not need to check for attached database and active transaction, nor does it need to mark this blob as closed.- Specified by:
cancelImpl
in classAbstractFbBlob
- Throws:
java.sql.SQLException
-
releaseResources
protected void releaseResources()
Description copied from class:AbstractFbBlob
Release Java resources held. This should not communicate with the Firebird server.- Specified by:
releaseResources
in classAbstractFbBlob
-
-