Class JnaDatabase
- java.lang.Object
- 
- org.firebirdsql.gds.ng.AbstractFbAttachment<T>
- 
- org.firebirdsql.gds.ng.AbstractFbDatabase<JnaDatabaseConnection>
- 
- org.firebirdsql.gds.ng.jna.JnaDatabase
 
 
 
- 
- All Implemented Interfaces:
- java.lang.AutoCloseable,- FbAttachment,- FbDatabase,- FbClientFeatureAccess,- JnaAttachment,- ExceptionListenable,- TransactionListener
 
 public class JnaDatabase extends AbstractFbDatabase<JnaDatabaseConnection> implements JnaAttachment, TransactionListener, FbClientFeatureAccess Implementation ofFbDatabasefor native client access.- Since:
- 3.0
- Author:
- Mark Rotteveel
 
- 
- 
Field SummaryFields Modifier and Type Field Description protected com.sun.jna.ptr.IntByReferencehandlestatic intMAX_STATEMENT_LENGTHstatic intSTATUS_VECTOR_SIZEprotected ISC_STATUS[]statusVector- 
Fields inherited from class org.firebirdsql.gds.ng.AbstractFbDatabasedatabaseListenerDispatcher
 - 
Fields inherited from class org.firebirdsql.gds.ng.AbstractFbAttachmentconnection, exceptionListenerDispatcher
 
- 
 - 
Constructor SummaryConstructors Constructor Description JnaDatabase(JnaDatabaseConnection connection)
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidafterAttachActions()Additional tasks to execute directly after attach operation.voidattach()Attach to the attachment type.protected voidattachOrCreate(DatabaseParameterBuffer dpb, boolean create)voidcancelEvent(EventHandle eventHandle)Cancels a registered event.voidcancelOperation(int kind)Cancels the current operation.protected voidcheckConnected()Checks if the attachment is connected, and throws aSQLExceptionif it isn't connected.voidcountEvents(EventHandle eventHandle)Counts the events occurred.FbBlobcreateBlobForInput(FbTransaction transaction, BlobParameterBuffer blobParameterBuffer, long blobId)Creates a blob for read access to an existing blob on the server.FbBlobcreateBlobForOutput(FbTransaction transaction, BlobParameterBuffer blobParameterBuffer)Creates a blob for write access to a new blob on the server.voidcreateDatabase()Creates a new database, connection remains attached to database.JnaEventHandlecreateEventHandle(java.lang.String eventName, EventHandler eventHandler)Creates an event handle for this database type.JnaStatementcreateStatement(FbTransaction transaction)Creates a statement associated with a transactionvoiddropDatabase()Drops (and deletes) the currently attached database.voidexecuteImmediate(java.lang.String statementText, FbTransaction transaction)Performs an execute immediate of a statement.protected voidfinalize()protected FbClientLibrarygetClientLibrary()byte[]getDatabaseInfo(byte[] requestItems, int maxBufferLength)Performs a database info request.EncodingDefinitiongetEncodingDefinition()java.util.Set<FbClientFeature>getFeatures()intgetHandle()com.sun.jna.ptr.IntByReferencegetJnaHandle()intgetNetworkTimeout()Gets the current network timeout for this attachment.protected byte[]getTransactionIdBuffer(long transactionId)booleanhasFeature(FbClientFeature clientFeature)Checks for presence of a client feature.protected voidinternalDetach()Actual implementation of database detach.voidprocessStatusVector(ISC_STATUS[] statusVector, WarningMessageCallback warningMessageCallback)voidqueueEvent(EventHandle eventHandle)Queues a wait for an event.FbTransactionreconnectTransaction(long transactionId)Reconnects a prepared transaction.voidsetNetworkTimeout(int milliseconds)Sets the network timeout for this attachment.JnaTransactionstartTransaction(TransactionParameterBuffer tpb)Creates and starts a transaction.protected JnaEventHandlevalidateEventHandle(EventHandle eventHandle)- 
Methods inherited from class org.firebirdsql.gds.ng.AbstractFbDatabaseaddDatabaseListener, addWeakDatabaseListener, close, createBlobParameterBuffer, createTransactionParameterBuffer, emptyRowDescriptor, getActiveTransactionCount, getConnectionDialect, getConnectionProperties, getDatabaseDialect, getDatabaseInfo, getDatabaseInformationProcessor, getDatabaseWarningCallback, getDescribeDatabaseInfoBlock, getOdsMajor, getOdsMinor, getParameterDescriptionInfoRequestItems, getStatementInfoRequestItems, removeDatabaseListener, setDatabaseDialect, setOdsMajor, setOdsMinor, transactionAdded, transactionStateChanged
 - 
