lib/UR/Context/ObjectFabricator.pm

filter: Statementstmt 4.4% 22 / 490 Branchbran 0.0% 0 / 186 Conditioncond 0.0% 0 / 87 MC/DCmcdc 0.0% 0 / 48 Subroutinesub 26.0% 6 / 23 Podpod 54.5% 6 / 11 totaltotal 4.0% 34 / 845 CC 143 SCAR 76.3
CC
143
Cov
3%
__ANON__
4567.4
_resolve_delegation_data
870.0
create_for_loading_template
202.7
CRAP 2063.9
« blib/lib/UR/DataSource/QueryPlan.pm ↑ Summary lib/UR/Context/LoadingIterator.pm »
1 package UR::Context::ObjectFabricator;
2  
3 266 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 266 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 266 ▶use Scalar::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 266 ▶use UR::Context;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 266 our $VERSION = "0.47"; # UR $VERSION;
10  
11 # A helper package for UR::Context to keep track of the subrefs used
12 # to create objects from database data
13 # These are normal Perl objects, not UR objects, so they get
14 # regular refcounting and scoping
15  
16 266 our @CARP_NOT = qw( UR::Context );
17  
18 266 my %all_object_fabricators;
19  
20 0 ▶sub _create {
Subroutine _create: not called CC=8 SCAR=42.8
21 0 my $class = shift;
22  
23 0 my %params = @_;
24  
25 0 ▶ unless ($params{'fabricator'} and ref($params{'fabricator'}) eq 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
unless ($params{"fabricator"} and ref $params{"fabricator"} eq "CODE") 0 0 0
Condition0%0/3
$params{"fabricator"} and ref $params{"fabricator"} eq "CODE"
!ll&&!rl&&r
000
MC/DC0%0/2
$params{"fabricator"} and ref $params{"fabricator"} eq "CODE"
$params{"fabricator"} ref $params{"fabricator"} eq "CODE"
Truth table0%0/3
A and B
A= $params{"fabricator"}B= ref $params{"fabricator"} eq "CODE"
ABresult
0X0
100
111
26 0 Carp::croak("UR::Context::ObjectFabricator::create requires a subroutine ref for the 'fabricator' parameter");
27 }
28  
29 0 ▶ unless ($params{'context'} and ref($params{'context'}) and $params{'context'}->isa('UR::Context')) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($params{"context"} and ref $params{"context"} and $params{"context"}->isa("UR::Context")) 0 0 0
Condition0%0/6
$params{"context"} and ref $params{"context"} and $params{"context"}->isa("UR::Context")
!ll&&!rl&&r
000
$params{"context"} and ref $params{"context"}
!ll&&!rl&&r
000
MC/DC0%0/3
$params{"context"} and ref $params{"context"} and $params{"context"}->isa("UR::Context")
$params{"context"} ref $params{"context"} $params{"context"}->isa("UR::Context")
Truth table0%0/4
A and B and C
A= $params{"context"}B= ref $params{"context"}C= $params{"context"}->isa("UR::Context")
ABCresult
0XX0
10X0
1100
1111
30 0 Carp::croak("UR::Context::ObjectFabricator::create requires a UR::Context object for the 'context' parameter");
31 }
32  
33 0 my $self = bless {}, $class;
34  
35 0 $self->{'fabricator'} = $params{'fabricator'};
36 0 $self->{'context'} = $params{'context'};
37  
38 0 ▶ $self->{'all_params_loaded'} = $params{'all_params_loaded'} || {};
Condition0%0/2
$params{'all_params_loaded'} || {}
l!l
00
MC/DC0%0/1
$params{'all_params_loaded'} || {}
$params{'all_params_loaded'}
Truth table0%0/2
A
A= $params{'all_params_loaded'}
Aresult
11
00
39 0 ▶ $self->{'in_clause_values'} = $params{'in_clause_values'} || {};
Condition0%0/2
$params{'in_clause_values'} || {}
l!l
00
MC/DC0%0/1
$params{'in_clause_values'} || {}
$params{'in_clause_values'}
Truth table0%0/2
A
A= $params{'in_clause_values'}
Aresult
11
00
40  
41 0 $all_object_fabricators{$self} = $self;
42 0 Scalar::Util::weaken($all_object_fabricators{$self});
43  
44 0 return $self;
45 }
46  
47  
48 0 ▶sub create_for_loading_template {
Subroutine create_for_loading_template: not called CC=14 SCAR=53.1
Pod documented
49 0 my($fab_class, $context, $loading_template, $query_plan, $rule, $rule_template, $values, $dsx) = @_;
50 0 my @values = @$values;
51  
52 0 my $class_name = $loading_template->{final_class_name};
53 #$class_name or Carp::croak("No final_class_name in loading template?");
54 0 ▶ unless ($class_name) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($class_name) 0 0 0
55 #Carp::carp("No final_class_name in loading template for rule $rule");
56 0 return; # This join doesn't result in an object? - i think this happens when you do a get() with -hints
57 }
58  
59 0 my $class_meta = $class_name->__meta__;
60 0 my $class_data = $dsx->_get_class_data_for_loading($class_meta);
61 0 my $class = $class_name;
62  
63 0 my $ghost_class = $class_data->{ghost_class};
64 0 my $sub_classification_meta_class_name = $class_data->{sub_classification_meta_class_name};
65 0 my $subclassify_by = $class_data->{subclassify_by};
66 0 my $sub_classification_method_name = $class_data->{sub_classification_method_name};
67  
68 # FIXME, right now, we don't have a rule template for joined entities...
69  
70 0 my $rule_template_id = $query_plan->{rule_template_id};
71 0 my $rule_template_without_recursion_desc = $query_plan->{rule_template_without_recursion_desc};
72 0 my $rule_template_id_without_recursion_desc = $query_plan->{rule_template_id_without_recursion_desc};
73 0 my $rule_matches_all = $query_plan->{rule_matches_all};
74 0 my $rule_template_is_id_only = $query_plan->{rule_template_is_id_only};
75 0 my $rule_specifies_id = $query_plan->{rule_specifies_id};
76 0 my $rule_template_specifies_value_for_subtype = $query_plan->{rule_template_specifies_value_for_subtype};
77  
78 0 my $recursion_desc = $query_plan->{recursion_desc};
79 0 my $recurse_property_on_this_row = $query_plan->{recurse_property_on_this_row};
80 0 my $recurse_property_referencing_other_rows = $query_plan->{recurse_property_referencing_other_rows};
81  
82 0 my $needs_further_boolexpr_evaluation_after_loading = $query_plan->{'needs_further_boolexpr_evaluation_after_loading'};
83  
84 0 my $rule_id = $rule->id;
85 0 my $rule_without_recursion_desc = $rule_template_without_recursion_desc->get_rule_for_values(@values);
86  
87 0 my $loading_base_object;
88 0 ▶ if ($loading_template == $query_plan->{loading_templates}[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($loading_template == $query_plan->{'loading_templates'}[0]) { } 0 0 0
89 0 $loading_base_object = 1;
90 }
91 else {
92 0 $loading_base_object = 0;
93 0 $needs_further_boolexpr_evaluation_after_loading = 0;
94 }
95  
96 0 my %subclass_is_safe_for_re_bless;
97 my %subclass_for_subtype_name;
98 0 my %recurse_property_value_found;
99  
100 0 my @property_names = @{ $loading_template->{property_names} };
101 0 my @id_property_names = @{ $loading_template->{id_property_names} };
102 0 my @column_positions = @{ $loading_template->{column_positions} };
103 0 my @id_positions = @{ $loading_template->{id_column_positions} };
104 0 ▶ my $multi_column_id = (@id_positions > 1 ? 1 : 0);
Branch: 1 branch
BranchTrueFalseTotal
@id_positions > 1 ? : 0 0 0
105 0 my $composite_id_resolver = $class_meta->get_composite_id_resolver;
106  
107 # The old way of specifying that some values were constant for all objects returned
108 # by a get(). The data source would wrap the method that builds the loading template
109 # and wedge in some constant_property_names. The new way is to add columns to the
110 # loading template, and then add the values onto the list returned by the data source
111 # iterator.
112 0 my %initial_object_data;
113 0 ▶ if ($loading_template->{constant_property_names}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($loading_template->{"constant_property_names"}) 0 0 0
114 0 my @constant_property_names = @{ $loading_template->{constant_property_names} };
115 0 my @constant_property_values = map { $rule->value_for($_) } @constant_property_names;
116 0 @initial_object_data{@constant_property_names} = @constant_property_values;
117 }
118  
119 0 my $rule_class_name = $rule_template->subject_class_name;
120 0 my $template_id = $rule_template->id;
121 0 my $load_class_name = $class;
122 # $rule can contain params that may not apply to the subclass that's currently loading.
123 # define_boolexpr() in array context will return the portion of the rule that actually applies
124 #my($load_rule, undef) = $load_class_name->define_boolexpr($rule->params_list);
125 0 my($load_rule, @extra_params) = UR::BoolExpr->resolve($load_class_name, $rule->params_list);
126 0 my $load_rule_id = $load_rule->id;
127 0 my $load_template_id = $load_rule->template_id;
128  
129 my @rule_properties_with_in_clauses =
130 0 grep { $rule_template_without_recursion_desc->operator_for($_) eq 'in' }
131 $rule_template_without_recursion_desc->_property_names;
132  
133 0 my($rule_template_without_in_clause,$rule_template_id_without_in_clause,%in_clause_values,@all_rule_property_names);
134 0 my $do_record_in_all_params_loaded = 1;
135 0 ▶ if (@rule_properties_with_in_clauses) {
Branch: 1 branch
BranchTrueFalseTotal
if (@rule_properties_with_in_clauses) 0 0 0
136 0 $rule_template_id_without_in_clause = $rule_template_without_recursion_desc->id;
137 0 foreach my $property_name ( @rule_properties_with_in_clauses ) {
138 # FIXME - removing and re-adding the filter should have the same effect as the substitute below,
139 # but the two result in different rules in the end.
140 #$rule_template_without_in_clause = $rule_template_without_in_clause->remove_filter($property_name);
141 #$rule_template_without_in_clause = $rule_template_without_in_clause->add_filter($property_name);
142 0 $rule_template_id_without_in_clause =~ s/($property_name) in/$1/;
143 }
144 0 $rule_template_without_in_clause = UR::BoolExpr::Template->get($rule_template_id_without_in_clause);
145 # Make a note of all the values in the in-clauses. As the objects get returned from the
146 # data source, we'll remove these notes. Anything that's left by the time the iterator is
147 # finalized must be values that matched nothing. Then, finalize can put data in
148 # all_params_loaded showing it matches nothing
149 0 my %rule_properties_with_in_clauses = map { $_ => 1 } @rule_properties_with_in_clauses;
150 0 @all_rule_property_names = $rule_template_without_in_clause->_property_names;
151 0 foreach my $property ( @rule_properties_with_in_clauses ) {
152 0 my $values_for_in_clause = $rule_without_recursion_desc->value_for($property);
153 0 ▶ unless ($values_for_in_clause) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($values_for_in_clause) 0 0 0
154 0 Carp::confess("rule has no value for property $property: $rule_without_recursion_desc");
155 }
156 0 ▶ if (@$values_for_in_clause > 100) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$values_for_in_clause > 100) 0 0 0
157 0 $do_record_in_all_params_loaded = 0;
158 0 next;
159 }
160  
161 0 ▶ my @other_values = map { exists $rule_properties_with_in_clauses{$_}
Branch: 1 branch
BranchTrueFalseTotal
exists $rule_properties_with_in_clauses{$_} ? : 0 0 0
162 ? undef # placeholder filled in below
163 : $rule_without_recursion_desc->value_for($_) }
164 $rule_template_without_in_clause->_property_names;
165 0 my $position_for_this_property = $rule_template_without_in_clause->value_position_for_property_name($property);
166  
167  
168 # If the number of items in the in-clause is over this number, then don't bother recording
169 # the template-id/rule-id, since searching the list to see if this query has been done before
170 # is going to take longer than just re-doing the query
171 0 foreach my $value ( @$values_for_in_clause ) {
172 0 ▶ $value = '' if (!defined $value);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 0 0
173 0 $other_values[$position_for_this_property] = $value;
174 0 my $rule_with_this_in_property = $rule_template_without_in_clause->get_rule_for_values(@other_values);
175 0 $in_clause_values{$property}->{$value}
176 = [$rule_template_id_without_in_clause, $rule_with_this_in_property->id];
177 }
178 }
179  
180 }
181  
182 # This is a local copy of what we want to put in all_params_loaded, when the object fabricator is
183 # finalized
184 0 my $local_all_params_loaded = {};
185  
186 0 my($hints_or_delegation,$delegations_with_no_objects);
187 0 ▶ if (!$loading_base_object) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($loading_base_object) 0 0 0
188 0 ($hints_or_delegation,$delegations_with_no_objects)
189 = $fab_class->_resolve_delegation_data($rule,$loading_template,$query_plan,$local_all_params_loaded);
190 }
191  
192 0 ▶ my $update_apl_for_loaded_object = sub {
Subroutine __ANON__: not called CC=8 SCAR=40.5
193 0 my $pending_db_object = shift;
194  
195 # Make a note in all_params_loaded (essentially, the query cache) that we've made a
196 # match on this rule, and some equivalent rules
197 0 ▶ if ($loading_base_object and not $rule_specifies_id) {
Branch: 1 branch
BranchTrueFalseTotal
if ($loading_base_object and not $rule_specifies_id) 0 0 0
Condition0%0/3
$loading_base_object and not $rule_specifies_id
!ll&&!rl&&r
000
MC/DC0%0/2
$loading_base_object and not $rule_specifies_id
$loading_base_object not $rule_specifies_id
Truth table0%0/3
A and not(B)
A= $loading_base_objectB= not $rule_specifies_id
ABresult
0X0
100
111
198 0 ▶ if ($do_record_in_all_params_loaded) {
Branch: 1 branch
BranchTrueFalseTotal
if ($do_record_in_all_params_loaded) 0 0 0
199 0 ▶ if ($rule_class_name ne $load_class_name and scalar(@extra_params) == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rule_class_name ne $load_class_name and scalar @extra_params == 0) 0 0 0
Condition0%0/3
$rule_class_name ne $load_class_name and scalar @extra_params == 0
!ll&&!rl&&r
000
MC/DC0%0/2
$rule_class_name ne $load_class_name and scalar @extra_params == 0
$rule_class_name ne $load_class_name scalar @extra_params == 0
Truth table0%0/3
A and B
A= $rule_class_name ne $load_class_nameB= scalar @extra_params == 0
ABresult
0X0
100
111
200 0 $pending_db_object->{__load}->{$load_template_id}{$load_rule_id}++;
201 0 $UR::Context::all_params_loaded->{$load_template_id}{$load_rule_id} = undef;
202 0 $local_all_params_loaded->{$load_template_id}{$load_rule_id}++;
203 }
204 0 $pending_db_object->{__load}->{$template_id}{$rule_id}++;
205 0 $UR::Context::all_params_loaded->{$template_id}{$rule_id} = undef;
206 0 $local_all_params_loaded->{$template_id}{$rule_id}++;
207 }
208  
209 0 ▶ if (@rule_properties_with_in_clauses) {
Branch: 1 branch
BranchTrueFalseTotal
if (@rule_properties_with_in_clauses) 0 0 0
210 # FIXME - confirm that all the object properties are filled in at this point, right?
211 #my @values = @$pending_db_object{@rule_properties_with_in_clauses};
212 0 my @values = @$pending_db_object{@all_rule_property_names};
213 0 my $r = $rule_template_without_in_clause->get_normalized_rule_for_values(@values);
214 0 my $r_id = $r->id;
215  
216 0 $UR::Context::all_params_loaded->{$rule_template_id_without_in_clause}{$r_id} = undef;
217 0 $local_all_params_loaded->{$rule_template_id_without_in_clause}{$r_id}++;
218 # remove the notes about these in-clause values since they matched something
219 266 ▶ no warnings; # undef treated as an empty string below
Subroutine BEGIN: called CC=1 SCAR=0.0
220 0 foreach my $property (@rule_properties_with_in_clauses) {
221 0 my $value = $pending_db_object->{$property};
222 0 delete $in_clause_values{$property}->{$value};
223 }
224 }
225 }
226 0 };
227  
228  
229 0 my $fabricator_obj; # filled in after the closure definition
230 0 ▶ my $object_fabricator = sub {
Subroutine __ANON__: not called CC=68 SCAR=84.3
231  
232 0 my $next_db_row = $_[0];
233  
234 # If all the columns for this object are undef, then this doesn't encode an actual
235 # object, it's a result of a left join that matched nothing
236 0 my $values_exist;
237 0 foreach my $column ( @column_positions ) {
238 0 ▶ if (defined($next_db_row->[$column])) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $next_db_row->[$column]) 0 0 0
239 0 $values_exist = 1;
240 0 last;
241 }
242 }
243 0 ▶ if (!$loading_base_object and !$values_exist and $delegations_with_no_objects) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $loading_base_object || $values_exist and $delegations_with_no_objects) 0 0 0
Condition0%0/6
not $loading_base_object || $values_exist and $delegations_with_no_objects
!ll&&!rl&&r
000
$loading_base_object || $values_exist
l!l&&r!l&&!r
000
MC/DC0%0/3
not $loading_base_object || $values_exist and $delegations_with_no_objects
$loading_base_object $values_exist $delegations_with_no_objects
Truth table0%0/4
not(A || B) and C
A= $loading_base_objectB= $values_existC= $delegations_with_no_objects
ABCresult
1XX0
01X0
0000
0011
244 0 my $templates_and_rules = $fab_class->_lapl_data_for_delegation_data($delegations_with_no_objects, $next_db_row);
245 0 ▶ while ( my($template_id, $rule_id) = each %$templates_and_rules) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$templates_and_rules) 0 0 0
246 0 $local_all_params_loaded->{$template_id}->{$rule_id} = 0;
247 0 $UR::Context::all_params_loaded->{$template_id}->{$rule_id} = 0;
248 }
249 0 return;
250 }
251
252  
253 0 my $pending_db_object_data = { %initial_object_data };
254 0 @$pending_db_object_data{@property_names} = @$next_db_row[@column_positions];
255  
256 # resolve id
257 0 my $pending_db_object_id;
258 0 ▶ if ($multi_column_id) {
Branch: 1 branch
BranchTrueFalseTotal
if ($multi_column_id) { } 0 0 0
259 0 $pending_db_object_id = $composite_id_resolver->(@$pending_db_object_data{@id_property_names})
260 }
261 else {
262 0 $pending_db_object_id = $pending_db_object_data->{$id_property_names[0]};
263 }
264  
265 0 ▶ unless (defined $pending_db_object_id) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $pending_db_object_id) 0 0 0
266 0 return undef;
267 0 Carp::confess(
268 "no id found in object data for $class_name?\n"
269 . Data::Dumper::Dumper($pending_db_object_data)
270 );
271 }
272  
273 0 my $pending_db_object;
274  
275 # skip if this object has been deleted but not committed
276 0 do {
277 266 ▶ no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
278 0 ▶ if ($UR::Context::all_objects_loaded->{$ghost_class}{$pending_db_object_id}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($UR::Context::all_objects_loaded->{$ghost_class}{$pending_db_object_id}) 0 0 0
279 0 return;
280 #$pending_db_object = undef;
281 #redo;
282 }
283 };
284  
285 # Handle the object based-on whether it is already loaded in the current context.
286 0 ▶ if ($pending_db_object = $UR::Context::all_objects_loaded->{$class}{$pending_db_object_id}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pending_db_object = $UR::Context::all_objects_loaded->{$class}{$pending_db_object_id}) { } 0 0 0
287 0 $context->__merge_db_data_with_existing_object($class, $pending_db_object, $pending_db_object_data, \@property_names);
288 0 ▶ if ($loading_base_object
Branch: 1 branch
BranchTrueFalseTotal
if ($loading_base_object and $needs_further_boolexpr_evaluation_after_loading and not $rule->evaluate($pending_db_object)) 0 0 0
Condition0%0/6
$loading_base_object and $needs_further_boolexpr_evaluation_after_loading and not $rule->evaluate($pending_db_object)
!ll&&!rl&&r
000
$loading_base_object and $needs_further_boolexpr_evaluation_after_loading
!ll&&!rl&&r
000
MC/DC0%0/3
$loading_base_object and $needs_further_boolexpr_evaluation_after_loading and not $rule->evaluate($pending_db_object)
$loading_base_object $needs_further_boolexpr_evaluation_after_loading not $rule->evaluate($pending_db_object)
Truth table0%0/4
A and B and not(C)
A= $loading_base_objectB= $needs_further_boolexpr_evaluation_after_loadingC= not $rule->evaluate($pending_db_object)
ABCresult
0XX0
10X0
1100
1111
289 and
290 $needs_further_boolexpr_evaluation_after_loading
291 and
292 not $rule->evaluate($pending_db_object)
293 ) {
294 0 return;
295 }
296 0 $update_apl_for_loaded_object->($pending_db_object);
297 }
298 else {
299 # Handle the case in which the object is completely new in the current context.
300  
301 # Create a new object for the resultset row
302 0 $pending_db_object = bless { %$pending_db_object_data, id => $pending_db_object_id }, $class;
303 0 $pending_db_object->{db_committed} = $pending_db_object_data;
304  
305 # determine the subclass name for classes which automatically sub-classify
306 0 my $subclass_name;
307 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($sub_classification_method_name || $subclassify_by || $sub_classification_meta_class_name and ref $pending_db_object eq $class) { } 0 0 0
Condition0%0/9
$sub_classification_method_name || $subclassify_by || $sub_classification_meta_class_name and ref $pending_db_object eq $class
!ll&&!rl&&r
000
$sub_classification_method_name or $subclassify_by or $sub_classification_meta_class_name
l!l&&r!l&&!r
000
$sub_classification_method_name or $subclassify_by
l!l&&r!l&&!r
000
MC/DC0%0/4
$sub_classification_method_name || $subclassify_by || $sub_classification_meta_class_name and ref $pending_db_object eq $class
$sub_classification_method_name $subclassify_by $sub_classification_meta_class_name ref $pending_db_object eq $class
Truth table0%0/7
A or B or C and D
A= $sub_classification_method_nameB= $subclassify_byC= $sub_classification_meta_class_nameD= ref $pending_db_object eq $class
ABCDresult
000X0
1XX00
01X00
00100
1XX11
01X11
00111
308 (
309 $sub_classification_method_name
310 or $subclassify_by
311 or $sub_classification_meta_class_name
312 )
313 and
314 (ref($pending_db_object) eq $class) # not already subclased
315 ) {
316 0 ▶ if ($sub_classification_method_name) {
Branch: 2 branches
BranchTrueFalseTotal
if ($sub_classification_method_name) { } 0 0 0
elsif ($sub_classification_meta_class_name) { } 0 0 0
317 0 $subclass_name = $class->$sub_classification_method_name($pending_db_object);
318 0 ▶ unless ($subclass_name) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($subclass_name) 0 0 0
319 0 my $pending_obj_id = eval { $pending_db_object->id };
320 0 Carp::confess(
321 "Object with id '$pending_obj_id' loaded as abstract class $class failed to subclassify itself using method "
322 . $sub_classification_method_name
323 );
324 }
325 }
326 elsif ($sub_classification_meta_class_name) {
327 # Group objects requiring reclassification by type,
328 # and catch anything which doesn't need reclassification.
329  
330 0 my $subtype_name = $pending_db_object->$subclassify_by;
331 0 $subclass_name = $subclass_for_subtype_name{$subtype_name};
332 0 ▶ unless ($subclass_name) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($subclass_name) 0 0 0
333 0 my $type_obj = $sub_classification_meta_class_name->get($subtype_name);
334  
335 0 ▶ unless ($type_obj) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($type_obj) 0 0 0
336 # The base type may give the final subclass, or an intermediate
337 # either choice has trade-offs, but we support both.
338 # If an intermediate subclass is specified, that subclass
339 # will join to a table with another field to indicate additional
340 # subclassing. This means we have to do this part the hard way.
341 # TODO: handle more than one level.
342 0 my @all_type_objects = $sub_classification_meta_class_name->get();
343 0 for my $some_type_obj (@all_type_objects) {
344 0 my $some_subclass_name = $some_type_obj->subclass_name($class);
345 0 ▶ unless (UR::Object::Type->get($some_subclass_name)->is_abstract) {
Branch: 1 branch
BranchTrueFalseTotal
unless ("UR::Object::Type"->get($some_subclass_name)->is_abstract) 0 0 0
346 0 next;
347 }
348 0 my $some_subclass_meta = $some_subclass_name->__meta__;
349 0 my $some_subclass_type_class =
350 $some_subclass_meta->sub_classification_meta_class_name;
351 0 ▶ if ($type_obj = $some_subclass_type_class->get($subtype_name)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type_obj = $some_subclass_type_class->get($subtype_name)) { } 0 0 0
352 # this second-tier subclass works
353 0 last;
354 }
355 else {
356 # try another subclass, and check the subclasses under it
357 #print "skipping $some_subclass_name: no $subtype_name for $some_subclass_type_class\n";
358 }
359 }
360 }
361  
362 0 ▶ if ($type_obj) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type_obj) { } 0 0 0
363 0 $subclass_name = $type_obj->subclass_name($class);
364 }
365 else {
366 0 warn "Failed to find $class_name sub-class for type '$subtype_name'!";
367 0 $subclass_name = $class_name;
368 }
369  
370 0 ▶ unless ($subclass_name) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($subclass_name) 0 0 0
371 0 Carp::confess(
372 "Failed to sub-classify $class using "
373 . $type_obj->class
374 . " '" . $type_obj->id . "'"
375 );
376 }
377  
378 0 $subclass_name->class;
379 }
380 0 $subclass_for_subtype_name{$subtype_name} = $subclass_name;
381 }
382 else {
383 0 $subclass_name = $pending_db_object->$subclassify_by;
384 0 ▶ unless ($subclass_name) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($subclass_name) 0 0 0
385 0 Carp::croak("Failed to sub-classify $class while loading; calling method "
386 . "'$subclassify_by' returned false. Relevant object data: "
387 . Data::Dumper::Dumper($pending_db_object));
388 }
389 }
390  
391 # note: we check this again with the real base class, but this keeps junk objects out of the core hash
392 0 ▶ unless ($subclass_name->isa($class)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($subclass_name->isa($class)) 0 0 0
393 # We may have done a load on the base class, and not been able to use properties to narrow down to the correct subtype.
394 # The resultset returned more data than we needed, and we're filtering out the other subclasses here.
395 0 return;
396 }
397 }
398 else {
399 # regular, non-subclassifier
400 0 $subclass_name = $class;
401 }
402  
403 # store the object
404 # note that we do this on the base class even if we know it's going to be put into a subclass below
405 0 $UR::Context::all_objects_loaded->{$class}{$pending_db_object_id} = $pending_db_object;
406 0 $UR::Context::all_objects_cache_size++;
407  
408 # If we're using a light cache, weaken the reference.
409 0 ▶ if ($UR::Context::light_cache and substr($class,0,5) ne 'App::') {
Branch: 1 branch
BranchTrueFalseTotal
if ($UR::Context::light_cache and substr($class, 0, 5) ne "App::") 0 0 0
Condition0%0/3
$UR::Context::light_cache and substr($class, 0, 5) ne "App::"
!ll&&!rl&&r
000
MC/DC0%0/2
$UR::Context::light_cache and substr($class, 0, 5) ne "App::"
$UR::Context::light_cache substr($class, 0, 5) ne "App::"
Truth table0%0/3
A and B
A= $UR::Context::light_cacheB= substr($class, 0, 5) ne "App::"
ABresult
0X0
100
111
410 0 Scalar::Util::weaken($UR::Context::all_objects_loaded->{$class_name}->{$pending_db_object_id});
411 }
412  
413 0 $update_apl_for_loaded_object->($pending_db_object);
414  
415 0 my $boolexpr_evaluated_ok;
416 0 ▶ if ($subclass_name eq $class) {
Branch: 1 branch
BranchTrueFalseTotal
if ($subclass_name eq $class) { } 0 0 0
417 # This object doesn't need additional subclassing
418 # Signal that the object has been loaded
419 # NOTE: until this is done indexes cannot be used to look-up an object
420 0 $pending_db_object->__signal_change__('load');
421 }
422 else {
423 # we did this above, but only checked the base class
424 0 my $subclass_ghost_class = $subclass_name->ghost_class;
425 0 ▶ if ($UR::Context::all_objects_loaded->{$subclass_ghost_class}{$pending_db_object_id}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($UR::Context::all_objects_loaded->{$subclass_ghost_class}{$pending_db_object_id}) 0 0 0
426 # We put it in the object cache a few lines above.
427 # FIXME - why not wait until we know we're keeping it before putting it in there?
428 0 delete $UR::Context::all_objects_loaded->{$class}{$pending_db_object_id};
429 0 $UR::Context::all_objects_cache_size--;
430 0 return;
431 #$pending_db_object = undef;
432 #redo;
433 }
434  
435 0 my $re_bless = $subclass_is_safe_for_re_bless{$subclass_name};
436 0 ▶ if (not defined $re_bless) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $re_bless) 0 0 0
437 0 $re_bless = $dsx->_class_is_safe_to_rebless_from_parent_class($subclass_name, $class);
438 0 ▶ $re_bless ||= 0;
Condition0%0/2
$re_bless ||= 0
l!l
00
MC/DC0%0/1
$re_bless ||= 0
$re_bless
Truth table0%0/2
A
A= $re_bless
Aresult
11
00
439 0 $subclass_is_safe_for_re_bless{$subclass_name} = $re_bless;
440 }
441  
442 0 my $loading_info;
443  
444 0 ▶ if (!$re_bless) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($re_bless) 0 0 0
445 # This object cannot just be re-classified into a subclass because the subclass joins to additional tables.
446 # We'll make a parallel iterator for each subclass we encounter.
447  
448 # Note that we let the calling db-based iterator do that, so that if multiple objects on the row need
449 # sub-classing, we do them all at once.
450  
451 # Decrement all of the param_keys it is using.
452 0 ▶ if ($loading_base_object) {
Branch: 1 branch
BranchTrueFalseTotal
if ($loading_base_object) 0 0 0
453 0 $loading_info = $dsx->_get_object_loading_info($pending_db_object);
454 0 $loading_info = $dsx->_reclassify_object_loading_info_for_new_class($loading_info,$subclass_name);
455 }
456  
457 #$pending_db_object->unload;
458 0 delete $UR::Context::all_objects_loaded->{$class}->{$pending_db_object_id};
459  
460 0 ▶ if ($loading_base_object) {
Branch: 1 branch
BranchTrueFalseTotal
if ($loading_base_object) 0 0 0
461 0 $dsx->_record_that_loading_has_occurred($loading_info);
462 }
463  
464 # NOTE: we're returning a class name instead of an object
465 # this tells the caller to re-do the entire row using a subclass to get the real data.
466 # Hack? Probably so...
467 0 return $subclass_name;
468 }
469  
470 # Performance shortcut.
471 # These need to be subclassed, but there is no additional data to load.
472 # Just remove from the object cache, rebless to the proper subclass, and
473 # re-add to the object cache
474 0 my $already_loaded = $subclass_name->is_loaded($pending_db_object_id);
475  
476 0 my $different;
477 my $merge_exception;
478 0 ▶ if ($already_loaded) {
Branch: 1 branch
BranchTrueFalseTotal
if ($already_loaded) 0 0 0
479 0 eval { $different = $context->__merge_db_data_with_existing_object($class, $already_loaded, $pending_db_object_data, \@property_names) };
480 0 $merge_exception = $@;
481 }
482  
483 0 ▶ if ($already_loaded and !$different and !$merge_exception) {
Branch: 1 branch
BranchTrueFalseTotal
if ($already_loaded and not $different and not $merge_exception) { } 0 0 0
Condition0%0/6
$already_loaded and not $different and not $merge_exception
!ll&&!rl&&r
000
$already_loaded and not $different
!ll&&!rl&&r
000
MC/DC0%0/3
$already_loaded and not $different and not $merge_exception
$already_loaded not $different not $merge_exception
Truth table0%0/4
A and not(B) and not(C)
A= $already_loadedB= not $differentC= not $merge_exception
ABCresult
0XX0
10X0
1100
1111
484 0 ▶ if ($pending_db_object == $already_loaded) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pending_db_object == $already_loaded) 0 0 0
485 0 Carp::croak("An object of type ".$already_loaded->class." with ID '".$already_loaded->id
486 ."' was just loaded, but already exists in the object cache in the proper subclass");
487 }
488 0 ▶ if ($loading_base_object) {
Branch: 1 branch
BranchTrueFalseTotal
if ($loading_base_object) 0 0 0
489 # Get our records about loading this object
490 0 $loading_info = $dsx->_get_object_loading_info($pending_db_object);
491  
492 # Transfer the load info for the load we _just_ did to the subclass too.
493 0 my $subclassified_template = $rule_template->sub_classify($subclass_name);
494 0 $loading_info->{$subclassified_template->id} = $loading_info->{$template_id};
495 0 $loading_info = $dsx->_reclassify_object_loading_info_for_new_class($loading_info,$subclass_name);
496 }
497  
498 # This will wipe the above data from the object and the contex...
499 0 delete $UR::Context::all_objects_loaded->{$class}->{$pending_db_object_id};
500  
501 0 ▶ if ($loading_base_object) {
Branch: 1 branch
BranchTrueFalseTotal
if ($loading_base_object) 0 0 0
502 # ...now we put it back for both.
503 0 $dsx->_add_object_loading_info($already_loaded, $loading_info);
504 0 $dsx->_record_that_loading_has_occurred($loading_info);
505 }
506  
507 0 bless($pending_db_object,'UR::DeletedRef');
508 0 $pending_db_object = $already_loaded;
509 }
510 else {
511 0 ▶ if ($loading_base_object) {
Branch: 1 branch
BranchTrueFalseTotal
if ($loading_base_object) 0 0 0
512 0 my $subclassified_template = $rule_template->sub_classify($subclass_name);
513  
514 0 $loading_info = $dsx->_get_object_loading_info($pending_db_object);
515 0 $dsx->_record_that_loading_has_occurred($loading_info);
516 0 $loading_info->{$subclassified_template->id} = delete $loading_info->{$template_id};
517 0 $loading_info = $dsx->_reclassify_object_loading_info_for_new_class($loading_info,$subclass_name);
518 }
519  
520 0 my $prev_class_name = $pending_db_object->class;
521 #my $id = $pending_db_object->id;
522 #$pending_db_object->__signal_change__("unload");
523 0 delete $UR::Context::all_objects_loaded->{$prev_class_name}->{$pending_db_object_id};
524 0 delete $UR::Context::all_objects_are_loaded->{$prev_class_name};
525 0 ▶ if ($merge_exception) {
Branch: 1 branch
BranchTrueFalseTotal
if ($merge_exception) 0 0 0
526 # Now that we've removed traces of the incorrectly-subclassed $pending_db_object,
527 # we can pass up any exception generated in __merge_db_data_with_existing_object
528 0 Carp::croak($merge_exception);
529 }
530 0 ▶ if ($already_loaded) {
Branch: 1 branch
BranchTrueFalseTotal
if ($already_loaded) { } 0 0 0
531 # The new object should replace the old object. Since other parts of the user's program
532 # may have references to this object, we need to copy the values from the new object into
533 # the existing cached object
534 0 bless($pending_db_object,'UR::DeletedRef');
535 0 $pending_db_object = $already_loaded;
536 } else {
537 # This is a completely new object
538 0 $UR::Context::all_objects_loaded->{$subclass_name}->{$pending_db_object_id} = $pending_db_object;
539 }
540 0 bless $pending_db_object, $subclass_name;
541 0 $pending_db_object->__signal_change__("load");
542  
543 0 $dsx->_add_object_loading_info($pending_db_object, $loading_info);
544 0 $dsx->_record_that_loading_has_occurred($loading_info);
545 }
546  
547 # the object may no longer match the rule after subclassifying...
548 0 ▶ if ($needs_further_boolexpr_evaluation_after_loading
Branch: 1 branch
BranchTrueFalseTotal
if ($needs_further_boolexpr_evaluation_after_loading and $loading_base_object and not $rule->evaluate($pending_db_object)) { } 0 0 0
Condition0%0/6
$needs_further_boolexpr_evaluation_after_loading and $loading_base_object and not $rule->evaluate($pending_db_object)
!ll&&!rl&&r
000
$needs_further_boolexpr_evaluation_after_loading and $loading_base_object
!ll&&!rl&&r
000
MC/DC0%0/3
$needs_further_boolexpr_evaluation_after_loading and $loading_base_object and not $rule->evaluate($pending_db_object)
$needs_further_boolexpr_evaluation_after_loading $loading_base_object not $rule->evaluate($pending_db_object)
Truth table0%0/4
A and B and not(C)
A= $needs_further_boolexpr_evaluation_after_loadingB= $loading_base_objectC= not $rule->evaluate($pending_db_object)
ABCresult
0XX0
10X0
1100
1111
549 and
550 $loading_base_object
551 and
552 not $rule->evaluate($pending_db_object)
553 ) {
554 #print "Object does not match rule!" . Dumper($pending_db_object,[$rule->params_list]) . "\n";
555 #$rule->evaluate($pending_db_object);
556 0 return;
557 } else {
558 0 $boolexpr_evaluated_ok = 1;
559 }
560 } # end of sub-classification code
561  
562 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($loading_base_object and $needs_further_boolexpr_evaluation_after_loading and not $boolexpr_evaluated_ok and not $rule->evaluate($pending_db_object)) 0 0 0
Condition0%0/9
$loading_base_object and $needs_further_boolexpr_evaluation_after_loading and not $boolexpr_evaluated_ok and not $rule->evaluate($pending_db_object)
!ll&&!rl&&r
000
$loading_base_object and $needs_further_boolexpr_evaluation_after_loading and not $boolexpr_evaluated_ok
!ll&&!rl&&r
000
$loading_base_object and $needs_further_boolexpr_evaluation_after_loading
!ll&&!rl&&r
000
MC/DC0%0/4
$loading_base_object and $needs_further_boolexpr_evaluation_after_loading and not $boolexpr_evaluated_ok and not $rule->evaluate($pending_db_object)
$loading_base_object $needs_further_boolexpr_evaluation_after_loading not $boolexpr_evaluated_ok not $rule->evaluate($pending_db_object)
Truth table0%0/5
A and B and not(C) and not(D)
A= $loading_base_objectB= $needs_further_boolexpr_evaluation_after_loadingC= not $boolexpr_evaluated_okD= not $rule->evaluate($pending_db_object)
ABCDresult
0XXX0
10XX0
110X0
11100
11111
563 $loading_base_object
564 and
565 $needs_further_boolexpr_evaluation_after_loading
566 and
567 ( ! $boolexpr_evaluated_ok )
568 and
569 ( ! $rule->evaluate($pending_db_object) )
570 ) {
571 0 return;
572 }
573 } # end handling newly loaded objects
574  
575 # If the rule had hints, mark that we loaded those things too, in all_params_loaded
576 0 ▶ if ($hints_or_delegation) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hints_or_delegation) 0 0 0
577 0 my $templates_and_rules = $fab_class->_lapl_data_for_delegation_data($hints_or_delegation,
578 $next_db_row,
579 $pending_db_object);
580 0 ▶ while ( my($template_id, $rule_id) = each %$templates_and_rules) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$templates_and_rules) 0 0 0
581 0 $local_all_params_loaded->{$template_id}->{$rule_id}++;
582 0 $UR::Context::all_params_loaded->{$template_id}->{$rule_id} = undef;
583 }
584 }
585  
586 # note all of the joins which follow this object as having been "done"
587 0 ▶ if (my $next_joins = $loading_template->{next_joins}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $next_joins = $loading_template->{"next_joins"}) 0 0 0
588 0 if (0) {
589 # disabled until a fully reframed query is the basis for these joins
590 for my $next_join (@$next_joins) {
591 my ($bxt_id, $values, $value_position_property_name) = @$next_join;
592 for (my $n = 0; $n < @$value_position_property_name; $n+=2) {
593 my $pos = $value_position_property_name->[$n];
594 my $name = $value_position_property_name->[$n+1];
595 $values->[$pos] = $pending_db_object->$name;
596 }
597 my $bxt = UR::BoolExpr::Template::And->get($bxt_id);
598 my $bx = $bxt->get_rule_for_values(@$values);
599 $UR::Context::all_params_loaded->{$bxt->{id}}->{$bx->{id}} = undef;
600 $local_all_params_loaded->{$bxt->{id}}->{$bx->{id}}++;
601 print "remembering $bx\n";
602 }
603 }
604 }
605  
606 # When there is recursion in the query, we record data from each
607 # recursive "level" as though the query was done individually.
608 0 ▶ if ($recursion_desc and $loading_base_object) {
Branch: 1 branch
BranchTrueFalseTotal
if ($recursion_desc and $loading_base_object) 0 0 0
Condition0%0/3
$recursion_desc and $loading_base_object
!ll&&!rl&&r
000
MC/DC0%0/2
$recursion_desc and $loading_base_object
$recursion_desc $loading_base_object
Truth table0%0/3
A and B
A= $recursion_descB= $loading_base_object
ABresult
0X0
100
111
609 # if we got a row from a query, the object must have
610 # a db_committed or db_saved_committed
611 0 ▶ my $dbc = $pending_db_object->{db_committed} || $pending_db_object->{db_saved_uncommitted};
Condition0%0/3
$pending_db_object->{'db_committed'} || $pending_db_object->{'db_saved_uncommitted'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$pending_db_object->{'db_committed'} || $pending_db_object->{'db_saved_uncommitted'}
$pending_db_object->{'db_committed'} $pending_db_object->{'db_saved_uncommitted'}
Truth table0%0/3
A || B
A= $pending_db_object->{'db_committed'}B= $pending_db_object->{'db_saved_uncommitted'}
ABresult
1X1
011
000
612 0 ▶ Carp::croak("Loaded database data has no save data for $class id ".$pending_db_object->id
Branch: 1 branch
BranchTrueFalseTotal
unless $dbc 0 0 0
613 .". Something bad happened.".Data::Dumper::Dumper($pending_db_object)) unless $dbc;
614  
615 0 my $value_by_which_this_object_is_loaded_via_recursion = $dbc->{$recurse_property_on_this_row};
616 0 my $value_referencing_other_object = $dbc->{$recurse_property_referencing_other_rows};
617 0 ▶ $value_referencing_other_object = '' unless (defined $value_referencing_other_object);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value_referencing_other_object 0 0 0
618 0 ▶ unless ($recurse_property_value_found{$value_referencing_other_object}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($recurse_property_value_found{$value_referencing_other_object}) 0 0 0
619 # This row points to another row which will be grabbed because the query is hierarchical.
620 # Log the smaller query which would get the hierarchically linked data directly as though it happened directly.
621 0 $recurse_property_value_found{$value_referencing_other_object} = 1;
622 # note that the direct query need not be done again
623 0 my $equiv_rule = UR::BoolExpr->resolve_normalized(
624 $class,
625 $recurse_property_on_this_row => $value_referencing_other_object,
626 );
627 0 my $equiv_rule_id = $equiv_rule->id;
628 0 my $equiv_template_id = $equiv_rule->template_id;
629  
630 # note that the recursive query need not be done again
631 0 my $equiv_rule_2 = UR::BoolExpr->resolve_normalized(
632 $class,
633 $recurse_property_on_this_row => $value_referencing_other_object,
634 -recurse => $recursion_desc,
635 );
636 0 my $equiv_rule_id_2 = $equiv_rule_2->id;
637 0 my $equiv_template_id_2 = $equiv_rule_2->template_id;
638  
639 # For any of the hierarchically related data which is already loaded,
640 # note on those objects that they are part of that query. These may have loaded earlier in this
641 # query, or in a previous query. Anything NOT already loaded will be hit later by the if-block below.
642 0 my @subset_loaded = $class->is_loaded($recurse_property_on_this_row => $value_referencing_other_object);
643 0 $UR::Context::all_params_loaded->{$equiv_template_id}->{$equiv_rule_id} = undef;
644 0 $UR::Context::all_params_loaded->{$equiv_template_id_2}->{$equiv_rule_id_2} = undef;
645 0 $local_all_params_loaded->{$equiv_template_id}->{$equiv_rule_id} = scalar(@subset_loaded);
646 0 $local_all_params_loaded->{$equiv_template_id_2}->{$equiv_rule_id_2} = scalar(@subset_loaded);
647 0 for my $pending_db_object (@subset_loaded) {
648 0 $pending_db_object->{__load}->{$equiv_template_id}->{$equiv_rule_id}++;
649 0 $pending_db_object->{__load}->{$equiv_template_id_2}->{$equiv_rule_id_2}++;
650 }
651 }
652  
653 # NOTE: if it were possible to use undef values in a connect-by, this could be a problem
654 # however, connect by in UR is always COL = COL, which would always fail on NULLs.
655 0 ▶ if (defined($value_by_which_this_object_is_loaded_via_recursion) and $recurse_property_value_found{$value_by_which_this_object_is_loaded_via_recursion}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value_by_which_this_object_is_loaded_via_recursion and $recurse_property_value_found{$value_by_which_this_object_is_loaded_via_recursion}) 0 0 0
Condition0%0/3
defined $value_by_which_this_object_is_loaded_via_recursion and $recurse_property_value_found{$value_by_which_this_object_is_loaded_via_recursion}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $value_by_which_this_object_is_loaded_via_recursion and $recurse_property_value_found{$value_by_which_this_object_is_loaded_via_recursion}
defined $value_by_which_this_object_is_loaded_via_recursion $recurse_property_value_found{$value_by_which_this_object_is_loaded_via_recursion}
Truth table0%0/3
A and B
A= defined $value_by_which_this_object_is_loaded_via_recursionB= $recurse_property_value_found{$value_by_which_this_object_is_loaded_via_recursion}
ABresult
0X0
100
111
656 # This row was expected because some other row in the hierarchical query referenced it.
657 # Up the object count, and note on the object that it is a result of this query.
658 0 my $equiv_rule = UR::BoolExpr->resolve_normalized(
659 $class,
660 $recurse_property_on_this_row => $value_by_which_this_object_is_loaded_via_recursion,
661 );
662 0 my $equiv_rule_id = $equiv_rule->id;
663 0 my $equiv_template_id = $equiv_rule->template_id;
664  
665 # note that the recursive query need not be done again
666 0 my $equiv_rule_2 = UR::BoolExpr->resolve_normalized(
667 $class,
668 $recurse_property_on_this_row => $value_by_which_this_object_is_loaded_via_recursion,
669 -recurse => $recursion_desc
670 );
671 0 my $equiv_rule_id_2 = $equiv_rule_2->id;
672 0 my $equiv_template_id_2 = $equiv_rule_2->template_id;
673  
674 0 $UR::Context::all_params_loaded->{$equiv_template_id}->{$equiv_rule_id} = undef;
675 0 $UR::Context::all_params_loaded->{$equiv_template_id_2}->{$equiv_rule_id_2} = undef;
676 0 $local_all_params_loaded->{$equiv_template_id}->{$equiv_rule_id}++;
677 0 $local_all_params_loaded->{$equiv_template_id_2}->{$equiv_rule_id_2}++;
678 0 $pending_db_object->{__load}->{$equiv_template_id}->{$equiv_rule_id}++;
679 0 $pending_db_object->{__load}->{$equiv_template_id_2}->{$equiv_rule_id_2}++;
680 }
681 } # end of handling recursion
682  
683 0 return $pending_db_object;
684  
685 0 }; # end of per-class object fabricator
686 0 Sub::Name::subname("UR::Context::__object_fabricator(closure)__ ($class_name)", $object_fabricator);
687  
688 # remember all the changes to $UR::Context::all_params_loaded that should be made.
689 # This fixes the problem where you create an iterator for a query, read back some of
690 # the items, but not all, then later make the same query. The old behavior made
691 # entries in all_params_loaded as objects got loaded from the DB, so that at the time
692 # the second query is made, UR::Context::_cache_is_complete_for_class_and_normalized_rule()
693 # sees there are entries in all_params_loaded, and so reports yes, the cache is complete,
694 # and the second query only returns the objects that were loaded during the first query.
695 #
696 # The new behavior builds up changes to be made to all_params_loaded, and someone
697 # needs to call $object_fabricator->finalize() to apply these changes
698 0 $fabricator_obj = $fab_class->_create(fabricator => $object_fabricator,
699 context => $context,
700 all_params_loaded => $local_all_params_loaded,
701 in_clause_values => \%in_clause_values);
702  
703 0 return $fabricator_obj;
704 }
705  
706  
707 # Given the data created in _resolve_delegation_data (rule templates and values/valuerefs)
708 # return a hash of template IDs => rule IDs that need to be manipulated in local_all_params_loaded
709 0 ▶sub _lapl_data_for_delegation_data {
Subroutine _lapl_data_for_delegation_data: not called CC=6 SCAR=37.4
710 0 my($fab_class, $delegation_data_list, $next_db_row, $pending_db_object) = @_;
711  
712 0 my %tmpl_and_rules;
713  
714 0 foreach my $delegation_data ( @$delegation_data_list ) {
715 0 my $value_sources = $delegation_data->[0];
716 0 my $rule_tmpl = $delegation_data->[1];
717 0 my @values;
718 0 foreach my $value_source ( @$value_sources ) {
719 0 ▶ if (! ref($value_source)) {
Branch: 3 branches
BranchTrueFalseTotal
if (not ref $value_source) { } 0 0 0
elsif (&Scalar::Util::looks_like_number($$value_source)) { } 0 0 0
elsif ($pending_db_object) { } 0 0 0
720 0 push @values, $value_source;
721 } elsif (Scalar::Util::looks_like_number($$value_source)) {
722 0 push @values, $next_db_row->[$$value_source];
723 } elsif ($pending_db_object) {
724 0 my $method_name = $$value_source;
725 0 my $result = eval { $pending_db_object->$method_name };
726 0 push @values, $result;
727 } else {
728 0 Carp::croak("Can't resolve value for '".$$value_source."' in delegation data when there is no object involved");
729 }
730 }
731 0 my $rule = $rule_tmpl->get_normalized_rule_for_values(@values);
732 0 $tmpl_and_rules{$rule_tmpl->id} = $rule->id;
733 }
734 0 return \%tmpl_and_rules;
735 }
736  
737  
738 # This is used by fabricators created as a result of filters or hints on delegated properties
739 # of the primary object to pre-calculate rule templates and value sources that can be combined
740 # with these templates to make rules. The resulting template and rule IDs are then plugged into
741 # all_params_loaded to indicate these related objects are loaded so that subsequent queries
742 # will not hit the data sources.
743 0 ▶sub _resolve_delegation_data {
Subroutine _resolve_delegation_data: not called CC=29 SCAR=67.7
744 0 my($fab_class,$rule,$loading_template,$query_plan,$local_all_params_loaded) = @_;
745  
746 0 my $rule_template = $rule->template;
747  
748 0 my $query_class_meta = $rule_template->subject_class_name->__meta__;
749  
750 0 my %hints;
751 0 ▶ if ($rule_template->hints) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rule_template->hints) 0 0 0
752 0 $hints{$_} = 1 foreach(@{ $rule_template->hints });
753 }
754 0 my %delegations;
755 0 ▶ if (@{ $query_plan->{'joins'}} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$query_plan->{"joins"};}) 0 0 0
756 0 foreach my $delegated_property_name ( $rule_template->_property_names ) {
757 0 my $delegated_property_meta = $query_class_meta->property_meta_for_name($delegated_property_name);
758 0 ▶ next unless ($delegated_property_meta and $delegated_property_meta->is_delegated);
Branch: 1 branch
BranchTrueFalseTotal
unless $delegated_property_meta and $delegated_property_meta->is_delegated 0 0 0
Condition0%0/3
$delegated_property_meta and $delegated_property_meta->is_delegated
!ll&&!rl&&r
000
MC/DC0%0/2
$delegated_property_meta and $delegated_property_meta->is_delegated
$delegated_property_meta $delegated_property_meta->is_delegated
Truth table0%0/3
A and B
A= $delegated_property_metaB= $delegated_property_meta->is_delegated
ABresult
0X0
100
111
759 0 $delegations{$delegated_property_name} = 1;
760 }
761 }
762  
763 0 my $this_object_num = $loading_template->{'object_num'};
764  
765 0 my $join = $query_plan->_get_alias_join($loading_template->{'table_alias'});
766 0 ▶ return unless $join; # would this ever be false?
Branch: 1 branch
BranchTrueFalseTotal
unless $join 0 0 0
767 0 ▶ return unless ($join->{'foreign_class'} eq $loading_template->{'data_class_name'}); # sanity check
Branch: 1 branch
BranchTrueFalseTotal
unless $join->{"foreign_class"} eq $loading_template->{"data_class_name"} 0 0 0
768  
769 0 my $delegated_property_meta;
770 # Find out which delegation property was responsible for this object being loaded
771 DELEGATIONS:
772 0 foreach my $delegation ((keys %hints), (keys %delegations)) {
773 0 my $query_property_meta = $query_class_meta->property_meta_for_name($delegation);
774 0 ▶ next DELEGATIONS unless $query_property_meta;
Branch: 1 branch
BranchTrueFalseTotal
unless $query_property_meta 0 0 0
775  
776 0 my @joins_from_delegation = $query_property_meta->_resolve_join_chain();
777 0 foreach my $join_from_delegation ( @joins_from_delegation ) {
778 0 ▶ if ($join_from_delegation->id eq $join->id) {
Branch: 1 branch
BranchTrueFalseTotal
if ($join_from_delegation->id eq $join->id) 0 0 0
779 0 $delegated_property_meta = $query_property_meta;
780 0 last DELEGATIONS;
781 }
782 }
783 }
784 0 ▶ return unless $delegated_property_meta;
Branch: 1 branch
BranchTrueFalseTotal
unless $delegated_property_meta 0 0 0
785 0 my $delegated_property_name = $delegated_property_meta->property_name;
786  
787 0 ▶ return if $join->destination_is_all_id_properties();
Branch: 1 branch
BranchTrueFalseTotal
if $join->destination_is_all_id_properties 0 0 0
788  
789 0 my @template_filter_names = @{$join->{'foreign_property_names'}};
790 0 my %template_filter_values;
791 0 foreach my $name ( @template_filter_names ) {
792 my $column_num = $query_plan->column_index_for_class_property_and_object_num(
793 0 $join->{'foreign_class'},
794 $name,
795 $this_object_num);
796 0 ▶ if (defined $column_num) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $column_num) { } 0 0 0
797 0 $template_filter_values{$name} = \$column_num;
798 } else {
799 0 my $prop_name = $name;
800 0 $template_filter_values{$name} = \$prop_name;
801 }
802 }
803  
804 0 ▶ if ($delegations{$delegated_property_name}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($delegations{$delegated_property_name}) 0 0 0
805 0 my $delegation_final_property_meta = $delegated_property_meta->final_property_meta;
806 0 ▶ if ($delegation_final_property_meta
Branch: 1 branch
BranchTrueFalseTotal
if ($delegation_final_property_meta and $delegation_final_property_meta->class_name eq $join->{"foreign_class"}) 0 0 0
Condition0%0/3
$delegation_final_property_meta and $delegation_final_property_meta->class_name eq $join->{"foreign_class"}
!ll&&!rl&&r
000
MC/DC0%0/2
$delegation_final_property_meta and $delegation_final_property_meta->class_name eq $join->{"foreign_class"}
$delegation_final_property_meta $delegation_final_property_meta->class_name eq $join->{"foreign_class"}
Truth table0%0/3
A and B
A= $delegation_final_property_metaB= $delegation_final_property_meta->class_name eq $join->{"foreign_class"}
ABresult
0X0
100
111
807 and
808 $delegation_final_property_meta->class_name eq $join->{'foreign_class'}
809 ) {
810 # This delegation points to (or at least through) this join's foreign class
811 # We'll note that these related objects were loaded as a result of being
812 # connected to the primary object by this value, and filtered by the
813 # delegation property's value
814 0 my $delegation_final_property_name = $delegation_final_property_meta->property_name;
815 my $column_num = $query_plan->column_index_for_class_property_and_object_num(
816 0 $join->{'foreign_class'},
817 $delegation_final_property_name,
818 $this_object_num);
819 0 push @template_filter_names, $delegation_final_property_name;
820 0 ▶ if ($delegation_final_property_meta->column_name and ! defined ($column_num)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($delegation_final_property_meta->column_name and not defined $column_num) 0 0 0
Condition0%0/3
$delegation_final_property_meta->column_name and not defined $column_num
!ll&&!rl&&r
000
MC/DC0%0/2
$delegation_final_property_meta->column_name and not defined $column_num
$delegation_final_property_meta->column_name not defined $column_num
Truth table0%0/3
A and not(B)
A= $delegation_final_property_meta->column_nameB= not defined $column_num
ABresult
0X0
100
111
821 # sanity check
822 Carp::carp("Could not determine column offset in result set for property "
823 0 . "$delegation_final_property_name of class " . $join->{'foreign_class'}
824 . " even though it has column_name " . $delegation_final_property_meta->column_name);
825 0 $column_num = undef;
826 }
827 0 ▶ if (defined $column_num) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $column_num) { } 0 0 0
828 0 $template_filter_values{$delegation_final_property_name} = \$column_num;
829 } else {
830 0 $template_filter_values{$delegation_final_property_name} = \$delegation_final_property_name;
831 }
832 }
833 }
834  
835 # For missing objects, ie. a left join was done and it matched nothing
836 0 my @missing_prop_names;
837 my %missing_values;
838 0 ▶ for (my $i = 0; $i < @{ $join->{'foreign_property_names'}}; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @{$join->{"foreign_property_names"};}) 0 0 0
839 # we're using the source class/property here because we're going to denote that a value
840 # of the source class of the join matched nothing
841 0 my $prop_name = $join->{'foreign_property_names'}->[$i];
842 0 push @missing_prop_names, $prop_name;
843 0 my $source_class = $join->{'source_class'};
844 0 my $source_prop_name = $join->{'source_property_names'}->[$i];
845 0 my $column_num;
846 0 ▶ if( my($actual_prop_meta) = $source_class->__meta__->_concrete_property_meta_for_class_and_name($source_prop_name) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my($actual_prop_meta) = $source_class->__meta__->_concrete_property_meta_for_class_and_name($source_prop_name)) 0 0 0
847 0 $column_num = $query_plan->column_index_for_class_and_property_before_object_num($actual_prop_meta->class_name,
848 $actual_prop_meta->property_name,
849 $this_object_num);
850 }
851 0 ▶ if (defined $column_num) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $column_num) { } 0 0 0
852 0 $missing_values{$prop_name} = \$column_num;
853 } else {
854 0 Carp::croak("Can't determine resultset column for $source_class property $source_prop_name for rule $rule");
855 }
856 }
857 0 ▶ if ($join->{'where'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($join->{"where"}) 0 0 0
858 0 ▶ for (my $i = 0; $i < @{$join->{'where'}}; $i += 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @{$join->{"where"};}) 0 0 0
859 0 my $where_prop = $join->{'where'}->[$i];
860 0 push @template_filter_names, $where_prop;
861 0 push @missing_prop_names, $where_prop;
862  
863 0 my $pos = index($where_prop, ' ');
864 0 ▶ if ($pos != -1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pos != -1) 0 0 0
865 # the key is "propname op"
866 0 $where_prop = substr($where_prop,0,$pos);
867 }
868 0 my $where_value = $join->{'where'}->[$i+1];
869 0 $template_filter_values{$where_prop} = $where_value;
870 0 $missing_values{$where_prop} = $where_value;
871 }
872 }
873  
874 0 my $missing_rule_tmpl = UR::BoolExpr::Template->resolve($join->{'foreign_class'}, @missing_prop_names)->get_normalized_template_equivalent;
875  
876 0 my $related_rule_tmpl = UR::BoolExpr::Template->resolve($join->{'foreign_class'},
877 @template_filter_names)->get_normalized_template_equivalent;
878  
879 0 my(@hints_or_delegation, @delegations_with_no_objects);
880 # Items in the first listref can be one of three things:
881 # 1) a reference to an integer - meaning retrieve the value from this column in the result set
882 # 2) a reference to a string - meaning retrieve the value from the object usign this as a property name
883 # 3) a string - meaning this is a literal value to fill in directly
884 # The second item is a rule template we'll be feeding these values in to
885 0 my @template_filter_values = @template_filter_values{$related_rule_tmpl->_property_names};
886 0 push @hints_or_delegation, [ \@template_filter_values, $related_rule_tmpl];
887  
888 0 my @missing_values = @missing_values{$missing_rule_tmpl->_property_names};
889 0 push @delegations_with_no_objects, [\@missing_values, $missing_rule_tmpl];
890  
891 0 return (\@hints_or_delegation, \@delegations_with_no_objects);
892 }
893  
894  
895  
896 0 ▶sub all_object_fabricators {
Subroutine all_object_fabricators: not called CC=1 SCAR=6.9
Pod documented
897 0 return values %all_object_fabricators;
898 }
899  
900 # simple accessors
901  
902 0 ▶sub fabricator {
Subroutine fabricator: not called CC=1 SCAR=6.9
Pod undocumented
903 0 my $self = shift;
904 0 return $self->{'fabricator'};
905 }
906  
907 0 ▶sub context {
Subroutine context: not called CC=1 SCAR=6.9
Pod undocumented
908 0 my $self = shift;
909 0 return $self->{'context'};
910 }
911  
912 0 ▶sub all_params_loaded {
Subroutine all_params_loaded: not called CC=1 SCAR=6.9
Pod undocumented
913 0 my $self = shift;
914 0 return $self->{'all_params_loaded'};
915 }
916  
917 0 ▶sub in_clause_values {
Subroutine in_clause_values: not called CC=1 SCAR=6.9
Pod undocumented
918 0 my $self = shift;
919 0 return $self->{'in_clause_values'};
920 }
921  
922 # call the object fabricator closure
923 0 ▶sub fabricate {
Subroutine fabricate: not called CC=1 SCAR=6.9
Pod documented
924 0 my $self = shift;
925  
926 0 &{$self->{'fabricator'}};
927 }
928  
929  
930  
931 # Returns true if this fabricator has loaded an object matching this boolexpr
932 0 ▶sub is_loading_in_progress_for_boolexpr {
Subroutine is_loading_in_progress_for_boolexpr: not called CC=3 SCAR=24.8
Pod documented
933 0 my $self = shift;
934 0 my $boolexpr = shift;
935  
936 0 my $template_id = $boolexpr->template_id;
937 # FIXME should it use is_subsest_of here?
938 0 ▶ return unless exists $self->{'all_params_loaded'}->{$template_id};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"all_params_loaded"}{$template_id} 0 0 0
939 0 ▶ return unless exists $self->{'all_params_loaded'}->{$template_id}->{$boolexpr->id};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"all_params_loaded"}{$template_id}{$boolexpr->id} 0 0 0
940 0 return 1;
941 }
942  
943  
944 # UR::Contect::_abandon_object calls this to forget about loading an object
945 0 ▶sub delete_from_all_params_loaded {
Subroutine delete_from_all_params_loaded: not called CC=5 SCAR=34.0
Pod undocumented
946 0 my($self,$template_id,$boolexpr_id) = @_;
947  
948 0 ▶ return unless ($template_id and $boolexpr_id);
Branch: 1 branch
BranchTrueFalseTotal
unless $template_id and $boolexpr_id 0 0 0
Condition0%0/3
$template_id and $boolexpr_id
!ll&&!rl&&r
000
MC/DC0%0/2
$template_id and $boolexpr_id
$template_id $boolexpr_id
Truth table0%0/3
A and B
A= $template_idB= $boolexpr_id
ABresult
0X0
100
111
949  
950 0 my $all_params_loaded = $self->all_params_loaded;
951  
952 0 ▶ return unless $all_params_loaded;
Branch: 1 branch
BranchTrueFalseTotal
unless $all_params_loaded 0 0 0
953 0 ▶ return unless exists($all_params_loaded->{$template_id});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $all_params_loaded->{$template_id} 0 0 0
954 0 delete $all_params_loaded->{$template_id}->{$boolexpr_id};
955 }
956  
957  
958 0 ▶sub finalize {
Subroutine finalize: not called CC=1 SCAR=6.9
Pod documented
959 0 my $self = shift;
960  
961 0 $self->apply_all_params_loaded();
962  
963 0 delete $all_object_fabricators{$self};
964 0 $self->{'all_params_loaded'} = undef;
965 }
966  
967  
968 0 ▶sub apply_all_params_loaded {
Subroutine apply_all_params_loaded: not called CC=6 SCAR=37.4
Pod documented
969 0 my $self = shift;
970  
971 0 my $local_all_params_loaded = $self->{'all_params_loaded'};
972  
973 0 my @template_ids = keys %$local_all_params_loaded;
974 0 foreach my $template_id ( @template_ids ) {
975 0 my @rule_ids = keys %{$local_all_params_loaded->{$template_id}};
976 0 foreach my $rule_id ( @rule_ids ) {
977 0 my $val = $local_all_params_loaded->{$template_id}->{$rule_id};
978 0 ▶ next unless exists $UR::Context::all_params_loaded->{$template_id}->{$rule_id}; # Has unload() removed this one earlier?
Branch: 1 branch
BranchTrueFalseTotal
unless exists $UR::Context::all_params_loaded->{$template_id}{$rule_id} 0 0 0
979 0 $UR::Context::all_params_loaded->{$template_id}->{$rule_id} += $val;
980 }
981 }
982  
983 # Anything left in here is in-clause values that matched nothing. Make a note in
984 # all_params_loaded showing that so later queries for those values won't hit the
985 # data source
986 0 my $in_clause_values = $self->{'in_clause_values'};
987 0 my @properties = keys %$in_clause_values;
988 0 foreach my $property ( @properties ) {
989 0 my @values = keys %{$in_clause_values->{$property}};
990 0 foreach my $value ( @values ) {
991 0 my $data = $in_clause_values->{$property}->{$value};
992 0 $UR::Context::all_params_loaded->{$data->[0]}->{$data->[1]} = 0;
993 }
994 }
995  
996 0 $self->{'all_params_loaded'} = {};
997 }
998  
999  
1000 0 ▶sub DESTROY {
Subroutine DESTROY: not called CC=5 SCAR=34.0
1001 0 my $self = shift;
1002 # Don't apply the changes. Maybe the importer closure just went out of scope before
1003 # it read all the data
1004 0 my $local_all_params_loaded = $self->{'all_params_loaded'};
1005 0 ▶ if ($local_all_params_loaded) {
Branch: 1 branch
BranchTrueFalseTotal
if ($local_all_params_loaded) 0 0 0
1006 # finalize wasn't called on this iterator; maybe the importer closure went out
1007 # of scope before it read all the data.
1008 # Conditionally apply the changes from the local all_params_loaded. If the Context's
1009 # all_params_loaded is defined, then another query has successfully run to
1010 # completion, and we should add our data to it. Otherwise, we're the only query like
1011 # this and all_params_loaded should be cleaned out
1012 0 foreach my $template_id ( keys %$local_all_params_loaded ) {
1013 0 while(1) {
1014 0 my($rule_id, $val) = each %{$local_all_params_loaded->{$template_id}};
1015 0 ▶ last unless $rule_id;
Branch: 1 branch
BranchTrueFalseTotal
unless $rule_id 0 0 0
1016 0 ▶ if (defined $UR::Context::all_params_loaded->{$template_id}->{$rule_id}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $UR::Context::all_params_loaded->{$template_id}{$rule_id}) { } 0 0 0
1017 0 $UR::Context::all_params_loaded->{$template_id}->{$rule_id} += $val;
1018 } else {
1019 0 delete $UR::Context::all_params_loaded->{$template_id}->{$rule_id};
1020 }
1021 }
1022 }
1023 }
1024 0 delete $all_object_fabricators{$self};
1025 }
1026  
1027 266 1;
1028  
1029 =pod
1030  
1031 =head1 NAME
1032  
1033 UR::Context::ObjectFabricator - Track closures used to fabricate objects from data sources
1034  
1035 =head1 DESCRIPTION
1036  
1037 Object Fabricators are closures that accept listrefs of data returned by
1038 data source iterators, take slices out of them, and construct UR objects
1039 out of the results. They also handle updating the query cache and merging
1040 changed DB data with previously cached objects.
1041  
1042 UR::Context::ObjectFabricator objects are used internally by UR::Context,
1043 and not intended to be used directly.
1044  
1045 =head1 METHODS
1046  
1047 =over 4
1048  
1049 =item create_for_loading_template
1050  
1051 my $fab = UR::Context::ObjectFabricator->create_for_loading_template(
1052 $context, $loading_tmpl_hashref, $template_data,
1053 $rule, $rule_template, $values, $dsx);
1054  
1055 Returns an object fabricator instance that is able to construct objects
1056 of the rule's target class from rows of data returned by data source
1057 iterators. Object fabricators are used a part of the object loading
1058 process, and are called by UR::Context::get_objects_for_class_and_rule()
1059 to transform a row of data returned by a data source iterator into a UR
1060 object.
1061  
1062 For each class involved in a get request, the system prepares a loading
1063 template that describes which columns of the data source data are to be
1064 used to construct an instance of that class. For example, in the case where
1065 a get() is done on a child class, and the parent and child classes store data
1066 in separate tables linked by a relation-property/foreign-key, then the query
1067 against the data source will involve and SQL join (for RDBMS data sources).
1068 That join will produce a result set that includes data from both tables.
1069  
1070 The C<$loading_tmpl_hashref> will have information about which columns of
1071 that result set map to which properties of each involved class. The heart
1072 of the fabricator closure is a list slice extracting the data for that class
1073 and assigning it to a hash slice of properties to fill in the initial object
1074 data for its class. The remainder of the closure is bookkeeping to keep the
1075 object cache ($UR::Context::all_objects_loaded) and query cache
1076 ($UR::Context::all_params_loaded) consistent.
1077  
1078 The interaction of the object fabricator, the query cache, object cache
1079 pruner and object loading iterators that may or may not have loaded all
1080 their data requires that the object fabricators keep a list of changes they
1081 plan to make to the query cache instead of applying them directly. When
1082 the Underlying Context Loading iterator has loaded the last row from the
1083 Data Source Iterator, it calls C<finalize()> on the object fabricator to
1084 tell it to go ahead and apply its changes; essentially treating that
1085 data as a transaction.
1086  
1087 =item all_object_fabricators
1088  
1089 my @fabs = UR::Context::ObjectFabricator->all_object_fabricators();
1090  
1091 Returns a list of all object fabricators that have not yet been finalized
1092  
1093 =item fabricate
1094  
1095 my $ur_object = $fab->fabricate([columns,from,data,source]);
1096  
1097 Given a listref of data pulled from a data source iterator, it slices out
1098 the appropriate columns from the list and constructs a single object to
1099 return.
1100  
1101 =item is_loading_in_progress_for_boolexpr
1102  
1103 my $bool = $fab->is_loading_in_progress_for_boolexpr($boolexpr);
1104  
1105 Given a UR::BoolExpr instance, it returns true if the given fabricator is
1106 prepared to construct objects matching this boolexpr. This is used by
1107 UR::Context to know if other iterators are still pulling in objects that
1108 could match another iterator's boolexpr, and it should therefore not trust
1109 that the object cache is conplete.
1110  
1111 =item finalize
1112  
1113 $fab->finalize();
1114  
1115 Indicates to the iterator that the caller is done using it for constructing
1116 objects, probably because the data source has no more data or the iterator
1117 that was using this fabricator has gone out of scope.
1118  
1119 =item apply_all_params_loaded
1120  
1121 $fab->apply_all_params_loaded();
1122  
1123 As the fabricator constructs objects, it buffers changes to all_params_loaded
1124 (the Context's query cache) to maintain consistency if multiple iterators are
1125 working concurrently. At the appripriate time, call apply_all_params_loaded()
1126 to take those changes and apply them to the current Context's all_params_loaded.
1127  
1128 =back
1129  
1130 =cut
1131  
« blib/lib/UR/DataSource/QueryPlan.pm ↑ Summary lib/UR/Context/LoadingIterator.pm »