| Name | Total Lines | Lines of Code | Total Coverage | Code Coverage |
|---|---|---|---|---|
| lib/dagnabit/link/transitive_closure_recalculation/on_create.rb | 104 | 75 | 100.00%
|
100.00%
|
Code reported as executed by Ruby looks like this...and this: this line is also marked as covered.Lines considered as run by rcov, but not reported by Ruby, look like this,and this: these lines were inferred by rcov (using simple heuristics).Finally, here's a line marked as not executed.
1 require 'dagnabit/link/transitive_closure_recalculation/utilities' |
2 |
3 module Dagnabit |
4 module Link |
5 module TransitiveClosureRecalculation |
6 module OnCreate |
7 include Utilities |
8 |
9 def after_create |
10 super |
11 update_transitive_closure_for_create |
12 end |
13 |
14 private |
15 |
16 def update_transitive_closure_for_create |
17 tc = self.class.transitive_closure_table_name |
18 tc_aid, tc_did, tc_atype, tc_dtype = quoted_dag_link_column_names |
19 aid, did, atype, dtype = quoted_dag_link_values |
20 all_columns = all_quoted_column_names.join(',') |
21 all_values = all_quoted_column_values.join(',') |
22 |
23 with_temporary_edge_tables('new', 'delta') do |new, delta| |
24 extend_connected_paths(new, tc_aid, tc_did, tc_atype, tc_dtype, tc, aid, did, atype, dtype) |
25 append_created_edge(new, all_columns, all_values) |
26 synchronize_transitive_closure(new, delta, all_columns, tc, tc_aid, tc_did, tc_atype, tc_dtype) |
27 end |
28 end |
29 |
30 # |
31 # determine: |
32 # * all paths constructed by adding (a, b) to the back of paths |
33 # ending at a (first subselect) |
34 # * all paths constructed by adding (a, b) to the front of paths |
35 # starting at b (second subselect) |
36 # * all paths constructed by adding (a, b) in the middle of paths |
37 # starting at a and ending at b (third subselect) |
38 # |
39 def extend_connected_paths(new, tc_aid, tc_did, tc_atype, tc_dtype, tc, aid, did, atype, dtype) |
40 connection.execute <<-END |
41 INSERT INTO #{new} (#{tc_aid}, #{tc_did}, #{tc_atype}, #{tc_dtype}) |
42 SELECT * FROM ( |
43 SELECT |
44 TC.#{tc_aid}, #{did}, TC.#{tc_atype}, #{dtype} |
45 FROM |
46 #{tc} AS TC |
47 WHERE |
48 TC.#{tc_did} = #{aid} AND TC.#{tc_dtype} = #{atype} |
49 UNION |
50 SELECT |
51 #{aid}, TC.#{tc_did}, #{atype}, TC.#{tc_dtype} |
52 FROM |
53 #{tc} AS TC |
54 WHERE |
55 TC.#{tc_aid} = #{did} AND TC.#{tc_atype} = #{dtype} |
56 UNION |
57 SELECT |
58 TC1.#{tc_aid}, TC2.#{tc_did}, TC1.#{tc_atype}, TC2.#{tc_dtype} |
59 FROM |
60 #{tc} AS TC1, #{tc} AS TC2 |
61 WHERE |
62 TC1.#{tc_did} = #{aid} AND TC1.#{tc_dtype} = #{atype} |
63 AND |
64 TC2.#{tc_aid} = #{did} AND TC2.#{tc_atype} = #{dtype} |
65 ) AS tmp0 |
66 END |
67 end |
68 |
69 def append_created_edge(new, all_columns, all_values) |
70 connection.execute <<-END |
71 INSERT INTO #{new} (#{all_columns}) VALUES (#{all_values}) |
72 END |
73 end |
74 |
75 def synchronize_transitive_closure(new, delta, all_columns, tc, tc_aid, tc_did, tc_atype, tc_dtype) |
76 # |
77 # ...filter out duplicates... |
78 # |
79 connection.execute <<-END |
80 INSERT INTO #{delta} |
81 SELECT * FROM #{new} AS T |
82 WHERE NOT EXISTS ( |
83 SELECT * |
84 FROM |
85 #{tc} AS TC |
86 WHERE |
87 TC.#{tc_aid} = T.#{tc_aid} AND TC.#{tc_did} = T.#{tc_did} |
88 AND |
89 TC.#{tc_atype} = T.#{tc_atype} AND TC.#{tc_dtype} = T.#{tc_dtype} |
90 ) |
91 END |
92 |
93 # |
94 # ...and update the transitive closure table |
95 # |
96 connection.execute <<-END |
97 INSERT INTO #{tc} (#{all_columns}) |
98 SELECT * FROM #{delta} |
99 END |
100 end |
101 end |
102 end |
103 end |
104 end |
Generated on Tue Dec 08 04:06:14 -0600 2009 with rcov 0.9.6