public interface ConnectionBoundObject
Statement, ResultSet or DatabaseMetaData wrapper).
The wrapper records the internal connection it was created on. Before running a method that would operate on the database, the wrapper pipeline compares the recorded connection against the current one: a difference means the internal connection was swapped out (failover or read/write splitting) after this object was created, so the object belongs to the previous session and must not be used.
Recording the connection replaces asking the target driver which connection the underlying
object is bound to. Driver-reported bindings are not reliable for this purpose: a driver may hand
out an object bound to the physical connection while the wrapper holds a pooled or logical handle
that wraps that same physical connection (for example a ResultSet obtained from
java.sql.Array#getResultSet, or a statement from a pooled XA connection). Those are the
same session, but they are not reference-identical, which used to be reported as a stale object.
Recording it also avoids calling into the target driver (Statement.getConnection() may
block) on every guarded invocation.
| Modifier and Type | Method and Description |
|---|---|
java.sql.Connection |
getCreatedOnConnection()
The internal connection that was current when this object was created, or the connection its
underlying object was last re-created on.
|
void |
setCreatedOnConnection(java.sql.Connection connection)
Records the internal connection this object now belongs to.
|
java.sql.Connection getCreatedOnConnection()
void setCreatedOnConnection(java.sql.Connection connection)
Rebindable.rebind(Connection)), so the object is no
longer considered stale.connection - the internal connection this object is now bound to.