121 |
121 |
122 def where_equal(session_name: String, name: String = ""): SQL.Source = |
122 def where_equal(session_name: String, name: String = ""): SQL.Source = |
123 SQL.where_and( |
123 SQL.where_and( |
124 Sources.session_name.equal(session_name), |
124 Sources.session_name.equal(session_name), |
125 if_proper(name, Sources.name.equal(name))) |
125 if_proper(name, Sources.name.equal(name))) |
|
126 } |
|
127 |
|
128 def read_bytes(db: SQL.Database, name: String, column: SQL.Column): Bytes = |
|
129 db.execute_query_statementO[Bytes]( |
|
130 Session_Info.table.select(List(column), sql = Session_Info.session_name.where_equal(name)), |
|
131 res => res.bytes(column) |
|
132 ).getOrElse(Bytes.empty) |
|
133 |
|
134 def read_properties( |
|
135 db: SQL.Database, name: String, column: SQL.Column, cache: Term.Cache |
|
136 ): List[Properties.T] = Properties.uncompress(read_bytes(db, name, column), cache = cache) |
|
137 |
|
138 def read_session_timing(db: SQL.Database, name: String, cache: Term.Cache): Properties.T = |
|
139 Properties.decode(read_bytes(db, name, Session_Info.session_timing), cache = cache) |
|
140 |
|
141 def read_command_timings(db: SQL.Database, name: String): Bytes = |
|
142 read_bytes(db, name, Session_Info.command_timings) |
|
143 |
|
144 def read_theory_timings(db: SQL.Database, name: String, cache: Term.Cache): List[Properties.T] = |
|
145 read_properties(db, name, Session_Info.theory_timings, cache) |
|
146 |
|
147 def read_ml_statistics(db: SQL.Database, name: String, cache: Term.Cache): List[Properties.T] = |
|
148 read_properties(db, name, Session_Info.ml_statistics, cache) |
|
149 |
|
150 def read_task_statistics(db: SQL.Database, name: String, cache: Term.Cache): List[Properties.T] = |
|
151 read_properties(db, name, Session_Info.task_statistics, cache) |
|
152 |
|
153 def read_errors(db: SQL.Database, name: String, cache: Term.Cache): List[String] = |
|
154 Build_Log.uncompress_errors(read_bytes(db, name, Session_Info.errors), cache = cache) |
|
155 |
|
156 def read_build(db: SQL.Database, name: String): Option[Store.Build_Info] = { |
|
157 if (db.tables.contains(Session_Info.table.name)) { |
|
158 db.execute_query_statementO[Store.Build_Info]( |
|
159 Session_Info.table.select(sql = Session_Info.session_name.where_equal(name)), |
|
160 { res => |
|
161 val uuid = |
|
162 try { Option(res.string(Session_Info.uuid)).getOrElse("") } |
|
163 catch { case _: SQLException => "" } |
|
164 Store.Build_Info( |
|
165 SHA1.fake_shasum(res.string(Session_Info.sources)), |
|
166 SHA1.fake_shasum(res.string(Session_Info.input_heaps)), |
|
167 SHA1.fake_shasum(res.string(Session_Info.output_heap)), |
|
168 res.int(Session_Info.return_code), |
|
169 uuid) |
|
170 } |
|
171 ) |
|
172 } |
|
173 else None |
126 } |
174 } |
127 |
175 |
128 def write_session_info( |
176 def write_session_info( |
129 db: SQL.Database, |
177 db: SQL.Database, |
130 cache: Compress.Cache, |
178 cache: Compress.Cache, |
357 case None => (false, SHA1.no_shasum) |
405 case None => (false, SHA1.no_shasum) |
358 } |
406 } |
359 } |
407 } |
360 |
408 |
361 |
409 |
362 /* SQL database content */ |
|
363 |
|
364 def read_bytes(db: SQL.Database, name: String, column: SQL.Column): Bytes = |
|
365 db.execute_query_statementO[Bytes]( |
|
366 Store.Data.Session_Info.table.select(List(column), |
|
367 sql = Store.Data.Session_Info.session_name.where_equal(name)), |
|
368 res => res.bytes(column) |
|
369 ).getOrElse(Bytes.empty) |
|
370 |
|
371 def read_properties(db: SQL.Database, name: String, column: SQL.Column): List[Properties.T] = |
|
372 Properties.uncompress(read_bytes(db, name, column), cache = cache) |
|
373 |
|
374 |
|
375 /* session info */ |
410 /* session info */ |
376 |
411 |
377 def session_info_exists(db: SQL.Database): Boolean = { |
412 def session_info_exists(db: SQL.Database): Boolean = { |
378 val tables = db.tables |
413 val tables = db.tables |
379 Store.Data.tables.forall(table => tables.contains(table.name)) |
414 Store.Data.tables.forall(table => tables.contains(table.name)) |
414 Store.Data.write_sources(db, session_name, sources) |
449 Store.Data.write_sources(db, session_name, sources) |
415 Store.Data.write_session_info(db, cache.compress, session_name, build_log, build) |
450 Store.Data.write_session_info(db, cache.compress, session_name, build_log, build) |
416 } |
451 } |
417 } |
452 } |
418 |
453 |
419 def read_session_timing(db: SQL.Database, name: String): Properties.T = |
454 def read_session_timing(db: SQL.Database, session: String): Properties.T = |
420 Properties.decode(read_bytes(db, name, Store.Data.Session_Info.session_timing), cache = cache) |
455 Store.Data.transaction_lock(db) { Store.Data.read_session_timing(db, session, cache) } |
421 |
456 |
422 def read_command_timings(db: SQL.Database, name: String): Bytes = |
457 def read_command_timings(db: SQL.Database, session: String): Bytes = |
423 read_bytes(db, name, Store.Data.Session_Info.command_timings) |
458 Store.Data.transaction_lock(db) { Store.Data.read_command_timings(db, session) } |
424 |
459 |
425 def read_theory_timings(db: SQL.Database, name: String): List[Properties.T] = |
460 def read_theory_timings(db: SQL.Database, session: String): List[Properties.T] = |
426 read_properties(db, name, Store.Data.Session_Info.theory_timings) |
461 Store.Data.transaction_lock(db) { Store.Data.read_theory_timings(db, session, cache) } |
427 |
462 |
428 def read_ml_statistics(db: SQL.Database, name: String): List[Properties.T] = |
463 def read_ml_statistics(db: SQL.Database, session: String): List[Properties.T] = |
429 read_properties(db, name, Store.Data.Session_Info.ml_statistics) |
464 Store.Data.transaction_lock(db) { Store.Data.read_ml_statistics(db, session, cache) } |
430 |
465 |
431 def read_task_statistics(db: SQL.Database, name: String): List[Properties.T] = |
466 def read_task_statistics(db: SQL.Database, session: String): List[Properties.T] = |
432 read_properties(db, name, Store.Data.Session_Info.task_statistics) |
467 Store.Data.transaction_lock(db) { Store.Data.read_task_statistics(db, session, cache) } |
433 |
468 |
434 def read_theories(db: SQL.Database, name: String): List[String] = |
469 def read_theories(db: SQL.Database, session: String): List[String] = |
435 read_theory_timings(db, name).flatMap(Markup.Name.unapply) |
470 read_theory_timings(db, session).flatMap(Markup.Name.unapply) |
436 |
471 |
437 def read_errors(db: SQL.Database, name: String): List[String] = |
472 def read_errors(db: SQL.Database, session: String): List[String] = |
438 Build_Log.uncompress_errors(read_bytes(db, name, Store.Data.Session_Info.errors), cache = cache) |
473 Store.Data.transaction_lock(db) { Store.Data.read_errors(db, session, cache) } |
439 |
474 |
440 def read_build(db: SQL.Database, name: String): Option[Store.Build_Info] = { |
475 def read_build(db: SQL.Database, session: String): Option[Store.Build_Info] = |
441 if (db.tables.contains(Store.Data.Session_Info.table.name)) { |
476 Store.Data.transaction_lock(db) { Store.Data.read_build(db, session) } |
442 db.execute_query_statementO[Store.Build_Info]( |
|
443 Store.Data.Session_Info.table.select( |
|
444 sql = Store.Data.Session_Info.session_name.where_equal(name)), |
|
445 { res => |
|
446 val uuid = |
|
447 try { Option(res.string(Store.Data.Session_Info.uuid)).getOrElse("") } |
|
448 catch { case _: SQLException => "" } |
|
449 Store.Build_Info( |
|
450 SHA1.fake_shasum(res.string(Store.Data.Session_Info.sources)), |
|
451 SHA1.fake_shasum(res.string(Store.Data.Session_Info.input_heaps)), |
|
452 SHA1.fake_shasum(res.string(Store.Data.Session_Info.output_heap)), |
|
453 res.int(Store.Data.Session_Info.return_code), |
|
454 uuid) |
|
455 } |
|
456 ) |
|
457 } |
|
458 else None |
|
459 } |
|
460 |
477 |
461 def read_sources(db: SQL.Database, session: String, name: String = ""): List[Store.Source_File] = |
478 def read_sources(db: SQL.Database, session: String, name: String = ""): List[Store.Source_File] = |
462 Store.Data.read_sources(db, cache.compress, session, name = name) |
479 Store.Data.transaction_lock(db) { Store.Data.read_sources(db, session, name, cache.compress) } |
463 } |
480 } |