@Override
  public int execute() throws HiveException {
    String dbName = desc.getDatabaseName();
    if (!context.getDb().databaseExists(dbName)) {
      throw new HiveException(ErrorMsg.DATABASE_NOT_EXISTS, dbName);
    }

    SessionState.get().setCurrentDatabase(dbName);

    // set database specific parameters
    Database database = context.getDb().getDatabase(dbName);
    assert(database != null);

    Map<String, String> dbParams = database.getParameters();
    if (dbParams != null) {
      for (HiveConf.ConfVars var: HiveConf.dbVars) {
        String newValue = dbParams.get(var.varname);
        if (newValue != null) {
          LOG.info("Changing {} from {} to {}", var.varname, context.getConf().getVar(var), newValue);
          context.getConf().setVar(var, newValue);
        }
      }
    }

    return 0;
  }
Operation process of switching to another database.
ql/src/java/org/apache/hadoop/hive/ql/ddl/database/use/SwitchDatabaseOperation.java