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 Summary
Fields 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.AbstractFbDatabase
databaseListenerDispatcher
-
Fields inherited from class org.firebirdsql.gds.ng.AbstractFbAttachment
connection, exceptionListenerDispatcher
-
-
Constructor Summary
Constructors Constructor Description JnaDatabase(JnaDatabaseConnection connection)
-
Method Summary
All 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.AbstractFbDatabase
addDatabaseListener, 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.AbstractFbAttachment
addExceptionListener, forceClose, getDatatypeCoder, getEncoding, getEncodingFactory, getServerVersion, getServerVersionInformation, isAttached, isLockedByCurrentThread, removeExceptionListener, safelyDetach, setAttached, setDetached, setServerVersion, withLock
-
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.firebirdsql.gds.ng.listeners.ExceptionListenable
addExceptionListener, removeExceptionListener
-
Methods inherited from interface org.firebirdsql.gds.ng.FbAttachment
close, forceClose, getDatatypeCoder, getEncoding, getEncodingFactory, getServerVersion, isAttached, isLockedByCurrentThread, withLock
-
Methods inherited from interface org.firebirdsql.gds.ng.FbDatabase
createBlobForInput, createBlobForInput, createBlobForOutput, createBlobForOutput
-
Methods inherited from interface org.firebirdsql.gds.ng.listeners.TransactionListener
transactionStateChanged
-
-
-
-
Field Detail
-
STATUS_VECTOR_SIZE
public static final int STATUS_VECTOR_SIZE
- See Also:
- Constant Field Values
-
MAX_STATEMENT_LENGTH
public static final int MAX_STATEMENT_LENGTH
- See Also:
- Constant Field Values
-
handle
protected final com.sun.jna.ptr.IntByReference handle
-
statusVector
protected final ISC_STATUS[] statusVector
-
-
Constructor Detail
-
JnaDatabase
public JnaDatabase(JnaDatabaseConnection connection)
-
-
Method Detail
-
getClientLibrary
protected final FbClientLibrary getClientLibrary()
- Returns:
- The client library instance associated with the database.
-
checkConnected
protected 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 classAbstractFbAttachment<JnaDatabaseConnection>- Throws:
java.sql.SQLException
-
internalDetach
protected 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 classAbstractFbDatabase<JnaDatabaseConnection>- Throws:
java.sql.SQLException
-
attach
public void attach() throws java.sql.SQLExceptionDescription copied from interface:FbAttachmentAttach to the attachment type.- Specified by:
attachin interfaceFbAttachment- Throws:
java.sql.SQLException
-
attachOrCreate
protected void attachOrCreate(DatabaseParameterBuffer dpb, boolean create) throws java.sql.SQLException
- Throws:
java.sql.SQLException
-
afterAttachActions
protected 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.
-
createDatabase
public void createDatabase() throws java.sql.SQLExceptionDescription copied from interface:FbDatabaseCreates a new database, connection remains attached to database.- Specified by:
createDatabasein interfaceFbDatabase- Throws:
java.sql.SQLException
-
dropDatabase
public void dropDatabase() throws java.sql.SQLExceptionDescription copied from interface:FbDatabaseDrops (and deletes) the currently attached database.- Specified by:
dropDatabasein interfaceFbDatabase- Throws:
java.sql.SQLException
-
cancelOperation
public 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 interfaceFbDatabase- Parameters:
kind- Cancellation type- Throws:
java.sql.SQLException- For errors cancelling, or if the cancel operation is not supported.
-
startTransaction
public JnaTransaction startTransaction(TransactionParameterBuffer tpb) throws java.sql.SQLException
Description copied from interface:FbDatabaseCreates and starts a transaction.- Specified by:
startTransactionin interfaceFbDatabase- Parameters:
tpb- TransactionParameterBuffer with the required transaction options- Returns:
- FbTransaction
- Throws:
java.sql.SQLException
-
reconnectTransaction
public 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 interfaceFbDatabase- Parameters:
transactionId- The id of the transaction to reconnect.- Returns:
- FbTransaction
- Throws:
java.sql.SQLException- For errors reconnecting the transaction
-
getTransactionIdBuffer
protected byte[] getTransactionIdBuffer(long transactionId)
-
createStatement
public JnaStatement createStatement(FbTransaction transaction) throws java.sql.SQLException
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:
java.sql.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 blobblobParameterBuffer- 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 blobblobParameterBuffer- blob parameter bufferblobId- id of the blob- Returns:
- instance of
FbBlob
-
getDatabaseInfo
public byte[] getDatabaseInfo(byte[] requestItems, int maxBufferLength) throws java.sql.SQLExceptionDescription 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:
java.sql.SQLException- For errors retrieving the information.
-
executeImmediate
public 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 interfaceFbDatabase- Parameters:
statementText- Statement texttransaction- Transaction (nullonly allowed if database is not attached!)- Throws:
java.sql.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
public void setNetworkTimeout(int milliseconds) throws java.sql.SQLExceptionDescription 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:
java.sql.SQLException- If this attachment is closed, the value ofmillisecondsis smaller than 0, or if setting the timeout fails.java.sql.SQLFeatureNotSupportedException- If this attachment doesn't support (changing) the network timeout.
-
getNetworkTimeout
public int getNetworkTimeout() throws java.sql.SQLExceptionDescription 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:
java.sql.SQLException- If this attachment is closedjava.sql.SQLFeatureNotSupportedException- If this attachment doesn't support network timeout
-
getJnaHandle
public com.sun.jna.ptr.IntByReference getJnaHandle()
-
getEncodingDefinition
public final EncodingDefinition getEncodingDefinition()
-
validateEventHandle
protected JnaEventHandle validateEventHandle(EventHandle eventHandle) throws java.sql.SQLException
- Throws:
java.sql.SQLException
-
createEventHandle
public 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 interfaceFbDatabase- Parameters:
eventName- Name of the eventeventHandler- 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
-
countEvents
public void countEvents(EventHandle eventHandle) throws java.sql.SQLException
Description copied from interface:FbDatabaseCounts the events occurred.- Specified by:
countEventsin interfaceFbDatabase- 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)
-
queueEvent
public void queueEvent(EventHandle eventHandle) throws java.sql.SQLException
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:
java.sql.SQLException- For errors establishing the asynchronous channel, or for queuing the event.
-
cancelEvent
public 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 interfaceFbDatabase- Parameters:
eventHandle- The event handle to cancel- Throws:
java.sql.SQLException- For errors cancelling the event
-
processStatusVector
public void processStatusVector(ISC_STATUS[] statusVector, WarningMessageCallback warningMessageCallback) throws java.sql.SQLException
- Throws:
java.sql.SQLException
-
finalize
protected void finalize() throws java.lang.Throwable- Overrides:
finalizein classjava.lang.Object- Throws:
java.lang.Throwable
-
hasFeature
public boolean hasFeature(FbClientFeature clientFeature)
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
public java.util.Set<FbClientFeature> getFeatures()
- Specified by:
getFeaturesin interfaceFbClientFeatureAccess- Returns:
- an unmodifiable set with supported client features
-
-