Methods inherited from class org.firebirdsql.gds.ng.AbstractFbAttachmentaddExceptionListener, forceClose, getDatatypeCoder, getEncoding, getEncodingFactory, getServerVersion, getServerVersionInformation, getSynchronizationObject, isAttached, removeExceptionListener, safelyDetach, setAttached, setDetached, setServerVersion
 - 
Methods inherited from class java.lang.Objectclone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 - 
Methods inherited from interface org.firebirdsql.gds.ng.listeners.ExceptionListenableaddExceptionListener, removeExceptionListener
 - 
Methods inherited from interface org.firebirdsql.gds.ng.FbAttachmentclose, forceClose, getDatatypeCoder, getEncoding, getEncodingFactory, getServerVersion, getSynchronizationObject, isAttached
 - 
Methods inherited from interface org.firebirdsql.gds.ng.listeners.TransactionListenertransactionStateChanged
 
- 
 
- 
- 
- 
Field Detail- 
STATUS_VECTOR_SIZEpublic static final int STATUS_VECTOR_SIZE - See Also:
- Constant Field Values
 
 - 
MAX_STATEMENT_LENGTHpublic static final int MAX_STATEMENT_LENGTH - See Also:
- Constant Field Values
 
 - 
handleprotected final com.sun.jna.ptr.IntByReference handle 
 - 
statusVectorprotected final ISC_STATUS[] statusVector 
 
- 
 - 
Constructor Detail- 
JnaDatabasepublic JnaDatabase(JnaDatabaseConnection connection) 
 
- 
 - 
Method Detail- 
getClientLibraryprotected final FbClientLibrary getClientLibrary() - Returns:
- The client library instance associated with the database.
 
 - 
checkConnectedprotected void checkConnected() throws java.sql.SQLExceptionDescription copied from class:AbstractFbAttachmentChecks if the attachment is connected, and throws aSQLExceptionif it isn't connected.- Specified by:
- checkConnectedin class- AbstractFbAttachment<JnaDatabaseConnection>
- Throws:
- java.sql.SQLException
 
 - 
internalDetachprotected void internalDetach() throws java.sql.SQLExceptionDescription copied from class:AbstractFbDatabaseActual implementation of database detach.Implementations of this method should only be called from AbstractFbDatabase.close(), and should not notify database listeners of the databaseDatabaseListener.detaching(FbDatabase)andDatabaseListener.detached(FbDatabase)events.- Specified by:
- internalDetachin class- AbstractFbDatabase<JnaDatabaseConnection>
- Throws:
- java.sql.SQLException
 
 - 
attachpublic void attach() throws java.sql.SQLExceptionDescription copied from interface:FbAttachmentAttach to the attachment type.- Specified by:
- attachin interface- FbAttachment
- Throws:
- java.sql.SQLException
 
 - 
attachOrCreateprotected void attachOrCreate(DatabaseParameterBuffer dpb, boolean create) throws java.sql.SQLException - Throws:
- java.sql.SQLException
 
 - 
afterAttachActionsprotected void afterAttachActions() throws java.sql.SQLExceptionAdditional tasks to execute directly after attach operation.Implementation retrieves database information like dialect ODS and server version. - Throws:
- java.sql.SQLException- For errors reading or writing database information.
 
 - 
createDatabasepublic void createDatabase() throws java.sql.SQLExceptionDescription copied from interface:FbDatabaseCreates a new database, connection remains attached to database.- Specified by:
- createDatabasein interface- FbDatabase
- Throws:
- java.sql.SQLException
 
 - 
dropDatabasepublic void dropDatabase() throws java.sql.SQLExceptionDescription copied from interface:FbDatabaseDrops (and deletes) the currently attached database.- Specified by:
- dropDatabasein interface- FbDatabase
- Throws:
- java.sql.SQLException
 
 - 
cancelOperationpublic void cancelOperation(int kind) throws java.sql.SQLExceptionDescription copied from interface:FbDatabaseCancels the current operation.The cancellation types are: - ISCConstants.fb_cancel_disable
- disables execution of fb_cancel_raise requests for the specified attachment. It can be useful when your program is executing critical operations, such as cleanup, for example.
- ISCConstants.fb_cancel_enable
- re-enables delivery of a cancel execution that was previously disabled. The 'cancel' state is effective by default, being initialized when the attachment is created.
- ISCConstants.fb_cancel_raise
- cancels any activity related to the database handle. The effect will be that, as soon as possible, the engine will try to stop the running request and return an exception to the caller
- ISCConstants.fb_cancel_abort
- forcibly close client side of connection. Useful if you need to close a connection urgently. All active transactions will be rolled back by the server. 'Success' is always returned to the application. Use with care!
 - Specified by:
