tajo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hyun...@apache.org
Subject [49/50] [abbrv] git commit: TAJO-911: Refactoring Mysql/Maria Catalog Store. (DaeMyung Kang via hyunsik)
Date Wed, 09 Jul 2014 04:11:06 GMT
TAJO-911: Refactoring Mysql/Maria Catalog Store. (DaeMyung Kang via hyunsik)

Closes #59


Project: http://git-wip-us.apache.org/repos/asf/tajo/repo
Commit: http://git-wip-us.apache.org/repos/asf/tajo/commit/b9a39728
Tree: http://git-wip-us.apache.org/repos/asf/tajo/tree/b9a39728
Diff: http://git-wip-us.apache.org/repos/asf/tajo/diff/b9a39728

Branch: refs/heads/window_function
Commit: b9a39728f9a18f8a9f986f35a40c17005795257b
Parents: 10caff0
Author: Hyunsik Choi <hyunsik@apache.org>
Authored: Tue Jul 8 15:33:42 2014 +0900
Committer: Hyunsik Choi <hyunsik@apache.org>
Committed: Tue Jul 8 15:33:42 2014 +0900

----------------------------------------------------------------------
 CHANGES                                         |   2 +
 .../store/AbstractMySQLMariaDBStore.java        | 297 +++++++++++++++++++
 .../apache/tajo/catalog/store/MariaDBStore.java | 255 +---------------
 .../apache/tajo/catalog/store/MySQLStore.java   | 242 +--------------
 4 files changed, 304 insertions(+), 492 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tajo/blob/b9a39728/CHANGES
----------------------------------------------------------------------
diff --git a/CHANGES b/CHANGES
index 661b488..c7ea93f 100644
--- a/CHANGES
+++ b/CHANGES
@@ -24,6 +24,8 @@ Release 0.9.0 - unreleased
 
   IMPROVEMENT
 
+    TAJO-911: Refactoring Mysql/Maria Catalog Store. (DaeMyung Kang via hyunsik)
+
     TAJO-853: Refactoring FilterPushDown for OUTER JOIN.
     (Hyoungjun Kim via hyunsik)
 

