From 49d4f4e41b4c6c0de88ba5bd5adc3e673e60d4ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=80=81=E5=91=A8?= Date: Mon, 20 Nov 2023 18:15:38 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E4=BC=98=E5=8C=96Oracle=E8=A1=A8?= =?UTF-8?q?=E7=BB=93=E6=9E=84=E8=A7=A3=E6=9E=90=E9=80=BB=E8=BE=91,?= =?UTF-8?q?=E8=BF=87=E6=BB=A4=E6=8E=89=E7=B3=BB=E7=BB=9F=E5=86=85=E7=BD=AE?= =?UTF-8?q?=E8=A1=A8.=20(#60)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: 修复无法解析数组类型方法引用信息. * refactor: 优化Oracle表结构解析逻辑,过滤掉系统内置表. --- .../oracle/OracleTableMetadataParser.java | 31 ++++++++++++++----- .../oracle/OracleTableMetaParserTest.java | 25 +++++++++------ 2 files changed, 39 insertions(+), 17 deletions(-) diff --git a/hsweb-easy-orm-rdb/src/main/java/org/hswebframework/ezorm/rdb/supports/oracle/OracleTableMetadataParser.java b/hsweb-easy-orm-rdb/src/main/java/org/hswebframework/ezorm/rdb/supports/oracle/OracleTableMetadataParser.java index c92a8a98..ed5ee840 100644 --- a/hsweb-easy-orm-rdb/src/main/java/org/hswebframework/ezorm/rdb/supports/oracle/OracleTableMetadataParser.java +++ b/hsweb-easy-orm-rdb/src/main/java/org/hswebframework/ezorm/rdb/supports/oracle/OracleTableMetadataParser.java @@ -9,7 +9,8 @@ import java.util.List; public class OracleTableMetadataParser extends RDBTableMetadataParser { - private final static String TABLE_META_SQL = String.join(" ", + private final static String TABLE_META_SQL = String.join( + " ", "select distinct(cols.column_name) as \"name\"", ",cols.table_name as \"table_name\"", ",cols.data_type as \"data_type\"", @@ -19,21 +20,35 @@ public class OracleTableMetadataParser extends RDBTableMetadataParser { ",acc.comments as \"comment\"", ",case when cols.nullable='Y' then 0 else 1 end as \"not_null\"", ",cols.table_name as \"table_name\"", - ",cols.column_id from all_tab_cols cols ", - "left join all_col_comments acc on acc.OWNER = #{schema} and acc.column_name=cols.column_name and acc.table_name=cols.table_name ", - "where cols.owner=#{schema} and cols.table_name like upper(#{table}) and (cols.virtual_column='NO' or cols.virtual_column is null) ", + ",cols.column_id from all_tab_cols cols", + "left join all_col_comments acc on acc.OWNER = #{schema} and acc.column_name=cols.column_name and acc.table_name=cols.table_name", + "where cols.owner=#{schema} and cols.table_name like upper(#{table})", + "and cols.table_name not like '%$%'", + "and cols.table_name not like 'LOGMNR%'", + "and cols.table_name not in ('HELP', 'SQLPLUS_PRODUCT_PROFILE')", + "and (cols.virtual_column='NO' or cols.virtual_column is null) ", "order by cols.column_id "); - private final static String TABLE_COMMENT_SQL = String.join(" ", + private final static String TABLE_COMMENT_SQL = String.join( + " ", "select", "table_name as \"table_name\",", "comments as \"comment\"", "from all_tab_comments ", "where owner=#{schema} and table_type='TABLE' and table_name like upper(#{table})"); - private final static String ALL_TABLE_SQL = "select table_name as \"name\" from all_tab_comments where owner=#{schema} and table_type='TABLE'"; - - private static final String TABLE_EXISTS_SQL = "select count(1) as \"total\" from all_tab_comments where owner=#{schema} and table_type='TABLE' and table_name=upper(#{table})"; + private final static String ALL_TABLE_SQL = String.join( + " ", + "select table_name as \"name\" from all_tab_comments ", + "where owner=#{schema} ", + "and table_name not like '%$%'", + "and table_name not like 'LOGMNR%'", + "and table_name not in ('HELP', 'SQLPLUS_PRODUCT_PROFILE')", + "and table_type='TABLE'"); + private static final String TABLE_EXISTS_SQL = "select count(1) as \"total\" from all_tab_comments " + + "where owner=#{schema} " + + "and table_type='TABLE' " + + "and table_name=upper(#{table})"; public OracleTableMetadataParser(RDBSchemaMetadata schema) { super(schema); diff --git a/hsweb-easy-orm-rdb/src/test/java/org/hswebframework/ezorm/rdb/supports/oracle/OracleTableMetaParserTest.java b/hsweb-easy-orm-rdb/src/test/java/org/hswebframework/ezorm/rdb/supports/oracle/OracleTableMetaParserTest.java index 190b5f56..18230fdb 100644 --- a/hsweb-easy-orm-rdb/src/test/java/org/hswebframework/ezorm/rdb/supports/oracle/OracleTableMetaParserTest.java +++ b/hsweb-easy-orm-rdb/src/test/java/org/hswebframework/ezorm/rdb/supports/oracle/OracleTableMetaParserTest.java @@ -1,8 +1,6 @@ package org.hswebframework.ezorm.rdb.supports.oracle; -import io.r2dbc.spi.Statement; import org.hswebframework.ezorm.rdb.TestJdbcReactiveSqlExecutor; -import org.hswebframework.ezorm.rdb.TestReactiveSqlExecutor; import org.hswebframework.ezorm.rdb.TestSyncSqlExecutor; import org.hswebframework.ezorm.rdb.executor.SqlRequests; import org.hswebframework.ezorm.rdb.executor.SyncSqlExecutor; @@ -11,7 +9,6 @@ import org.junit.Assert; import org.junit.Before; import org.junit.Test; -import reactor.test.StepVerifier; import java.math.BigDecimal; import java.sql.JDBCType; @@ -38,12 +35,22 @@ public void init() { @Test public void testParseReactive() { - schema.loadAllTableReactive() - .as(StepVerifier::create) - .expectComplete() - .verify(); - - System.out.println(1); +// schema.loadAllTableReactive() +// .as(StepVerifier::create) +// .expectComplete() +// .verify(); + + + parser.parseAllTableNameReactive() + .doOnNext(System.out::println) + .blockLast(); + +// parser.parseAllReactive() +// .doOnNext(table -> System.out.println(table.getName())) +// .then() +// .as(StepVerifier::create) +// .expectComplete() +// .verify(); } @Test