@Override
  public String getJdoConnectionUrl(Configuration conf) throws Exception {
    if (originalUrl == null) {
      originalUrl = conf.get(HiveConf.ConfVars.METASTORE_CONNECT_URL_KEY.varname, "");
      return "jdbc:derby:;databaseName=target/tmp/junit_metastore_db_blank;create=true";
    } else {
      return originalUrl;
    }

  }
First returns a url for a blank DB, then returns a URL for the original DB.
For testing the feature in url_hook.q
contrib/src/java/org/apache/hadoop/hive/contrib/metastore/hooks/SampleURLHook.java