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
ConstructorsModifierConstructorDescriptionprotectedAbstractFbAttachment(T connection, DatatypeCoder datatypeCoder) -
Method Summary
Modifier and TypeMethodDescriptionfinal voidaddExceptionListener(ExceptionListener listener) Adds an exception listener to this object.protected abstract voidChecks if the attachment is connected, and throws aSQLExceptionif it isn't connected.voidForces the connection to close without proper detach or cleanup.final DatatypeCoderfinal Encodingfinal IEncodingFactoryintGets the current network timeout for this attachment.booleanCurrent attachment status.final booleanQueries if the lock is held by the current thread.final voidremoveExceptionListener(ExceptionListener listener) Removes an exception listener to this object.protected final voidChecks if not currently attached.protected final voidPerformsFbAttachment.close()suppressing any exception.protected final voidCalled when this attachment is attached.protected final voidCalled when this attachment is detached.protected final voidsetServerVersion(String... versionStrings) Sets the Firebird version from one or more version string elements.final LockCloseablewithLock()Locks the lock withLock.lock()(or equivalent).Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods 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:FbAttachmentLocks the lock withLock.lock()(or equivalent).The returned
LockClosablecan be used to unlock, preferably for use in a try-with-resources.- Specified by:
withLockin interfaceFbAttachment- Returns:
- lock closeable which unlocks the lock on close
-
isLockedByCurrentThread
public final boolean isLockedByCurrentThread()Description copied from interface:FbAttachmentQueries if the lock is held by the current thread.- Specified by:
isLockedByCurrentThreadin interfaceFbAttachment- Returns:
trueif current thread holds this lock andfalseotherwise- 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:
forceClosein interfaceFbAttachment- Throws:
SQLException- For problems closing the connection.
-
getServerVersion
- Specified by:
getServerVersionin 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
AbstractFbDatabaseinstance should call this method. -
isAttached
public boolean isAttached()Description copied from interface:FbAttachmentCurrent attachment status.- Specified by:
isAttachedin interfaceFbAttachment- Returns:
trueif connected to the server and attached to a database or service,falseotherwise.
-
setDetached
protected final void setDetached()Called when this attachment is detached.Only this
AbstractFbAttachmentinstance should call this method. -
getEncodingFactory
- Specified by:
getEncodingFactoryin interfaceFbAttachment- Returns:
- The
IEncodingFactoryfor this connection
-
getEncoding
- Specified by:
getEncodingin interfaceFbAttachment- Returns:
- The connection encoding (should be the same as returned from calling
IEncodingFactory.getDefaultEncoding()on the result ofFbAttachment.getEncodingFactory()).
-
getDatatypeCoder
- Specified by:
getDatatypeCoderin interfaceFbAttachment- Returns:
- The
DatatypeCoderfor this database implementation.
-
getNetworkTimeout
Description copied from interface:FbAttachmentGets the current network timeout for this attachment.- Specified by:
getNetworkTimeoutin 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:ExceptionListenableAdds an exception listener to this object.Implementations use
WeakReference.- Specified by:
addExceptionListenerin interfaceExceptionListenable- Parameters:
listener- Listener to register
-
removeExceptionListener
Description copied from interface:ExceptionListenableRemoves an exception listener to this object.- Specified by:
removeExceptionListenerin interfaceExceptionListenable- Parameters:
listener- Listener to remove
-
checkConnected
Checks if the attachment is connected, and throws aSQLExceptionif 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
-