http://git-wip-us.apache.org/repos/asf/tajo/blob/b9a39728/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/AbstractMySQLMariaDBStore.java
----------------------------------------------------------------------
diff --git a/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/AbstractMySQLMariaDBStore.java
b/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/AbstractMySQLMariaDBStore.java
new file mode 100644
index 0000000..6d0876f
--- /dev/null
+++ b/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/AbstractMySQLMariaDBStore.java
@@ -0,0 +1,297 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ *
+ */
+package org.apache.tajo.catalog.store;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.tajo.catalog.CatalogUtil;
+import org.apache.tajo.catalog.exception.CatalogException;
+import org.apache.tajo.exception.InternalException;
+
+import java.sql.*;
+import java.util.HashMap;
+import java.util.Map;
+
+public abstract class AbstractMySQLMariaDBStore extends AbstractDBStore  {
+  protected String getCatalogDriverName(){
+    throw new CatalogException("you can't use this directly.");
+  }
+
+  public AbstractMySQLMariaDBStore(final Configuration conf) throws InternalException {
+    super(conf);
+  }
+
+  @Override
+  public int getDriverVersion() {
+    throw new CatalogException("you can't use this directly.");
+  }
+
+  protected Connection createConnection(Configuration conf) throws SQLException {
+    Connection con = DriverManager.getConnection(getCatalogUri(), this.connectionId,
+        this.connectionPassword);
+    //TODO con.setAutoCommit(false);
+    return con;
+  }
+
+  @Override
+  protected boolean isConnValid(int timeout) throws CatalogException {
+    boolean isValid = false;
+
+    try {
+      isValid = super.isConnValid(timeout);
+    } catch (NullPointerException e) {
+      LOG.info("Conn abortion when checking isValid; retrieve false to create another Conn.");
+    }
+    return isValid;
+  }
+
+  @Override
+  public String readSchemaFile(String filename) throws CatalogException {
+      return super.readSchemaFile(filename);
+  }
+
+  // TODO - DDL and index statements should be renamed
+  @Override
+  protected void createBaseTable() throws CatalogException {
+    Statement stmt = null;
+    Connection conn = null;
+
+    try {
+      conn = getConnection();
+      stmt = conn.createStatement();
+
+
+      // META
+      if (!baseTableMaps.get(TB_META)) {
+        String sql = super.readSchemaFile("common/meta.sql");
+
+        if (LOG.isDebugEnabled()) {
+          LOG.debug(sql.toString());
+        }
+
+        stmt.executeUpdate(sql.toString());
+        LOG.info("Table '" + TB_META + " is created.");
+        baseTableMaps.put(TB_META, true);
+      }
+
+      // TABLE SPACES
+      if (!baseTableMaps.get(TB_SPACES)) {
+        String sql = readSchemaFile("tablespaces.sql");
+
+        if (LOG.isDebugEnabled()) {
+          LOG.debug(sql);
+        }
+
+        stmt.executeUpdate(sql);
+
+        LOG.info("Table '" + TB_SPACES + "' is created.");
+        baseTableMaps.put(TB_SPACES, true);
+      }
+
+      // DATABASES
+      if (!baseTableMaps.get(TB_DATABASES)) {
+        String sql = readSchemaFile("databases.sql");
+        if (LOG.isDebugEnabled()) {
+          LOG.debug(sql);
+        }
+        LOG.info("Table '" + TB_DATABASES + "' is created.");
+        baseTableMaps.put(TB_DATABASES, true);
+        stmt.executeUpdate(sql);
+      }
+
+      // TABLES
+      if (!baseTableMaps.get(TB_TABLES)) {
+        String sql = readSchemaFile("tables.sql");
+        if (LOG.isDebugEnabled()) {
+          LOG.debug(sql);
+        }
+        stmt.executeUpdate(sql);
+        LOG.info("Table '" + TB_TABLES + "' is created.");
+        baseTableMaps.put(TB_TABLES, true);
+      }
+
+      // COLUMNS
+      if (!baseTableMaps.get(TB_COLUMNS)) {
+        String sql = readSchemaFile("columns.sql");
+        if (LOG.isDebugEnabled()) {
+          LOG.debug(sql);
+        }
+
+        stmt.executeUpdate(sql.toString());
+        LOG.info("Table '" + TB_COLUMNS + " is created.");
+        baseTableMaps.put(TB_COLUMNS, true);
+      }
+
+      // OPTIONS
+      if (!baseTableMaps.get(TB_OPTIONS)) {
+        String sql = readSchemaFile("table_properties.sql");
+
+        if (LOG.isDebugEnabled()) {
+          LOG.debug(sql.toString());
+        }
+
+        stmt.executeUpdate(sql.toString());
+        LOG.info("Table '" + TB_OPTIONS + " is created.");
+        baseTableMaps.put(TB_OPTIONS, true);
+      }
+
+      // INDEXES
+      if (!baseTableMaps.get(TB_INDEXES)) {
+        String sql = readSchemaFile("indexes.sql");
+
+        if (LOG.isDebugEnabled()) {
+          LOG.debug(sql.toString());
+        }
+
+        stmt.executeUpdate(sql.toString());
+        LOG.info("Table '" + TB_INDEXES + "' is created.");
+        baseTableMaps.put(TB_INDEXES, true);
+      }
+
+      if (!baseTableMaps.get(TB_STATISTICS)) {
+        String sql = readSchemaFile("stats.sql");
+
+        if (LOG.isDebugEnabled()) {
+          LOG.debug(sql.toString());
+        }
+
+        stmt.executeUpdate(sql.toString());
+        LOG.info("Table '" + TB_STATISTICS + "' is created.");
+        baseTableMaps.put(TB_STATISTICS, true);
+      }
+
+      // PARTITION_METHODS
+      if (!baseTableMaps.get(TB_PARTITION_METHODS)) {
+        String sql = readSchemaFile("partition_methods.sql");
+
+        if (LOG.isDebugEnabled()) {
+          LOG.debug(sql);
+        }
+
+        stmt.executeUpdate(sql);
+        LOG.info("Table '" + TB_PARTITION_METHODS + "' is created.");
+        baseTableMaps.put(TB_PARTITION_METHODS, true);
+      }
+
+      // PARTITIONS
+      if (!baseTableMaps.get(TB_PARTTIONS)) {
+        String sql = readSchemaFile("partitions.sql");
+
+        if (LOG.isDebugEnabled()) {
+          LOG.debug(sql.toString());
+        }
+
+        stmt.executeUpdate(sql.toString());
+        LOG.info("Table '" + TB_PARTTIONS + "' is created.");
+        baseTableMaps.put(TB_PARTTIONS, true);
+      }
+
+      insertSchemaVersion();
+
+    } catch (SQLException se) {
+      throw new CatalogException("failed to create base tables for MySQL catalog store",
se);
+    } finally {
+      CatalogUtil.closeQuietly(stmt);
+    }
+  }
+
+  @Override
+  protected void dropBaseTable() throws CatalogException {
+    Connection conn = null;
+    Statement stmt = null;
+    Map<String, Boolean> droppedTable = new HashMap<String, Boolean>();
+
+    try {
+      conn = getConnection();
+      stmt = conn.createStatement();
+      StringBuilder sql = new StringBuilder();
+
+      for(Map.Entry<String, Boolean> entry : baseTableMaps.entrySet()) {
+        if(entry.getValue() && !entry.getKey().equals(TB_TABLES)) {
+          sql.delete(0, sql.length());
+          sql.append("DROP TABLE ").append(entry.getKey());
+          stmt.addBatch(sql.toString());
+          droppedTable.put(entry.getKey(), true);
+        }
+      }
+      if(baseTableMaps.get(TB_TABLES)) {
+        sql.delete(0, sql.length());
+        sql.append("DROP TABLE ").append(TB_TABLES);
+        stmt.addBatch(sql.toString());
+        droppedTable.put(TB_TABLES, true);
+      }
+      stmt.executeBatch();
+
+      for(String tableName : droppedTable.keySet()) {
+        LOG.info("Table '" + tableName + "' is dropped");
+      }
+    } catch (SQLException se) {
+      throw new CatalogException(se);
+    } finally {
+      CatalogUtil.closeQuietly(stmt);
+    }
+  }
+
+  @Override
+  protected boolean isInitialized() throws CatalogException {
+    Connection conn;
+    ResultSet res = null;
+
+    try {
+      conn = getConnection();
+      res = conn.getMetaData().getTables(null, null, null,
+          new String[]{"TABLE"});
+
+      baseTableMaps.put(TB_META, false);
+      baseTableMaps.put(TB_SPACES, false);
+      baseTableMaps.put(TB_DATABASES, false);
+      baseTableMaps.put(TB_TABLES, false);
+      baseTableMaps.put(TB_COLUMNS, false);
+      baseTableMaps.put(TB_OPTIONS, false);
+      baseTableMaps.put(TB_STATISTICS, false);
+      baseTableMaps.put(TB_INDEXES, false);
+      baseTableMaps.put(TB_PARTITION_METHODS, false);
+      baseTableMaps.put(TB_PARTTIONS, false);
+
+      if (res.wasNull())
+        return false;
+
+      while (res.next()) {
+        // if my.cnf has lower_case_table_names = 1,
+        // TABLE_NAME returns lower case even it created by upper case.
+        baseTableMaps.put(res.getString("TABLE_NAME").toUpperCase(), true);
+      }
+
+      for(Map.Entry<String, Boolean> entry : baseTableMaps.entrySet()) {
+        if (!entry.getValue()) {
+          return false;
+        }
+      }
+
+    } catch(SQLException se) {
+      throw new CatalogException(se);
+    } finally {
+      CatalogUtil.closeQuietly(res);
+    }
+
+    return  true;
+  }
+}

