public JDOConnection getConnection ();
The getConnection
method returns the
datastore connection in use by the
PersistenceManager
. If the PersistenceManager
does not have a connection already, it obtains one.
The returned object implements JDOConnection
,
which provides a single method:
Object getNativeConnection ();
This method returns the underlying datastore connection, free from
all decorators. Using the raw connection is dangerous, and should
be avoided when possible. Instead, cast the JDOConnection
to the proper connection type. For example,
in a relational JDO implementation, the JDOConnection
will also implement
java.sql.Connection
.
If a JDO datastore transaction is in progress, then the returned
connection will be transactionally consistent. If an optimistic
transaction is in progress, the connection returned is only guaranteed
to be transactionally consistent if the PersistenceManager
has already flushed during the transaction. See
Section 9.1, “Transaction Types” for descriptions of
optimistic and pessimistic transaction types.
Note | |
---|---|
Kodo's |
Always close the returned connection (but not the underlying native
connection!) before attempting any other
PersistenceManager
operations. The JDO
implementation will ensure that the native connection is not released
if a transaction is in progress.