修复oracle代码生成获取不到注释问题

This commit is contained in:
cgc 2023-07-14 13:40:43 +08:00
parent c984880c93
commit 65b802a259
2 changed files with 28 additions and 5 deletions

View File

@ -5,13 +5,11 @@
<parent> <parent>
<artifactId>parent</artifactId> <artifactId>parent</artifactId>
<groupId>com.mybatis-flex</groupId> <groupId>com.mybatis-flex</groupId>
<version>1.4.9</version> <version>1.3.9</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<artifactId>mybatis-flex-codegen</artifactId> <artifactId>mybatis-flex-codegen</artifactId>
<packaging>jar</packaging>
<properties> <properties>
<maven.compiler.source>8</maven.compiler.source> <maven.compiler.source>8</maven.compiler.source>
@ -29,7 +27,7 @@
<dependency> <dependency>
<groupId>com.mybatis-flex</groupId> <groupId>com.mybatis-flex</groupId>
<artifactId>mybatis-flex-spring</artifactId> <artifactId>mybatis-flex-spring</artifactId>
<version>${mybatis-flex.version}</version> <version>1.3.9</version>
</dependency> </dependency>
@ -50,6 +48,11 @@
<optional>true</optional> <optional>true</optional>
</dependency> </dependency>
<dependency>
<groupId>com.oracle.ojdbc</groupId>
<artifactId>ojdbc8</artifactId>
<version>19.3.0.0</version>
</dependency>
<dependency> <dependency>
<groupId>org.xerial</groupId> <groupId>org.xerial</groupId>

View File

@ -17,12 +17,17 @@ package com.mybatisflex.codegen.dialect;
import com.mybatisflex.codegen.config.GlobalConfig; import com.mybatisflex.codegen.config.GlobalConfig;
import com.mybatisflex.codegen.entity.Table; import com.mybatisflex.codegen.entity.Table;
import com.mybatisflex.core.util.ClassUtil;
import com.mybatisflex.core.util.StringUtil; import com.mybatisflex.core.util.StringUtil;
import com.zaxxer.hikari.pool.HikariProxyConnection;
import java.lang.reflect.Field;
import java.sql.Connection; import java.sql.Connection;
import java.sql.DatabaseMetaData; import java.sql.DatabaseMetaData;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.function.Predicate;
import oracle.jdbc.driver.OracleConnection;
/** /**
* 方言接口 * 方言接口
@ -65,7 +70,22 @@ public interface IDialect {
@Override @Override
protected ResultSet forRemarks(String schema, Table table, DatabaseMetaData dbMeta, Connection conn) throws SQLException { protected ResultSet forRemarks(String schema, Table table, DatabaseMetaData dbMeta, Connection conn) throws SQLException {
return dbMeta.getColumns(conn.getCatalog(), StringUtil.isNotBlank(schema) ? schema : dbMeta.getUserName(), table.getName(), null); HikariProxyConnection hikariProxyConnection = (HikariProxyConnection) conn;
Field delegate = ClassUtil.getFirstField(HikariProxyConnection.class, new Predicate<Field>() {
@Override
public boolean test(Field field) {
return field.getName().equals("delegate");
}
});
delegate.setAccessible(true);
OracleConnection oc;
try {
oc = (OracleConnection) delegate.get(hikariProxyConnection);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
oc.setRemarksReporting(true);
return dbMeta.getColumns(oc.getCatalog(), StringUtil.isNotBlank(schema) ? schema : dbMeta.getUserName(), table.getName(), null);
} }
}; };