http://git-wip-us.apache.org/repos/asf/tajo/blob/b9a39728/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/MariaDBStore.java
----------------------------------------------------------------------
diff --git a/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/MariaDBStore.java
b/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/MariaDBStore.java
index 94f3e70..8cb3858 100644
--- a/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/MariaDBStore.java
+++ b/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/MariaDBStore.java
@@ -22,19 +22,16 @@
 package org.apache.tajo.catalog.store;
 
 import org.apache.hadoop.conf.Configuration;
-import org.apache.tajo.catalog.CatalogUtil;
 import org.apache.tajo.catalog.exception.CatalogException;
 import org.apache.tajo.exception.InternalException;
 
-import java.sql.*;
-import java.util.HashMap;
-import java.util.Map;
-
-public class MariaDBStore extends AbstractDBStore  {
+public class MariaDBStore extends AbstractMySQLMariaDBStore {
   /** 2014-06-09: First versioning */
   private static final int MARIADB_CATALOG_STORE_VERSION = 2;
 
   private static final String CATALOG_DRIVER = "org.mariadb.jdbc.Driver";
+
+  @Override
   protected String getCatalogDriverName(){
     return CATALOG_DRIVER;
   }
@@ -48,254 +45,8 @@ public class MariaDBStore extends AbstractDBStore  {
     return MARIADB_CATALOG_STORE_VERSION;
   }
 
-  protected Connection createConnection(Configuration conf) throws SQLException {
-    Connection con = DriverManager.getConnection(getCatalogUri(), this.connectionId,
-        this.connectionPassword);
-    //TODO con.setAutoCommit(false);
-    return con;
-  }
-
-  @Override
-  protected boolean isConnValid(int timeout) throws CatalogException {
-    boolean isValid = false;
-
-    try {
-      isValid = super.isConnValid(timeout);
-    } catch (NullPointerException e) {
-      LOG.info("Conn abortion when checking isValid; retrieve false to create another Conn.");
-    }
-    return isValid;
-  }
-
   @Override
   public String readSchemaFile(String filename) throws CatalogException {
     return super.readSchemaFile("mariadb/" + filename);
   }
-
-  // TODO - DDL and index statements should be renamed
-  @Override
-  protected void createBaseTable() throws CatalogException {
-    Statement stmt = null;
-    Connection conn = null;
-
-    try {
-      conn = getConnection();
-      stmt = conn.createStatement();
-
-
-      // META
-      if (!baseTableMaps.get(TB_META)) {
-        String sql = super.readSchemaFile("common/meta.sql");
-
-        if (LOG.isDebugEnabled()) {
-          LOG.debug(sql.toString());
-        }
-
-        stmt.executeUpdate(sql.toString());
-        LOG.info("Table '" + TB_META + " is created.");
-        baseTableMaps.put(TB_META, true);
-      }
-
-      // TABLE SPACES
-      if (!baseTableMaps.get(TB_SPACES)) {
-        String sql = readSchemaFile("tablespaces.sql");
-
-        if (LOG.isDebugEnabled()) {
-          LOG.debug(sql);
-        }
-
-        stmt.executeUpdate(sql);
-
-        LOG.info("Table '" + TB_SPACES + "' is created.");
-        baseTableMaps.put(TB_SPACES, true);
-      }
-
-      // DATABASES
-      if (!baseTableMaps.get(TB_DATABASES)) {
-        String sql = readSchemaFile("databases.sql");
-        if (LOG.isDebugEnabled()) {
-          LOG.debug(sql);
-        }
-        LOG.info("Table '" + TB_DATABASES + "' is created.");
-        baseTableMaps.put(TB_DATABASES, true);
-        stmt.executeUpdate(sql);
-      }
-
-      // TABLES
-      if (!baseTableMaps.get(TB_TABLES)) {
-        String sql = readSchemaFile("tables.sql");
-        if (LOG.isDebugEnabled()) {
-          LOG.debug(sql);
-        }
-        stmt.executeUpdate(sql);
-        LOG.info("Table '" + TB_TABLES + "' is created.");
-        baseTableMaps.put(TB_TABLES, true);
-      }
-
-      // COLUMNS
-      if (!baseTableMaps.get(TB_COLUMNS)) {
-        String sql = readSchemaFile("columns.sql");
-        if (LOG.isDebugEnabled()) {
-          LOG.debug(sql);
-        }
-
-        stmt.executeUpdate(sql.toString());
-        LOG.info("Table '" + TB_COLUMNS + " is created.");
-        baseTableMaps.put(TB_COLUMNS, true);
-      }
-
-      // OPTIONS
-      if (!baseTableMaps.get(TB_OPTIONS)) {
-        String sql = readSchemaFile("table_properties.sql");
-
-        if (LOG.isDebugEnabled()) {
-          LOG.debug(sql.toString());
-        }
-
-        stmt.executeUpdate(sql.toString());
-        LOG.info("Table '" + TB_OPTIONS + " is created.");
-        baseTableMaps.put(TB_OPTIONS, true);
-      }
-
-      // INDEXES
-      if (!baseTableMaps.get(TB_INDEXES)) {
-        String sql = readSchemaFile("indexes.sql");
-
-        if (LOG.isDebugEnabled()) {
-          LOG.debug(sql.toString());
-        }
-
-        stmt.executeUpdate(sql.toString());
-        LOG.info("Table '" + TB_INDEXES + "' is created.");
-        baseTableMaps.put(TB_INDEXES, true);
-      }
-
-      if (!baseTableMaps.get(TB_STATISTICS)) {
-        String sql = readSchemaFile("stats.sql");
-
-        if (LOG.isDebugEnabled()) {
-          LOG.debug(sql.toString());
-        }
-
-        stmt.executeUpdate(sql.toString());
-        LOG.info("Table '" + TB_STATISTICS + "' is created.");
-        baseTableMaps.put(TB_STATISTICS, true);
-      }
-
-      // PARTITION_METHODS
-      if (!baseTableMaps.get(TB_PARTITION_METHODS)) {
-        String sql = readSchemaFile("partition_methods.sql");
-
-        if (LOG.isDebugEnabled()) {
-          LOG.debug(sql);
-        }
-
-        stmt.executeUpdate(sql);
-        LOG.info("Table '" + TB_PARTITION_METHODS + "' is created.");
-        baseTableMaps.put(TB_PARTITION_METHODS, true);
-      }
-
-      // PARTITIONS
-      if (!baseTableMaps.get(TB_PARTTIONS)) {
-        String sql = readSchemaFile("partitions.sql");
-
-        if (LOG.isDebugEnabled()) {
-          LOG.debug(sql.toString());
-        }
-
-        stmt.executeUpdate(sql.toString());
-        LOG.info("Table '" + TB_PARTTIONS + "' is created.");
-        baseTableMaps.put(TB_PARTTIONS, true);
-      }
-
-      insertSchemaVersion();
-
-    } catch (SQLException se) {
-      throw new CatalogException("failed to create base tables for MariaDB catalog store",
se);
-    } finally {
-      CatalogUtil.closeQuietly(stmt);
-    }
-  }
-
-  @Override
-  protected void dropBaseTable() throws CatalogException {
-    Connection conn = null;
-    Statement stmt = null;
-    Map<String, Boolean> droppedTable = new HashMap<String, Boolean>();
-
-    try {
-      conn = getConnection();
-      stmt = conn.createStatement();
-      StringBuilder sql = new StringBuilder();
-
-      for(Map.Entry<String, Boolean> entry : baseTableMaps.entrySet()) {
-        if(entry.getValue() && !entry.getKey().equals(TB_TABLES)) {
-          sql.delete(0, sql.length());
-          sql.append("DROP TABLE ").append(entry.getKey());
-          stmt.addBatch(sql.toString());
-          droppedTable.put(entry.getKey(), true);
-        }
-      }
-      if(baseTableMaps.get(TB_TABLES)) {
-        sql.delete(0, sql.length());
-        sql.append("DROP TABLE ").append(TB_TABLES);
-        stmt.addBatch(sql.toString());
-        droppedTable.put(TB_TABLES, true);
-      }
-      stmt.executeBatch();
-
-      for(String tableName : droppedTable.keySet()) {
-        LOG.info("Table '" + tableName + "' is dropped");
-      }
-    } catch (SQLException se) {
-      throw new CatalogException(se);
-    } finally {
-      CatalogUtil.closeQuietly(stmt);
-    }
-  }
-
-  @Override
-  protected boolean isInitialized() throws CatalogException {
-    Connection conn;
-    ResultSet res = null;
-
-    try {
-      conn = getConnection();
-      res = conn.getMetaData().getTables(null, null, null,
-          new String[]{"TABLE"});
-
-      baseTableMaps.put(TB_META, false);
-      baseTableMaps.put(TB_SPACES, false);
-      baseTableMaps.put(TB_DATABASES, false);
-      baseTableMaps.put(TB_TABLES, false);
-      baseTableMaps.put(TB_COLUMNS, false);
-      baseTableMaps.put(TB_OPTIONS, false);
-      baseTableMaps.put(TB_STATISTICS, false);
-      baseTableMaps.put(TB_INDEXES, false);
-      baseTableMaps.put(TB_PARTITION_METHODS, false);
-      baseTableMaps.put(TB_PARTTIONS, false);
-
-      if (res.wasNull())
-        return false;
-
-      while (res.next()) {
-        // if my.cnf has lower_case_table_names = 1,
-        // TABLE_NAME returns lower case even it created by upper case.
-        baseTableMaps.put(res.getString("TABLE_NAME").toUpperCase(), true);
-      }
-
-      for(Map.Entry<String, Boolean> entry : baseTableMaps.entrySet()) {
-        if (!entry.getValue()) {
-          return false;
-        }
-      }
-
-    } catch(SQLException se) {
-      throw new CatalogException(se);
-    } finally {
-      CatalogUtil.closeQuietly(res);
-    }
-
-    return  true;
-  }
 }

http://git-wip-us.apache.org/repos/asf/tajo/blob/b9a39728/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/MySQLStore.java
----------------------------------------------------------------------
diff --git a/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/MySQLStore.java
b/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/MySQLStore.java
index 849afc8..cedc0fe 100644
--- a/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/MySQLStore.java
+++ b/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/MySQLStore.java
@@ -22,21 +22,17 @@
 package org.apache.tajo.catalog.store;
 
 import org.apache.hadoop.conf.Configuration;
-import org.apache.tajo.catalog.CatalogUtil;
 import org.apache.tajo.catalog.exception.CatalogException;
 import org.apache.tajo.exception.InternalException;
 
-import java.sql.*;
-import java.util.HashMap;
-import java.util.Map;
-
-public class MySQLStore extends AbstractDBStore  {
+public class MySQLStore extends AbstractMySQLMariaDBStore  {
   /** 2014-03-20: First versioning */
   private static final int MYSQL_CATALOG_STORE_VERSION_2 = 2;
   /** Before 2013-03-20 */
   private static final int MYSQL_CATALOG_STORE_VERSION_1 = 1;
 
   private static final String CATALOG_DRIVER = "com.mysql.jdbc.Driver";
+  @Override
   protected String getCatalogDriverName(){
     return CATALOG_DRIVER;
   }
@@ -50,242 +46,8 @@ public class MySQLStore extends AbstractDBStore  {
     return MYSQL_CATALOG_STORE_VERSION_2;
   }
 
-  protected Connection createConnection(Configuration conf) throws SQLException {
-    Connection con = DriverManager.getConnection(getCatalogUri(), this.connectionId,
-        this.connectionPassword);
-    //TODO con.setAutoCommit(false);
-    return con;
-  }
-
   @Override
   public String readSchemaFile(String filename) throws CatalogException {
     return super.readSchemaFile("mysql/" + filename);
   }
-
-  // TODO - DDL and index statements should be renamed
-  @Override
-  protected void createBaseTable() throws CatalogException {
-    Statement stmt = null;
-    Connection conn = null;
-
-    try {
-      conn = getConnection();
-      stmt = conn.createStatement();
-
-
-      // META
-      if (!baseTableMaps.get(TB_META)) {
-        String sql = super.readSchemaFile("common/meta.sql");
-
-        if (LOG.isDebugEnabled()) {
-          LOG.debug(sql.toString());
-        }
-
-        stmt.executeUpdate(sql.toString());
-        LOG.info("Table '" + TB_META + " is created.");
-        baseTableMaps.put(TB_META, true);
-      }
-
-      // TABLE SPACES
-      if (!baseTableMaps.get(TB_SPACES)) {
-        String sql = readSchemaFile("tablespaces.sql");
-
-        if (LOG.isDebugEnabled()) {
-          LOG.debug(sql);
-        }
-
-        stmt.executeUpdate(sql);
-
-        LOG.info("Table '" + TB_SPACES + "' is created.");
-        baseTableMaps.put(TB_SPACES, true);
-      }
-
-      // DATABASES
-      if (!baseTableMaps.get(TB_DATABASES)) {
-        String sql = readSchemaFile("databases.sql");
-        if (LOG.isDebugEnabled()) {
-          LOG.debug(sql);
-        }
-        LOG.info("Table '" + TB_DATABASES + "' is created.");
-        baseTableMaps.put(TB_DATABASES, true);
-        stmt.executeUpdate(sql);
-      }
-
-      // TABLES
-      if (!baseTableMaps.get(TB_TABLES)) {
-        String sql = readSchemaFile("tables.sql");
-        if (LOG.isDebugEnabled()) {
-          LOG.debug(sql);
-        }
-        stmt.executeUpdate(sql);
-        LOG.info("Table '" + TB_TABLES + "' is created.");
-        baseTableMaps.put(TB_TABLES, true);
-      }
-
-      // COLUMNS
-      if (!baseTableMaps.get(TB_COLUMNS)) {
-        String sql = readSchemaFile("columns.sql");
-        if (LOG.isDebugEnabled()) {
-          LOG.debug(sql);
-        }
-
-        stmt.executeUpdate(sql.toString());
-        LOG.info("Table '" + TB_COLUMNS + " is created.");
-        baseTableMaps.put(TB_COLUMNS, true);
-      }
-
-      // OPTIONS
-      if (!baseTableMaps.get(TB_OPTIONS)) {
-        String sql = readSchemaFile("table_properties.sql");
-
-        if (LOG.isDebugEnabled()) {
-          LOG.debug(sql.toString());
-        }
-
-        stmt.executeUpdate(sql.toString());
-        LOG.info("Table '" + TB_OPTIONS + " is created.");
-        baseTableMaps.put(TB_OPTIONS, true);
-      }
-
-      // INDEXES
-      if (!baseTableMaps.get(TB_INDEXES)) {
-        String sql = readSchemaFile("indexes.sql");
-
-        if (LOG.isDebugEnabled()) {
-          LOG.debug(sql.toString());
-        }
-
-        stmt.executeUpdate(sql.toString());
-        LOG.info("Table '" + TB_INDEXES + "' is created.");
-        baseTableMaps.put(TB_INDEXES, true);
-      }
-
-      if (!baseTableMaps.get(TB_STATISTICS)) {
-        String sql = readSchemaFile("stats.sql");
-
-        if (LOG.isDebugEnabled()) {
-          LOG.debug(sql.toString());
-        }
-
-        stmt.executeUpdate(sql.toString());
-        LOG.info("Table '" + TB_STATISTICS + "' is created.");
-        baseTableMaps.put(TB_STATISTICS, true);
-      }
-
-      // PARTITION_METHODS
-      if (!baseTableMaps.get(TB_PARTITION_METHODS)) {
-        String sql = readSchemaFile("partition_methods.sql");
-
-        if (LOG.isDebugEnabled()) {
-          LOG.debug(sql);
-        }
-
-        stmt.executeUpdate(sql);
-        LOG.info("Table '" + TB_PARTITION_METHODS + "' is created.");
-        baseTableMaps.put(TB_PARTITION_METHODS, true);
-      }
-
-      // PARTITIONS
-      if (!baseTableMaps.get(TB_PARTTIONS)) {
-        String sql = readSchemaFile("partitions.sql");
-
-        if (LOG.isDebugEnabled()) {
-          LOG.debug(sql.toString());
-        }
-
-        stmt.executeUpdate(sql.toString());
-        LOG.info("Table '" + TB_PARTTIONS + "' is created.");
-        baseTableMaps.put(TB_PARTTIONS, true);
-      }
-
-      insertSchemaVersion();
-
-    } catch (SQLException se) {
-      throw new CatalogException("failed to create base tables for MySQL catalog store",
se);
-    } finally {
-      CatalogUtil.closeQuietly(stmt);
-    }
-  }
-
-  @Override
-  protected void dropBaseTable() throws CatalogException {
-    Connection conn = null;
-    Statement stmt = null;
-    Map<String, Boolean> droppedTable = new HashMap<String, Boolean>();
-
-    try {
-      conn = getConnection();
-      stmt = conn.createStatement();
-      StringBuilder sql = new StringBuilder();
-
-      for(Map.Entry<String, Boolean> entry : baseTableMaps.entrySet()) {
-        if(entry.getValue() && !entry.getKey().equals(TB_TABLES)) {
-          sql.delete(0, sql.length());
-          sql.append("DROP TABLE ").append(entry.getKey());
-          stmt.addBatch(sql.toString());
-          droppedTable.put(entry.getKey(), true);
-        }
-      }
-      if(baseTableMaps.get(TB_TABLES)) {
-        sql.delete(0, sql.length());
-        sql.append("DROP TABLE ").append(TB_TABLES);
-        stmt.addBatch(sql.toString());
-        droppedTable.put(TB_TABLES, true);
-      }
-      stmt.executeBatch();
-
-      for(String tableName : droppedTable.keySet()) {
-        LOG.info("Table '" + tableName + "' is dropped");
-      }
-    } catch (SQLException se) {
-      throw new CatalogException(se);
-    } finally {
-      CatalogUtil.closeQuietly(stmt);
-    }
-  }
-
-  @Override
-  protected boolean isInitialized() throws CatalogException {
-    Connection conn;
-    ResultSet res = null;
-
-    try {
-      conn = getConnection();
-      res = conn.getMetaData().getTables(null, null, null,
-          new String[]{"TABLE"});
-
-      baseTableMaps.put(TB_META, false);
-      baseTableMaps.put(TB_SPACES, false);
-      baseTableMaps.put(TB_DATABASES, false);
-      baseTableMaps.put(TB_TABLES, false);
-      baseTableMaps.put(TB_COLUMNS, false);
-      baseTableMaps.put(TB_OPTIONS, false);
-      baseTableMaps.put(TB_STATISTICS, false);
-      baseTableMaps.put(TB_INDEXES, false);
-      baseTableMaps.put(TB_PARTITION_METHODS, false);
-      baseTableMaps.put(TB_PARTTIONS, false);
-
-      if (res.wasNull())
-        return false;
-
-      while (res.next()) {
-        // if my.cnf has lower_case_table_names = 1,
-        // TABLE_NAME returns lower case even it created by upper case.
-        baseTableMaps.put(res.getString("TABLE_NAME").toUpperCase(), true);
-      }
-
-      for(Map.Entry<String, Boolean> entry : baseTableMaps.entrySet()) {
-        if (!entry.getValue()) {
-          return false;
-        }
-      }
-
-    } catch(SQLException se) {
-      throw new CatalogException(se);
-    } finally {
-      CatalogUtil.closeQuietly(res);
-    }
-
-    return  true;
-  }
 }


Mime
View raw message