Module org.firebirdsql.jaybird
Package org.firebirdsql.gds.ng
Class AbstractFbAttachment<T extends AbstractConnection<? extends IAttachProperties<?>,? extends FbAttachment>>
java.lang.Object
org.firebirdsql.gds.ng.AbstractFbAttachment<T>
- All Implemented Interfaces:
AutoCloseable
,FbAttachment
,ExceptionListenable
- Direct Known Subclasses:
AbstractFbDatabase
,AbstractFbService
public abstract class AbstractFbAttachment<T extends AbstractConnection<? extends IAttachProperties<?>,? extends FbAttachment>>
extends Object
implements FbAttachment
Common behavior for
AbstractFbService
and AbstractFbDatabase
.- Since:
- 3.0
- Author:
- Mark Rotteveel
-
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
AbstractFbAttachment
(T connection, DatatypeCoder datatypeCoder) -
Method Summary
Modifier and TypeMethodDescriptionfinal void
addExceptionListener
(ExceptionListener listener) Adds an exception listener to this object.protected abstract void
Checks if the attachment is connected, and throws aSQLException
if it isn't connected.void
Forces the connection to close without proper detach or cleanup.final DatatypeCoder
final Encoding
final IEncodingFactory
int
Gets the current network timeout for this attachment.boolean
Current attachment status.final boolean
Queries if the lock is held by the current thread.final void
removeExceptionListener
(ExceptionListener listener) Removes an exception listener to this object.protected final void
Checks if not currently attached.protected final void
PerformsFbAttachment.close()
suppressing any exception.protected final void
Called when this attachment is attached.protected final void
Called when this attachment is detached.protected final void
setServerVersion
(String... versionStrings) Sets the Firebird version from one or more version string elements.final LockCloseable
withLock()
Locks the lock withLock.lock()
(or equivalent).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.FbAttachment
attach, close, getHandle, setNetworkTimeout
-
Field Details
-
exceptionListenerDispatcher
-
connection
protected final T extends AbstractConnection<? extends IAttachProperties<?>,? extends FbAttachment> connection
-
-
Constructor Details
-
AbstractFbAttachment
-
-
Method Details
-
withLock
Description copied from interface:FbAttachment
Locks the lock withLock.lock()
(or equivalent).The returned
LockClosable
can be used to unlock, preferably for use in a try-with-resources.- Specified by:
withLock
in interfaceFbAttachment
- Returns:
- lock closeable which unlocks the lock on close
-
isLockedByCurrentThread
public final boolean isLockedByCurrentThread()Description copied from interface:FbAttachment
Queries if the lock is held by the current thread.- Specified by:
isLockedByCurrentThread
in interfaceFbAttachment
- Returns:
true
if current thread holds this lock andfalse
otherwise- See Also:
-
forceClose
Forces the connection to close without proper detach or cleanup.If a given implementation does not support this, then this method should call
FbAttachment.close()
.Default implementation, calls
FbAttachment.close()
- Specified by:
forceClose
in interfaceFbAttachment
- Throws:
SQLException
- For problems closing the connection.
-
getServerVersion
- Specified by:
getServerVersion
in interfaceFbAttachment
- Returns:
- Firebird version string
-
setServerVersion
Sets the Firebird version from one or more version string elements.This method should only be called by this instance.
- Parameters:
versionStrings
- Raw version strings
-
setAttached
protected final void setAttached()Called when this attachment is attached.Only this
AbstractFbDatabase
instance should call this method. -
isAttached
public boolean isAttached()Description copied from interface:FbAttachment
Current attachment status.- Specified by:
isAttached
in interfaceFbAttachment
- Returns:
true
if connected to the server and attached to a database or service,false
otherwise.
-
setDetached
protected final void setDetached()Called when this attachment is detached.Only this
AbstractFbAttachment
instance should call this method. -
getEncodingFactory
- Specified by:
getEncodingFactory
in interfaceFbAttachment
- Returns:
- The
IEncodingFactory
for this connection
-
getEncoding
- Specified by:
getEncoding
in interfaceFbAttachment
- Returns:
- The connection encoding (should be the same as returned from calling
IEncodingFactory.getDefaultEncoding()
on the result ofFbAttachment.getEncodingFactory()
).
-
getDatatypeCoder
- Specified by:
getDatatypeCoder
in interfaceFbAttachment
- Returns:
- The
DatatypeCoder
for this database implementation.
-
getNetworkTimeout
Description copied from interface:FbAttachment
Gets the current network timeout for this attachment.- Specified by:
getNetworkTimeout
in interfaceFbAttachment
- Returns:
- Timeout in milliseconds, 0 means no timeout
- Throws:
SQLException
- If this attachment is closedSQLFeatureNotSupportedException
- If this attachment doesn't support network timeout
-
addExceptionListener
Description copied from interface:ExceptionListenable
Adds an exception listener to this object.Implementations use
WeakReference
.- Specified by:
addExceptionListener
in interfaceExceptionListenable
- Parameters:
listener
- Listener to register
-
removeExceptionListener
Description copied from interface:ExceptionListenable
Removes an exception listener to this object.- Specified by:
removeExceptionListener
in interfaceExceptionListenable
- Parameters:
listener
- Listener to remove
-
checkConnected
Checks if the attachment is connected, and throws aSQLException
if it isn't connected.- Throws:
SQLException
-
safelyDetach
protected final void safelyDetach()PerformsFbAttachment.close()
suppressing any exception. -
requireNotAttached
Checks if not currently attached.- Throws:
SQLException
- if this attachment is currently attached- Since:
- 6
-