Class JnaDatabase
- All Implemented Interfaces:
AutoCloseable,FbAttachment,FbDatabase,FbClientFeatureAccess,JnaAttachment,ExceptionListenable,TransactionListener
FbDatabase for native client access.- Since:
- 3.0
- Author:
- Mark Rotteveel
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final com.sun.jna.ptr.IntByReferencestatic final intstatic final intprotected final ISC_STATUS[]Fields inherited from class org.firebirdsql.gds.ng.AbstractFbDatabase
databaseListenerDispatcherFields inherited from class org.firebirdsql.gds.ng.AbstractFbAttachment
connection, exceptionListenerDispatcher -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidAdditional 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 voidChecks if the attachment is connected, and throws aSQLExceptionif it isn't connected.voidcountEvents(EventHandle eventHandle) Counts the events occurred.createBlobForInput(FbTransaction transaction, BlobParameterBuffer blobParameterBuffer, long blobId) Creates a blob for read access to an existing blob on the server.createBlobForOutput(FbTransaction transaction, BlobParameterBuffer blobParameterBuffer) Creates a blob for write access to a new blob on the server.voidCreates a new database, connection remains attached to database.createEventHandle(String eventName, EventHandler eventHandler) Creates an event handle for this database type.createStatement(FbTransaction transaction) Creates a statement associated with a transactionvoidDrops (and deletes) the currently attached database.voidexecuteImmediate(String statementText, FbTransaction transaction) Performs an execute immediate of a statement.protected voidfinalize()protected final FbClientLibrarybyte[]getDatabaseInfo(byte[] requestItems, int maxBufferLength) Performs a database info request.final EncodingDefinitionintcom.sun.jna.ptr.IntByReferenceintGets the current network timeout for this attachment.protected byte[]getTransactionIdBuffer(long transactionId) booleanhasFeature(FbClientFeature clientFeature) Checks for presence of a client feature.protected voidActual implementation of database detach.voidprocessStatusVector(ISC_STATUS[] statusVector, WarningMessageCallback warningMessageCallback) voidqueueEvent(EventHandle eventHandle) Queues a wait for an event.reconnectTransaction(long transactionId) Reconnects a prepared transaction.voidsetNetworkTimeout(int milliseconds) Sets the network timeout for this attachment.Creates and starts a transaction.protected JnaEventHandlevalidateEventHandle(EventHandle eventHandle) Methods inherited from class org.firebirdsql.gds.ng.AbstractFbDatabase
addDatabaseListener, addWeakDatabaseListener, close, createBlobParameterBuffer, createTransactionParameterBuffer, emptyRowDescriptor, getActiveTransactionCount, getConnectionDialect, getConnectionProperties, getDatabaseDialect, getDatabaseInfo, getDatabaseInformationProcessor, getDatabaseWarningCallback, getDescribeDatabaseInfoBlock, getOdsMajor, getOdsMinor, getParameterDescriptionInfoRequestItems, getStatementInfoRequestItems, removeDatabaseListener, setDatabaseDialect, setOdsMajor, setOdsMinor, transactionAdded, transactionStateChangedMethods inherited from class org.firebirdsql.gds.ng.AbstractFbAttachment
addExceptionListener, forceClose, getDatatypeCoder, getEncoding, getEncodingFactory, getServerVersion, getServerVersionInformation, getSynchronizationObject, isAttached, removeExceptionListener, safelyDetach, setAttached, setDetached, setServerVersionMethods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.firebirdsql.gds.ng.listeners.ExceptionListenable
addExceptionListener, removeExceptionListenerMethods inherited from interface org.firebirdsql.gds.ng.FbAttachment
close, forceClose, getDatatypeCoder, getEncoding, getEncodingFactory, getServerVersion, getSynchronizationObject, isAttachedMethods inherited from interface org.firebirdsql.gds.ng.listeners.TransactionListener
transactionStateChanged
-
Field Details
-
STATUS_VECTOR_SIZE
public static final int STATUS_VECTOR_SIZE- See Also:
-
MAX_STATEMENT_LENGTH
public static final int MAX_STATEMENT_LENGTH- See Also:
-
handle
protected final com.sun.jna.ptr.IntByReference handle -
statusVector
-
-
Constructor Details
-
JnaDatabase
-
-
Method Details
-
getClientLibrary
- Returns:
- The client library instance associated with the database.
-
checkConnected
Description copied from class:AbstractFbAttachmentChecks if the attachment is connected, and throws aSQLExceptionif it isn't connected.- Specified by:
checkConnectedin classAbstractFbAttachment<JnaDatabaseConnection>- Throws:
SQLException
-
internalDetach
Description 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 classAbstractFbDatabase<JnaDatabaseConnection>- Throws:
SQLException
-
attach
Description copied from interface:FbAttachmentAttach to the attachment type.- Specified by:
attachin interfaceFbAttachment- Throws:
SQLException
-
attachOrCreate
- Throws:
SQLException
-
afterAttachActions
Additional tasks to execute directly after attach operation.Implementation retrieves database information like dialect ODS and server version.
- Throws:
SQLException- For errors reading or writing database information.
-
createDatabase
Description copied from interface:FbDatabaseCreates a new database, connection remains attached to database.- Specified by:
createDatabasein interfaceFbDatabase- Throws:
SQLException
-
dropDatabase
Description copied from interface:FbDatabaseDrops (and deletes) the currently attached database.- Specified by:
dropDatabasein interfaceFbDatabase- Throws:
SQLException
-
cancelOperation
Description 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 interfaceFbDatabase- Parameters:
kind- Cancellation type- Throws:
SQLException- For errors cancelling, or if the cancel operation is not supported.
-
startTransaction
Description copied from interface:FbDatabaseCreates and starts a transaction.- Specified by:
startTransactionin interfaceFbDatabase- Parameters:
tpb- TransactionParameterBuffer with the required transaction options- Returns:
- FbTransaction
- Throws:
SQLException
-
reconnectTransaction
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 interfaceFbDatabase- Parameters:
transactionId- The id of the transaction to reconnect.- Returns:
- FbTransaction
- Throws:
SQLException- For errors reconnecting the transaction
-
getTransactionIdBuffer
protected byte[] getTransactionIdBuffer(long transactionId) -
createStatement
Description copied from interface:FbDatabaseCreates a statement associated with a transaction- Specified by:
createStatementin interfaceFbDatabase- Parameters:
transaction- FbTransaction to associate with this statement (can benull).- Returns:
- FbStatement
- Throws:
SQLException
-
createBlobForOutput
public 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 interfaceFbDatabase- Parameters:
transaction- Transaction associated with the blob.blobParameterBuffer- Blob Parameter Buffer- Returns:
- Instance of
FbBlob
-
createBlobForInput
public 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 interfaceFbDatabase- Parameters:
transaction- Transaction associated with the blob.blobParameterBuffer- Blob Parameter BufferblobId- Handle id of the blob- Returns:
- Instance of
FbBlob
-
getDatabaseInfo
Description copied from interface:FbDatabasePerforms a database info request.- Specified by:
getDatabaseInfoin interfaceFbDatabase- Parameters:
requestItems- Information items to requestmaxBufferLength- Maximum response buffer length to use- Returns:
- The response buffer (note: length is the actual length of the
response, not
maxBufferLength - Throws:
SQLException- For errors retrieving the information.
-
executeImmediate
Description 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 interfaceFbDatabase- Parameters:
statementText- Statement texttransaction- Transaction (nullonly allowed if database is not attached!)- Throws:
SQLException- For errors executing the statement, or iftransactionisnullwhen the database is attached or notnullwhen the database is not attached
-
getHandle
public int getHandle()- Specified by:
getHandlein interfaceFbAttachment- Specified by:
getHandlein interfaceFbDatabase- Returns:
- The attachment handle value
-
setNetworkTimeout
Description copied from interface:FbAttachmentSets the network timeout for this attachment.- Specified by:
setNetworkTimeoutin interfaceFbAttachment- 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:
SQLException- If this attachment is closed, the value ofmillisecondsis smaller than 0, or if setting the timeout fails.SQLFeatureNotSupportedException- If this attachment doesn't support (changing) the network timeout.
-
getNetworkTimeout
Description copied from interface:FbAttachmentGets the current network timeout for this attachment.- Specified by:
getNetworkTimeoutin interfaceFbAttachment- Overrides:
getNetworkTimeoutin classAbstractFbAttachment<JnaDatabaseConnection>- Returns:
- Timeout in milliseconds, 0 means no timeout
- Throws:
SQLException- If this attachment is closedSQLFeatureNotSupportedException- If this attachment doesn't support network timeout
-
getJnaHandle
public com.sun.jna.ptr.IntByReference getJnaHandle() -
getEncodingDefinition
-
validateEventHandle
- Throws:
SQLException
-
createEventHandle
public JnaEventHandle createEventHandle(String eventName, EventHandler eventHandler) throws 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 interfaceFbDatabase- Parameters:
eventName- Name of the eventeventHandler- The event handler to call when the event occurred- Returns:
- A suitable event handle instance
- Throws:
SQLException- For errors creating the event handle
-
countEvents
Description copied from interface:FbDatabaseCounts the events occurred.- Specified by:
countEventsin interfaceFbDatabase- Parameters:
eventHandle- The event handle- Throws:
SQLException- When the count can not be done (as - for example - the event handle is of the wrong type)
-
queueEvent
Description copied from interface:FbDatabaseQueues a wait for an event.- Specified by:
queueEventin interfaceFbDatabase- Parameters:
eventHandle- The event handle (created usingFbDatabase.createEventHandle(String, EventHandler)of this instance).- Throws:
SQLException- For errors establishing the asynchronous channel, or for queuing the event.
-
cancelEvent
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 interfaceFbDatabase- Parameters:
eventHandle- The event handle to cancel- Throws:
SQLException- For errors cancelling the event
-
processStatusVector
public void processStatusVector(ISC_STATUS[] statusVector, WarningMessageCallback warningMessageCallback) throws SQLException - Throws:
SQLException
-
finalize
-
hasFeature
Description copied from interface:FbClientFeatureAccessChecks for presence of a client feature.- Specified by:
hasFeaturein interfaceFbClientFeatureAccess- Parameters:
clientFeature- Client feature- Returns:
trueif the feature is present,falseotherwise
-
getFeatures
- Specified by:
getFeaturesin interfaceFbClientFeatureAccess- Returns:
- an unmodifiable set with supported client features
-