src/Pure/Thy/sessions.scala
changeset 75786 ff6c1a82270f
parent 75782 dba571dd0ba9
child 75791 fb12433208aa
equal deleted inserted replaced
75785:16135603d9c7 75786:ff6c1a82270f
  1205     val build_columns = List(sources, input_heaps, output_heap, return_code)
  1205     val build_columns = List(sources, input_heaps, output_heap, return_code)
  1206 
  1206 
  1207     val table = SQL.Table("isabelle_session_info", build_log_columns ::: build_columns)
  1207     val table = SQL.Table("isabelle_session_info", build_log_columns ::: build_columns)
  1208   }
  1208   }
  1209 
  1209 
  1210   class Database_Context private[Sessions](
       
  1211     val store: Sessions.Store,
       
  1212     val database_server: Option[SQL.Database]
       
  1213   ) extends AutoCloseable {
       
  1214     def cache: Term.Cache = store.cache
       
  1215 
       
  1216     def close(): Unit = database_server.foreach(_.close())
       
  1217 
       
  1218     def database_output[A](session: String)(f: SQL.Database => A): A =
       
  1219       database_server match {
       
  1220         case Some(db) => f(db)
       
  1221         case None => using(store.open_database(session, output = true))(f)
       
  1222       }
       
  1223 
       
  1224     override def toString: String = {
       
  1225       val s =
       
  1226         database_server match {
       
  1227           case Some(db) => db.toString
       
  1228           case None => "input_dirs = " + store.input_dirs.map(_.absolute).mkString(", ")
       
  1229         }
       
  1230       "Database_Context(" + s + ")"
       
  1231     }
       
  1232   }
       
  1233 
       
  1234   def store(options: Options, cache: Term.Cache = Term.Cache.make()): Store =
  1210   def store(options: Options, cache: Term.Cache = Term.Cache.make()): Store =
  1235     new Store(options, cache)
  1211     new Store(options, cache)
  1236 
  1212 
  1237   class Store private[Sessions](val options: Options, val cache: Term.Cache) {
  1213   class Store private[Sessions](val options: Options, val cache: Term.Cache) {
  1238     store =>
  1214     store =>
  1307             SSH.open_session(options,
  1283             SSH.open_session(options,
  1308               host = ssh_host,
  1284               host = ssh_host,
  1309               user = options.string("build_database_ssh_user"),
  1285               user = options.string("build_database_ssh_user"),
  1310               port = options.int("build_database_ssh_port"))),
  1286               port = options.int("build_database_ssh_port"))),
  1311         ssh_close = true)
  1287         ssh_close = true)
  1312 
       
  1313     def open_database_context(server: Boolean = database_server): Database_Context =
       
  1314       new Database_Context(store, if (server) Some(open_database_server()) else None)
       
  1315 
  1288 
  1316     def try_open_database(
  1289     def try_open_database(
  1317       name: String,
  1290       name: String,
  1318       output: Boolean = false,
  1291       output: Boolean = false,
  1319       server: Boolean = database_server
  1292       server: Boolean = database_server