Search in sources :

Example 1 with PersistentHistory

use of jline.console.history.PersistentHistory in project hive by apache.

the class CliDriver method setupCmdHistory.

private void setupCmdHistory() {
    final String HISTORYFILE = ".hivehistory";
    String historyDirectory = System.getProperty("user.home");
    PersistentHistory history = null;
    try {
        if ((new File(historyDirectory)).exists()) {
            String historyFile = historyDirectory + File.separator + HISTORYFILE;
            history = new FileHistory(new File(historyFile));
            reader.setHistory(history);
        } else {
            System.err.println("WARNING: Directory for Hive history file: " + historyDirectory + " does not exist.   History will not be available during this session.");
        }
    } catch (Exception e) {
        System.err.println("WARNING: Encountered an error while trying to initialize Hive's " + "history file.  History will not be available during this session.");
        System.err.println(e.getMessage());
    }
    // add shutdown hook to flush the history to history file
    ShutdownHookManager.addShutdownHook(new Runnable() {

        @Override
        public void run() {
            History h = reader.getHistory();
            if (h instanceof FileHistory) {
                try {
                    ((FileHistory) h).flush();
                } catch (IOException e) {
                    System.err.println("WARNING: Failed to write command history file: " + e.getMessage());
                }
            }
        }
    });
}
Also used : PersistentHistory(jline.console.history.PersistentHistory) IOException(java.io.IOException) FileHistory(jline.console.history.FileHistory) PersistentHistory(jline.console.history.PersistentHistory) History(jline.console.history.History) File(java.io.File) FileHistory(jline.console.history.FileHistory) FileNotFoundException(java.io.FileNotFoundException) StringUtils.stringifyException(org.apache.hadoop.util.StringUtils.stringifyException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) CommandNeedRetryException(org.apache.hadoop.hive.ql.CommandNeedRetryException) SQLException(java.sql.SQLException) LogInitializationException(org.apache.hadoop.hive.common.LogUtils.LogInitializationException) IOException(java.io.IOException)

Aggregations

File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 SQLException (java.sql.SQLException)1 FileHistory (jline.console.history.FileHistory)1 History (jline.console.history.History)1 PersistentHistory (jline.console.history.PersistentHistory)1 LogInitializationException (org.apache.hadoop.hive.common.LogUtils.LogInitializationException)1 CommandNeedRetryException (org.apache.hadoop.hive.ql.CommandNeedRetryException)1 StringUtils.stringifyException (org.apache.hadoop.util.StringUtils.stringifyException)1