line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package EntityModel::EntityCollection; |
2
|
|
|
|
|
|
|
{ |
3
|
|
|
|
|
|
|
$EntityModel::EntityCollection::VERSION = '0.102'; |
4
|
|
|
|
|
|
|
} |
5
|
|
|
|
|
|
|
use EntityModel::Class { |
6
|
1
|
|
|
|
|
10
|
_isa => [qw(EntityModel::Collection)], |
7
|
|
|
|
|
|
|
query => { type => qw(EntityModel::Query) }, |
8
|
1
|
|
|
1
|
|
117160
|
}; |
|
1
|
|
|
|
|
2
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 NAME |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
EntityModel::EntityCollection - deal with collections of entities |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 VERSION |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
version 0.102 |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 SYNOPSIS |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=cut |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head2 group |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=cut |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub group { |
27
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
28
|
0
|
|
|
|
|
|
my $param = shift; |
29
|
0
|
|
|
|
|
|
logDebug("Group by %s", $param); |
30
|
0
|
|
|
|
|
|
$self->query->add_group($param); |
31
|
0
|
|
|
|
|
|
$self->pending(1); |
32
|
|
|
|
|
|
|
return defined wantarray |
33
|
0
|
0
|
|
|
|
|
? $self |
34
|
|
|
|
|
|
|
: $self->commit |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head2 select |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=cut |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub select : method { |
42
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
43
|
0
|
|
|
|
|
|
foreach my $param (@_) { |
44
|
0
|
|
|
|
|
|
logDebug("Select %s", $param); |
45
|
0
|
|
|
|
|
|
$self->query->add_field($param); |
46
|
|
|
|
|
|
|
} |
47
|
0
|
|
|
|
|
|
$self->pending(1); |
48
|
|
|
|
|
|
|
return defined wantarray |
49
|
0
|
0
|
|
|
|
|
? $self |
50
|
|
|
|
|
|
|
: $self->commit |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=head2 order |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=cut |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub order { |
58
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
59
|
0
|
|
|
|
|
|
foreach my $param (@_) { |
60
|
0
|
|
|
|
|
|
logDebug("Order by %s", $param); |
61
|
0
|
|
|
|
|
|
$self->query->add_order($param); |
62
|
|
|
|
|
|
|
} |
63
|
0
|
|
|
|
|
|
$self->pending(1); |
64
|
|
|
|
|
|
|
return defined wantarray |
65
|
0
|
0
|
|
|
|
|
? $self |
66
|
|
|
|
|
|
|
: $self->commit |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head2 apply |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=cut |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub apply { |
74
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
75
|
0
|
0
|
|
|
|
|
logInfo("Will run query: %s", |
76
|
|
|
|
|
|
|
'select ' . join(', ', map { |
77
|
0
|
|
|
|
|
|
(exists($_->{op}) |
78
|
|
|
|
|
|
|
? $_->{op} . '(' . $_->{field} . ')' |
79
|
|
|
|
|
|
|
: $_->{field}) |
80
|
|
|
|
|
|
|
. ' as "' . $_->{alias} . '"' |
81
|
0
|
0
|
|
|
|
|
} @{ $self->{select} }) |
82
|
|
|
|
|
|
|
. ' from article' |
83
|
|
|
|
|
|
|
. ' where 1=1' |
84
|
|
|
|
|
|
|
. ' group by ' . join(', ', map { |
85
|
0
|
|
|
|
|
|
(exists($_->{op}) |
86
|
|
|
|
|
|
|
? $_->{op} . '(' . $_->{field} . ')' |
87
|
|
|
|
|
|
|
: $_->{field}) |
88
|
0
|
0
|
|
|
|
|
} @{ $self->{group} }) |
|
|
0
|
|
|
|
|
|
89
|
|
|
|
|
|
|
. ' order by ' . join(', ', map { |
90
|
0
|
|
|
|
|
|
exists($_->{alias}) |
91
|
|
|
|
|
|
|
? $_->{alias} |
92
|
|
|
|
|
|
|
: (exists($_->{op}) |
93
|
|
|
|
|
|
|
? $_->{op} . '(' . $_->{field} . ')' |
94
|
|
|
|
|
|
|
: $_->{field}) |
95
|
0
|
|
|
|
|
|
} @{ $self->{order} }) |
96
|
|
|
|
|
|
|
); |
97
|
|
|
|
|
|
|
# $self->(item => 'xyz', map rand(1023), @{$self->{select}}); |
98
|
0
|
|
|
|
|
|
return $self; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
1; |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
__END__ |