- cancelOperationin interface- FbDatabase
- Parameters:
- kind- Cancellation type
- Throws:
- java.sql.SQLException- For errors cancelling, or if the cancel operation is not supported.
 
 - 
startTransactionpublic JnaTransaction startTransaction(TransactionParameterBuffer tpb) throws java.sql.SQLException Description copied from interface:FbDatabaseCreates and starts a transaction.- Specified by:
- startTransactionin interface- FbDatabase
- Parameters:
- tpb- TransactionParameterBuffer with the required transaction options
- Returns:
- FbTransaction
- Throws:
- java.sql.SQLException
 
 - 
reconnectTransactionpublic FbTransaction reconnectTransaction(long transactionId) throws java.sql.SQLException Description copied from interface:FbDatabaseReconnects a prepared transaction.Reconnecting transactions is only allowed for transactions in limbo (prepared, but not committed or rolled back). - Specified by:
- reconnectTransactionin interface- FbDatabase
- Parameters:
- transactionId- The id of the transaction to reconnect.
- Returns:
- FbTransaction
- Throws:
- java.sql.SQLException- For errors reconnecting the transaction
 
 - 
getTransactionIdBufferprotected byte[] getTransactionIdBuffer(long transactionId) 
 - 
createStatementpublic JnaStatement createStatement(FbTransaction transaction) throws java.sql.SQLException Description copied from interface:FbDatabaseCreates a statement associated with a transaction- Specified by:
- createStatementin interface- FbDatabase
- Parameters:
- transaction- FbTransaction to associate with this statement (can be- null).
- Returns:
- FbStatement
- Throws:
- java.sql.SQLException
 
 - 
createBlobForOutputpublic FbBlob createBlobForOutput(FbTransaction transaction, BlobParameterBuffer blobParameterBuffer) Description copied from interface:FbDatabaseCreates a blob for write access to a new blob on the server.The blob is initially closed. - Specified by:
- createBlobForOutputin interface- FbDatabase
- Parameters:
- transaction- Transaction associated with the blob.
- blobParameterBuffer- Blob Parameter Buffer
- Returns:
- Instance of FbBlob
 
 - 
createBlobForInputpublic FbBlob createBlobForInput(FbTransaction transaction, BlobParameterBuffer blobParameterBuffer, long blobId) Description copied from interface:FbDatabaseCreates a blob for read access to an existing blob on the server.The blob is initially closed. - Specified by:
- createBlobForInputin interface- FbDatabase
- Parameters:
- transaction- Transaction associated with the blob.
- blobParameterBuffer- Blob Parameter Buffer
- blobId- Handle id of the blob
- Returns:
- Instance of FbBlob
 
 - 
