Connection wrapper that keeps an internal ref count so that it knows
when to really close.
| Method from org.apache.openjpa.jdbc.kernel.JDBCStoreManager$RefCountConnection Detail: |
public void close() throws SQLException {
// lock at broker level to avoid deadlocks
_ctx.lock();
try {
_refs--;
if (_refs < = 0 && !_retain)
free();
} finally {
_ctx.unlock();
}
}
|
protected Statement createStatement(boolean wrap) throws SQLException {
return new CancelStatement(super.createStatement(false),
RefCountConnection.this);
}
|
protected Statement createStatement(int rsType,
int rsConcur,
boolean wrap) throws SQLException {
return new CancelStatement(super.createStatement(rsType, rsConcur,
false), RefCountConnection.this);
}
|
public void free() {
// ensure that we do not close the underlying connection
// multiple times; this could happen if someone (e.g., an
// Extent) holds a RefConnection, and then closes it (e.g., in
// the finalizer) after the StoreManager has already been closed.
if (_freed)
return;
try {
getDelegate().close();
} catch (SQLException se) {
}
_freed = true;
_conn = null;
}
|
public boolean getRetain() {
return _retain;
}
|
protected PreparedStatement prepareStatement(String sql,
boolean wrap) throws SQLException {
return new CancelPreparedStatement(super.prepareStatement(sql,
false), RefCountConnection.this);
}
|
protected PreparedStatement prepareStatement(String sql,
int rsType,
int rsConcur,
boolean wrap) throws SQLException {
return new CancelPreparedStatement(super.prepareStatement(sql,
rsType, rsConcur, false), RefCountConnection.this);
}
|
public void ref() {
// don't have to lock; called from connect(), which is locked
_refs++;
}
|
public void setRetain(boolean retain) {
if (_retain && !retain && _refs < = 0)
free();
_retain = retain;
}
|