Skip to content

Commit

Permalink
bugfix: connectionproxy prepareStatement not in global transaction (a…
Browse files Browse the repository at this point in the history
  • Loading branch information
jsbxyyx authored and zjinlei committed Oct 23, 2019
1 parent 00738ac commit ab32bee
Showing 1 changed file with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,16 @@ public Statement createStatement() throws SQLException {
public PreparedStatement prepareStatement(String sql) throws SQLException {
String dbType = getDbType();
// support oracle 10.2+
PreparedStatement targetPreparedStatement;
SQLRecognizer sqlRecognizer = SQLVisitorFactory.get(sql, dbType);
if (sqlRecognizer != null && sqlRecognizer.getSQLType() == SQLType.INSERT) {
final String tableName = sqlRecognizer.getTableName();
TableMeta tableMeta = TableMetaCacheFactory.getTableMetaCache(getDataSourceProxy()).getTableMeta(getDataSourceProxy(), tableName);
targetPreparedStatement = getTargetConnection().prepareStatement(sql, new String[]{ tableMeta.getPkName() });
} else {
PreparedStatement targetPreparedStatement = null;
if (RootContext.inGlobalTransaction()) {
SQLRecognizer sqlRecognizer = SQLVisitorFactory.get(sql, dbType);
if (sqlRecognizer != null && sqlRecognizer.getSQLType() == SQLType.INSERT) {
final String tableName = sqlRecognizer.getTableName();
TableMeta tableMeta = TableMetaCacheFactory.getTableMetaCache(getDataSourceProxy()).getTableMeta(getDataSourceProxy(), tableName);
targetPreparedStatement = getTargetConnection().prepareStatement(sql, new String[]{tableMeta.getPkName()});
}
}
if (targetPreparedStatement == null) {
targetPreparedStatement = getTargetConnection().prepareStatement(sql);
}
return new PreparedStatementProxy(this, targetPreparedStatement, sql);
Expand Down

0 comments on commit ab32bee

Please sign in to comment.