getDatabaseInfopublic byte[] getDatabaseInfo(byte[] requestItems, int maxBufferLength) throws java.sql.SQLExceptionDescription copied from interface:FbDatabasePerforms a database info request.- Specified by:
- getDatabaseInfoin interface- FbDatabase
- Parameters:
- requestItems- Information items to request
- maxBufferLength- Maximum response buffer length to use
- Returns:
- The response buffer (note: length is the actual length of the
 response, not maxBufferLength
- Throws:
- java.sql.SQLException- For errors retrieving the information.
 
 - 
executeImmediatepublic void executeImmediate(java.lang.String statementText, FbTransaction transaction) throws java.sql.SQLExceptionDescription copied from interface:FbDatabasePerforms an execute immediate of a statement.A call to this method is the equivalent of a isc_dsql_execute_immediate()without parameters.- Specified by:
- executeImmediatein interface- FbDatabase
- Parameters:
- statementText- Statement text
- transaction- Transaction (- nullonly allowed if database is not attached!)
- Throws:
- java.sql.SQLException- For errors executing the statement, or if- transactionis- nullwhen the database is attached or not- nullwhen the database is not attached
 
 - 
getHandlepublic int getHandle() - Specified by:
- getHandlein interface- FbAttachment
- Specified by:
- getHandlein interface- FbDatabase
- Returns:
- The attachment handle value
 
 - 
setNetworkTimeoutpublic void setNetworkTimeout(int milliseconds) throws java.sql.SQLExceptionDescription copied from interface:FbAttachmentSets the network timeout for this attachment.- Specified by:
- setNetworkTimeoutin interface- FbAttachment
- Parameters:
- milliseconds- Timeout in milliseconds; 0 means no timeout. If the attachment doesn't support milliseconds, it should round up to the nearest second.
- Throws:
- java.sql.SQLException- If this attachment is closed, the value of- millisecondsis smaller than 0, or if setting the timeout fails.
- java.sql.SQLFeatureNotSupportedException- If this attachment doesn't support (changing) the network timeout.
 
 - 
getNetworkTimeoutpublic int getNetworkTimeout() throws java.sql.SQLExceptionDescription copied from interface:FbAttachmentGets the current network timeout for this attachment.- Specified by:
- getNetworkTimeoutin interface- FbAttachment
- Overrides:
- getNetworkTimeoutin class- AbstractFbAttachment<JnaDatabaseConnection>
- Returns:
- Timeout in milliseconds, 0 means no timeout
- Throws:
- java.sql.SQLException- If this attachment is closed
- java.sql.SQLFeatureNotSupportedException- If this attachment doesn't support network timeout
 
 - 
getJnaHandlepublic com.sun.jna.ptr.IntByReference getJnaHandle() 
 - 
getEncodingDefinitionpublic final EncodingDefinition getEncodingDefinition() 
 - 
validateEventHandleprotected JnaEventHandle validateEventHandle(EventHandle eventHandle) throws java.sql.SQLException - Throws:
- java.sql.SQLException
 
 - 
createEventHandlepublic JnaEventHandle createEventHandle(java.lang.String eventName, EventHandler eventHandler) throws java.sql.SQLException Description copied from interface:FbDatabaseCreates an event handle for this database type.The returned event handle can be used with FbDatabase.queueEvent(org.firebirdsql.gds.EventHandle).- Specified by:
- createEventHandlein interface- FbDatabase
- Parameters:
- eventName- Name of the event
- eventHandler- The event handler to call when the event occurred
- Returns:
- A suitable event handle instance
- Throws:
- java.sql.SQLException- For errors creating the event handle
 
 - 
countEventspublic void countEvents(EventHandle eventHandle) throws java.sql.SQLException Description copied from interface:FbDatabaseCounts the events occurred.- Specified by:
- countEventsin interface- FbDatabase
- Parameters:
- eventHandle- The event handle
- Throws:
- java.sql.SQLException- When the count can not be done (as - for example - the event handle is of the wrong type)
 
 - 
queueEventpublic void queueEvent(EventHandle eventHandle) throws java.sql.SQLException Description copied from interface:FbDatabaseQueues a wait for an event.- Specified by:
- queueEventin interface- FbDatabase
- Parameters:
- eventHandle- The event handle (created using- FbDatabase.createEventHandle(String, EventHandler)of this instance).
- Throws:
- java.sql.SQLException- For errors establishing the asynchronous channel, or for queuing the event.
 
 - 
cancelEventpublic void cancelEvent(EventHandle eventHandle) throws java.sql.SQLException Description copied from interface:FbDatabaseCancels a registered event.After cancellation, the event handle should be considered unusable. Before queueing a new event, an new handle needs to be created. - Specified by:
- cancelEventin interface- FbDatabase
- Parameters:
- eventHandle- The event handle to cancel
- Throws:
- java.sql.SQLException- For errors cancelling the event
 
 - 
processStatusVectorpublic void processStatusVector(ISC_STATUS[] statusVector, WarningMessageCallback warningMessageCallback) throws java.sql.SQLException - Throws:
- java.sql.SQLException
 
 - 
finalizeprotected void finalize() throws java.lang.Throwable- Overrides:
- finalizein class- java.lang.Object
- Throws:
- java.lang.Throwable
 
 - 
hasFeaturepublic boolean hasFeature(FbClientFeature clientFeature) Description copied from interface:FbClientFeatureAccessChecks for presence of a client feature.- Specified by:
- hasFeaturein interface- FbClientFeatureAccess
- Parameters:
- clientFeature- Client feature
- Returns:
- trueif the feature is present,- falseotherwise
 
 - 
getFeaturespublic java.util.Set<FbClientFeature> getFeatures() - Specified by:
- getFeaturesin interface- FbClientFeatureAccess
- Returns:
- an unmodifiable set with supported client features
 
 
- 
 
-