表的索引信息

This commit is contained in:
inrgihc
2023-08-04 22:57:58 +08:00
parent 30792a5b14
commit ccd181a5a0
69 changed files with 794 additions and 347 deletions

View File

@@ -5,7 +5,7 @@
<parent>
<groupId>com.gitee.dbswitch</groupId>
<artifactId>dbswitch-parent</artifactId>
<version>1.8.0</version>
<version>1.8.1</version>
</parent>
<artifactId>dbswitch-common</artifactId>

View File

@@ -14,4 +14,11 @@ import javax.sql.DataSource;
public interface CloseableDataSource extends DataSource, Closeable {
String getJdbcUrl();
String getDriverClass();
String getUserName();
String getPassword();
}

View File

@@ -19,7 +19,9 @@ import java.util.Objects;
import java.util.Properties;
import java.util.logging.Logger;
import javax.sql.DataSource;
import lombok.Getter;
@Getter
public class InvisibleDataSource implements DataSource {
private final ClassLoader classLoader;

View File

@@ -14,7 +14,7 @@ package com.gitee.dbswitch.common.type;
*
* @author tang
*/
public enum ProductTableType {
public enum ProductTableEnum {
/**
* 物理表
*/
@@ -27,7 +27,7 @@ public enum ProductTableType {
private int index;
ProductTableType(int idx) {
ProductTableEnum(int idx) {
this.index = idx;
}

View File

@@ -0,0 +1,28 @@
// Copyright tang. All rights reserved.
// https://gitee.com/inrgihc/dbswitch
//
// Use of this source code is governed by a BSD-style license
//
// Author: tang (inrgihc@126.com)
// Date : 2020/1/2
// Location: beijing , china
/////////////////////////////////////////////////////////////
package com.gitee.dbswitch.common.type;
public enum TableIndexEnum {
NORMAL("普通索引"),
UNIQUE("唯一索引"),
;
private String description;
TableIndexEnum(String description) {
this.description = description;
}
public boolean isUnique() {
return UNIQUE == this;
}
}

View File

@@ -1,65 +0,0 @@
// Copyright tang. All rights reserved.
// https://gitee.com/inrgihc/dbswitch
//
// Use of this source code is governed by a BSD-style license
//
// Author: tang (inrgihc@126.com)
// Date : 2020/1/2
// Location: beijing , china
/////////////////////////////////////////////////////////////
package com.gitee.dbswitch.common.util;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import lombok.experimental.UtilityClass;
@UtilityClass
public final class HivePrepareUtils {
private final static String HIVE_SQL_1 = "set hive.resultset.use.unique.column.names=false";
private final static String HIVE_SQL_2 = "set hive.support.concurrency=true";
private final static String HIVE_SQL_3 = "set hive.txn.manager = org.apache.hadoop.hive.ql.lockmgr.DbTxnManager";
public static void setResultSetColumnNameNotUnique(Connection connection)
throws SQLException {
executeWithoutResultSet(connection, HIVE_SQL_1);
}
public static void prepare(Connection connection, String schema, String table)
throws SQLException {
executeWithoutResultSet(connection, HIVE_SQL_1);
if (isTransactionalTable(connection, schema, table)) {
executeWithoutResultSet(connection, HIVE_SQL_2);
executeWithoutResultSet(connection, HIVE_SQL_3);
}
}
private static boolean isTransactionalTable(Connection connection, String schema, String table)
throws SQLException {
String fullTableName = String.format("`%s`.`%s`", schema, table);
String sql = String.format("DESCRIBE FORMATTED %s", fullTableName);
try (Statement st = connection.createStatement();
ResultSet rs = st.executeQuery(sql)) {
while (rs.next()) {
String dataType = rs.getString("data_type");
String comment = rs.getString("comment");
if (dataType != null
&& comment != null
&& dataType.startsWith("transactional")
&& comment.startsWith("true")) {
return true;
}
}
return false;
}
}
private static boolean executeWithoutResultSet(Connection connection, String sql)
throws SQLException {
try (Statement st = connection.createStatement()) {
return st.execute(sql);
}
}
}