1201 |
1201 |
1202 class Database_Context private[Sessions]( |
1202 class Database_Context private[Sessions]( |
1203 val store: Sessions.Store, |
1203 val store: Sessions.Store, |
1204 database_server: Option[SQL.Database]) extends AutoCloseable |
1204 database_server: Option[SQL.Database]) extends AutoCloseable |
1205 { |
1205 { |
1206 def xml_cache: XML.Cache = store.xml_cache |
1206 def cache: XML.Cache = store.cache |
1207 def xz_cache: XZ.Cache = store.xz_cache |
|
1208 |
1207 |
1209 def close { database_server.foreach(_.close) } |
1208 def close { database_server.foreach(_.close) } |
1210 |
1209 |
1211 def output_database[A](session: String)(f: SQL.Database => A): A = |
1210 def output_database[A](session: String)(f: SQL.Database => A): A = |
1212 database_server match { |
1211 database_server match { |
1229 { |
1228 { |
1230 val attempts = |
1229 val attempts = |
1231 database_server match { |
1230 database_server match { |
1232 case Some(db) => |
1231 case Some(db) => |
1233 sessions.view.map(session_name => |
1232 sessions.view.map(session_name => |
1234 Export.read_entry(db, store.xz_cache, session_name, theory_name, name)) |
1233 Export.read_entry(db, store.cache, session_name, theory_name, name)) |
1235 case None => |
1234 case None => |
1236 sessions.view.map(session_name => |
1235 sessions.view.map(session_name => |
1237 store.try_open_database(session_name) match { |
1236 store.try_open_database(session_name) match { |
1238 case Some(db) => |
1237 case Some(db) => |
1239 using(db)(Export.read_entry(_, store.xz_cache, session_name, theory_name, name)) |
1238 using(db)(Export.read_entry(_, store.cache, session_name, theory_name, name)) |
1240 case None => None |
1239 case None => None |
1241 }) |
1240 }) |
1242 } |
1241 } |
1243 attempts.collectFirst({ case Some(entry) => entry }) |
1242 attempts.collectFirst({ case Some(entry) => entry }) |
1244 } |
1243 } |
1257 } |
1256 } |
1258 "Database_Context(" + s + ")" |
1257 "Database_Context(" + s + ")" |
1259 } |
1258 } |
1260 } |
1259 } |
1261 |
1260 |
1262 def store(options: Options, |
1261 def store(options: Options, cache: XML.Cache = XML.Cache.make()): Store = |
1263 xml_cache: XML.Cache = XML.Cache.make(), |
1262 new Store(options, cache) |
1264 xz_cache: XZ.Cache = XZ.Cache.make()): Store = |
1263 |
1265 new Store(options, xml_cache, xz_cache) |
1264 class Store private[Sessions](val options: Options, val cache: XML.Cache) |
1266 |
|
1267 class Store private[Sessions]( |
|
1268 val options: Options, |
|
1269 val xml_cache: XML.Cache, |
|
1270 val xz_cache: XZ.Cache) |
|
1271 { |
1265 { |
1272 store => |
1266 store => |
1273 |
1267 |
1274 override def toString: String = "Store(output_dir = " + output_dir.absolute + ")" |
1268 override def toString: String = "Store(output_dir = " + output_dir.absolute + ")" |
1275 |
1269 |
1405 val res = stmt.execute_query() |
1399 val res = stmt.execute_query() |
1406 if (!res.next()) Bytes.empty else res.bytes(column) |
1400 if (!res.next()) Bytes.empty else res.bytes(column) |
1407 }) |
1401 }) |
1408 |
1402 |
1409 def read_properties(db: SQL.Database, name: String, column: SQL.Column): List[Properties.T] = |
1403 def read_properties(db: SQL.Database, name: String, column: SQL.Column): List[Properties.T] = |
1410 Properties.uncompress( |
1404 Properties.uncompress(read_bytes(db, name, column), cache = cache) |
1411 read_bytes(db, name, column), cache = xz_cache, xml_cache = xml_cache) |
|
1412 |
1405 |
1413 |
1406 |
1414 /* session info */ |
1407 /* session info */ |
1415 |
1408 |
1416 def init_session_info(db: SQL.Database, name: String) |
1409 def init_session_info(db: SQL.Database, name: String) |
1457 db.transaction { |
1450 db.transaction { |
1458 db.using_statement(Session_Info.table.insert())(stmt => |
1451 db.using_statement(Session_Info.table.insert())(stmt => |
1459 { |
1452 { |
1460 stmt.string(1) = name |
1453 stmt.string(1) = name |
1461 stmt.bytes(2) = Properties.encode(build_log.session_timing) |
1454 stmt.bytes(2) = Properties.encode(build_log.session_timing) |
1462 stmt.bytes(3) = Properties.compress(build_log.command_timings, cache = xz_cache) |
1455 stmt.bytes(3) = Properties.compress(build_log.command_timings, cache = cache.xz) |
1463 stmt.bytes(4) = Properties.compress(build_log.theory_timings, cache = xz_cache) |
1456 stmt.bytes(4) = Properties.compress(build_log.theory_timings, cache = cache.xz) |
1464 stmt.bytes(5) = Properties.compress(build_log.ml_statistics, cache = xz_cache) |
1457 stmt.bytes(5) = Properties.compress(build_log.ml_statistics, cache = cache.xz) |
1465 stmt.bytes(6) = Properties.compress(build_log.task_statistics, cache = xz_cache) |
1458 stmt.bytes(6) = Properties.compress(build_log.task_statistics, cache = cache.xz) |
1466 stmt.bytes(7) = Build_Log.compress_errors(build_log.errors, cache = xz_cache) |
1459 stmt.bytes(7) = Build_Log.compress_errors(build_log.errors, cache = cache.xz) |
1467 stmt.string(8) = build.sources |
1460 stmt.string(8) = build.sources |
1468 stmt.string(9) = cat_lines(build.input_heaps) |
1461 stmt.string(9) = cat_lines(build.input_heaps) |
1469 stmt.string(10) = build.output_heap getOrElse "" |
1462 stmt.string(10) = build.output_heap getOrElse "" |
1470 stmt.int(11) = build.return_code |
1463 stmt.int(11) = build.return_code |
1471 stmt.execute() |
1464 stmt.execute() |
1472 }) |
1465 }) |
1473 } |
1466 } |
1474 } |
1467 } |
1475 |
1468 |
1476 def read_session_timing(db: SQL.Database, name: String): Properties.T = |
1469 def read_session_timing(db: SQL.Database, name: String): Properties.T = |
1477 Properties.decode(read_bytes(db, name, Session_Info.session_timing), xml_cache = xml_cache) |
1470 Properties.decode(read_bytes(db, name, Session_Info.session_timing), cache = cache) |
1478 |
1471 |
1479 def read_command_timings(db: SQL.Database, name: String): List[Properties.T] = |
1472 def read_command_timings(db: SQL.Database, name: String): List[Properties.T] = |
1480 read_properties(db, name, Session_Info.command_timings) |
1473 read_properties(db, name, Session_Info.command_timings) |
1481 |
1474 |
1482 def read_theory_timings(db: SQL.Database, name: String): List[Properties.T] = |
1475 def read_theory_timings(db: SQL.Database, name: String): List[Properties.T] = |
1490 |
1483 |
1491 def read_theories(db: SQL.Database, name: String): List[String] = |
1484 def read_theories(db: SQL.Database, name: String): List[String] = |
1492 read_theory_timings(db, name).flatMap(Markup.Name.unapply) |
1485 read_theory_timings(db, name).flatMap(Markup.Name.unapply) |
1493 |
1486 |
1494 def read_errors(db: SQL.Database, name: String): List[String] = |
1487 def read_errors(db: SQL.Database, name: String): List[String] = |
1495 Build_Log.uncompress_errors(read_bytes(db, name, Session_Info.errors), cache = xz_cache) |
1488 Build_Log.uncompress_errors(read_bytes(db, name, Session_Info.errors), cache = cache.xz) |
1496 |
1489 |
1497 def read_build(db: SQL.Database, name: String): Option[Build.Session_Info] = |
1490 def read_build(db: SQL.Database, name: String): Option[Build.Session_Info] = |
1498 { |
1491 { |
1499 if (db.tables.contains(Session_Info.table.name)) { |
1492 if (db.tables.contains(Session_Info.table.name)) { |
1500 db.using_statement(Session_Info.table.select(Session_Info.build_columns, |
1493 db.using_statement(Session_Info.table.select(Session_Info.build_columns, |