Skip to content

Commit

Permalink
* 延迟物理连接的关闭时机
Browse files Browse the repository at this point in the history
  • Loading branch information
liuyangming committed Jan 20, 2017
1 parent 86ea9c9 commit c72e89c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,6 @@ public LogicalConnection getConnection() throws SQLException {

LogicalConnection logicalConnection = new LogicalConnection(this, this.connection);

// if (this.physicalConnectionSharingCount == 0) {
// this.xaResource.setLocalTransaction(logicalConnection);
// }

this.physicalConnectionSharingCount++;
this.underlyingConCloseRequired = false;

Expand Down Expand Up @@ -105,10 +101,6 @@ public void commitLocalTransaction() throws SQLException {
throw ex;
} catch (RuntimeException ex) {
throw new SQLException(ex);
} finally {
if (this.underlyingConCloseRequired) {
this.releaseConnection();
}
}
}

Expand All @@ -119,10 +111,6 @@ public void rollbackLocalTransaction() throws SQLException {
throw ex;
} catch (RuntimeException ex) {
throw new SQLException(ex);
} finally {
if (this.underlyingConCloseRequired) {
this.releaseConnection();
}
}
}

Expand All @@ -135,7 +123,10 @@ public void closeQuietly() {
}

public void close() throws SQLException {
this.underlyingConCloseRequired = true;
if (this.underlyingConCloseRequired == false) {
logger.warn("Illegal state: there is at least one connection that is not closed!");
}

this.releaseConnection();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public synchronized void commit(Xid xid, boolean onePhase) throws XAException {
xae.initCause(ex);
throw xae;
} finally {
this.resetXAResource();
this.releasePhysicalConnection();
}
}

Expand All @@ -232,11 +232,11 @@ public synchronized void rollback(Xid xid) throws XAException {
xae.initCause(ex);
throw xae;
} finally {
this.resetXAResource();
this.releasePhysicalConnection();
}
}

private void resetXAResource() {
private void releasePhysicalConnection() {
Connection connection = this.managedConnection.getPhysicalConnection();
try {
connection.setAutoCommit(originalAutoCommit);
Expand Down

0 comments on commit c72e89c

Please sign in to comment.