Example usage for java.sql SQLFeatureNotSupportedException getMessage

List of usage examples for java.sql SQLFeatureNotSupportedException getMessage

Introduction

In this page you can find the example usage for java.sql SQLFeatureNotSupportedException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:org.apache.hadoop.hive.metastore.tools.SchemaToolTaskValidate.java

@VisibleForTesting
boolean validateSchemaTables(Connection conn) throws HiveMetaException {
    System.out.println("Validating metastore schema tables");
    String version = null;//from  w w w  . j a v a  2 s  .co m
    try {
        MetaStoreConnectionInfo connectionInfo = schemaTool.getConnectionInfo(false);
        version = schemaTool.getMetaStoreSchemaInfo().getMetaStoreSchemaVersion(connectionInfo);
    } catch (HiveMetaException he) {
        System.err.println("Failed to determine schema version from Hive Metastore DB. " + he.getMessage());
        System.out.println("Failed in schema table validation.");
        LOG.debug("Failed to determine schema version from Hive Metastore DB," + he.getMessage(), he);
        return false;
    }

    Connection hmsConn = schemaTool.getConnectionToMetastore(false);

    LOG.debug("Validating tables in the schema for version " + version);
    List<String> dbTables = new ArrayList<>();
    ResultSet rs = null;
    try {
        String schema = null;
        try {
            schema = hmsConn.getSchema();
        } catch (SQLFeatureNotSupportedException e) {
            LOG.debug("schema is not supported");
        }

        DatabaseMetaData metadata = conn.getMetaData();
        rs = metadata.getTables(null, schema, "%", new String[] { "TABLE" });

        while (rs.next()) {
            String table = rs.getString("TABLE_NAME");
            dbTables.add(table.toLowerCase());
            LOG.debug("Found table " + table + " in HMS dbstore");
        }
    } catch (SQLException e) {
        throw new HiveMetaException("Failed to retrieve schema tables from Hive Metastore DB," + e.getMessage(),
                e);
    } finally {
        if (rs != null) {
            try {
                rs.close();
            } catch (SQLException e) {
                throw new HiveMetaException("Failed to close resultset", e);
            }
        }
    }

    // parse the schema file to determine the tables that are expected to exist
    // we are using oracle schema because it is simpler to parse, no quotes or backticks etc
    List<String> schemaTables = new ArrayList<>();
    List<String> subScripts = new ArrayList<>();

    String baseDir = new File(schemaTool.getMetaStoreSchemaInfo().getMetaStoreScriptDir()).getParent();
    String schemaFile = new File(schemaTool.getMetaStoreSchemaInfo().getMetaStoreScriptDir(),
            schemaTool.getMetaStoreSchemaInfo().generateInitFileName(version)).getPath();
    try {
        LOG.debug("Parsing schema script " + schemaFile);
        subScripts.addAll(findCreateTable(schemaFile, schemaTables));
        while (subScripts.size() > 0) {
            schemaFile = baseDir + "/" + schemaTool.getDbType() + "/" + subScripts.remove(0);
            LOG.debug("Parsing subscript " + schemaFile);
            subScripts.addAll(findCreateTable(schemaFile, schemaTables));
        }
    } catch (Exception e) {
        System.err.println("Exception in parsing schema file. Cause:" + e.getMessage());
        System.out.println("Failed in schema table validation.");
        return false;
    }

    LOG.debug("Schema tables:[ " + Arrays.toString(schemaTables.toArray()) + " ]");
    LOG.debug("DB tables:[ " + Arrays.toString(dbTables.toArray()) + " ]");

    // now diff the lists
    schemaTables.removeAll(dbTables);
    if (schemaTables.size() > 0) {
        Collections.sort(schemaTables);
        System.err.println("Table(s) [ " + Arrays.toString(schemaTables.toArray()) + " ] "
                + "are missing from the metastore database schema.");
        System.out.println("[FAIL]\n");
        return false;
    } else {
        System.out.println("[SUCCESS]\n");
        return true;
    }
}