代码优化
This commit is contained in:
@@ -4,7 +4,6 @@ import com.yanghuanglin.seq.enums.DbType;
|
|||||||
|
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.DatabaseMetaData;
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -134,9 +133,8 @@ public class GeneratorConfig {
|
|||||||
|
|
||||||
public DbType getDbType() {
|
public DbType getDbType() {
|
||||||
if (this.dbType == null) {
|
if (this.dbType == null) {
|
||||||
Connection connection = null;
|
|
||||||
try {
|
try {
|
||||||
connection = dataSource.getConnection();
|
Connection connection = dataSource.getConnection();
|
||||||
String productName = connection.getMetaData().getDatabaseProductName();
|
String productName = connection.getMetaData().getDatabaseProductName();
|
||||||
this.dbType = DbType.of(productName);
|
this.dbType = DbType.of(productName);
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ public enum DbType {
|
|||||||
*/
|
*/
|
||||||
public static DbType of(String productName) {
|
public static DbType of(String productName) {
|
||||||
for (DbType value : DbType.values()) {
|
for (DbType value : DbType.values()) {
|
||||||
if (value.name().equalsIgnoreCase(productName.replace(" ","_"))) {
|
if (value.name().equalsIgnoreCase(productName.replace(" ", "_"))) {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user