apache / incubator-seata

:fire: Seata is an easy-to-use, high-performance, open source distributed transaction solution.
https://seata.apache.org/
Apache License 2.0
25.29k stars 8.78k forks source link

When getting the primary key index, jdbc will get a null pointer when it encounters oracle12c #1383

Open majiajue opened 5 years ago

majiajue commented 5 years ago

Ⅰ. Issue Description

1.获取主键索引时,jdbc在oracle12c上遇到会获取到空指针的情况下有可能是驱动问题影响的,所以换成了从数据库中查询,更改了TableMetaCacheOracle中resultSetMetaToSchema 方法获取主键索引修改为:

  try (Statement stmt = conn.getTargetConnection().createStatement();
             ResultSet rs1 = stmt.executeQuery(
                     String.format("select a.constraint_name, a.column_name from user_cons_columns a, user_constraints b  " +
                                     "where a.constraint_name = b.constraint_name and b.constraint_type = 'P' and a.table_name ='%s'",
                             tableName))) {
            while (rs1.next()) {
                String indexName = rs1.getString(1);
                String colName = rs1.getString(2);
                ColumnMeta col = tm.getAllColumns().get(colName);

                if (tm.getAllIndexes().containsKey(indexName)) {
                    IndexMeta index = tm.getAllIndexes().get(indexName);
                    index.getValues().add(col);
                } else {
                    IndexMeta index = new IndexMeta();
                    index.setIndexName(indexName);
                    index.getValues().add(col);
                    index.setIndextype(IndexType.PRIMARY);
                    tm.getAllIndexes().put(indexName, index);

                }
            }
        }

Ⅱ. Describe what happened

If there is an exception, please attach the exception trace:

Just paste your stack trace here!

Ⅲ. Describe what you expected to happen

Ⅳ. How to reproduce it (as minimally and precisely as possible)

  1. xxx
  2. xxx
  3. xxx

Ⅴ. Anything else we need to know?

Ⅵ. Environment:

fescar-robot commented 5 years ago

Hi @majiajue, we detect non-English characters in the issue. This comment is an auto translation from @fescar-robot to help other users to understand this issue. We encourage you to describe your issue in English which is more friendly to other users.

When getting the primary key index, jdbc will get a null pointer when it encounters oracle12c

Ⅰ. Issue Description

  1. When getting the primary key index, jdbc will encounter the driver problem when it encounters the null pointer on oracle12c, so it is replaced by the query from the database, and the resultSetMetaToSchema method in TableMetaCacheOracle is changed to obtain the primary key index.

    try (Statement stmt = conn.getTargetConnection().createStatement();
             ResultSet rs1 = stmt.executeQuery(
                     String.format("select a.constraint_name, a.column_name from user_cons_columns a, user_constraints b  " +
                                     "where a.constraint_name = b.constraint_name and b.constraint_type = 'P' and a.table_name ='%s'",
                             tableName))) {
            while (rs1.next()) {
                String indexName = rs1.getString(1);
                String colName = rs1.getString(2);
                ColumnMeta col = tm.getAllColumns().get(colName);
    
                if (tm.getAllIndexes().containsKey(indexName)) {
                    IndexMeta index = tm.getAllIndexes().get(indexName);
                    index.getValues().add(col);
                } else {
                    IndexMeta index = new IndexMeta();
                    index.setIndexName(indexName);
                    index.getValues().add(col);
                    index.setIndextype(IndexType.PRIMARY);
                    tm.getAllIndexes().put(indexName, index);
    
                }
            }
        }

    Ⅱ. Describe what happened

    If there is an exception, please attach the exception trace:

Just paste your stack trace here!

Ⅲ. Describe what you expected to happen

Ⅳ. How to reproduce it (as minimally and precisely as possible)

  1. xxx
  2. xxx
  3. xxx

Ⅴ. Anything else we need to know?

Ⅵ. Environment: