From 3b0977715979369569191776fae914b62642342d Mon Sep 17 00:00:00 2001 From: Xiaobing Zhou Date: Fri, 20 Feb 2015 17:04:34 -0800 Subject: [PATCH] HIVE-9741: Refactor MetaStoreDirectSql by using getProductName instead of querying DB to determine DbType --- .../hadoop/hive/metastore/MetaStoreDirectSql.java | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git metastore/src/java/org/apache/hadoop/hive/metastore/MetaStoreDirectSql.java metastore/src/java/org/apache/hadoop/hive/metastore/MetaStoreDirectSql.java index 574141c..fb170fd 100644 --- metastore/src/java/org/apache/hadoop/hive/metastore/MetaStoreDirectSql.java +++ metastore/src/java/org/apache/hadoop/hive/metastore/MetaStoreDirectSql.java @@ -135,19 +135,17 @@ public MetaStoreDirectSql(PersistenceManager pm, Configuration conf) { private DB determineDbType() { DB dbType = DB.OTHER; - if (runDbCheck("SET @@session.sql_mode=ANSI_QUOTES", "MySql")) { + String productName = getProductName(); + if (productName != null && productName.toLowerCase().contains("mysql")) { dbType = DB.MYSQL; - } else if (runDbCheck("SELECT version FROM v$instance", "Oracle")) { + } else if (productName != null && productName.toLowerCase().contains("oracle")) { dbType = DB.ORACLE; - } else if (runDbCheck("SELECT @@version", "MSSQL")) { + } else if (productName != null && productName.toLowerCase().contains("microsoft sql server")) { dbType = DB.MSSQL; - } else { - // TODO: maybe we should use getProductName to identify all the DBs - String productName = getProductName(); - if (productName != null && productName.toLowerCase().contains("derby")) { - dbType = DB.DERBY; - } - } + } else if (productName != null && productName.toLowerCase().contains("derby")) { + dbType = DB.DERBY; + } else; + return dbType; } @@ -180,6 +178,9 @@ private boolean ensureDbInit() { private boolean runTestQuery() { Transaction tx = pm.currentTransaction(); + if (!tx.isActive()) { + tx.begin(); + } // Run a self-test query. If it doesn't work, we will self-disable. What a PITA... String selfTestQuery = "select \"DB_ID\" from \"DBS\""; try { -- 1.9.3 (Apple Git-50)