line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Persistence::Entity::Query; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
16832
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
85
|
|
4
|
2
|
|
|
2
|
|
11
|
use warnings; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
73
|
|
5
|
2
|
|
|
2
|
|
12
|
use vars qw($VERSION); |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
97
|
|
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
19
|
use Abstract::Meta::Class ':all'; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
378
|
|
8
|
2
|
|
|
2
|
|
12
|
use base 'SQL::Query'; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
1312
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
$VERSION = 0.02; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 NAME |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
Persistence::Entity::Query - Database entity query. |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 CLASS HIERARCHY |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
SQL::Query |
19
|
|
|
|
|
|
|
| |
20
|
|
|
|
|
|
|
+----Persistence::Entity::Query |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head1 SYNOPSIS |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
my $entity_manager = $class->new(connection_name => 'my_connection'); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
$entity_manager->add_entities(SQL::Entity->new( |
28
|
|
|
|
|
|
|
name => 'emp', |
29
|
|
|
|
|
|
|
unique_expression => 'empno', |
30
|
|
|
|
|
|
|
columns => [ |
31
|
|
|
|
|
|
|
sql_column(name => 'ename'), |
32
|
|
|
|
|
|
|
sql_column(name => 'empno'), |
33
|
|
|
|
|
|
|
sql_column(name => 'deptno') |
34
|
|
|
|
|
|
|
], |
35
|
|
|
|
|
|
|
indexes => [ |
36
|
|
|
|
|
|
|
sql_index(name => 'emp_idx1', columns => ['empno']) |
37
|
|
|
|
|
|
|
] |
38
|
|
|
|
|
|
|
)); |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
package Employee; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
use Abstract::Meta::Class ':all'; |
43
|
|
|
|
|
|
|
use Persistence::ORM ':all'; |
44
|
|
|
|
|
|
|
entity 'emp'; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
column empno => has('$.no') ; |
47
|
|
|
|
|
|
|
column ename => has('$.name'); |
48
|
|
|
|
|
|
|
column deptno => has('$.deptno'); |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
my $query = $entity_manager->query(emp => 'Employee'); |
51
|
|
|
|
|
|
|
$query->set_offset(20); |
52
|
|
|
|
|
|
|
$query->set_limit(5); |
53
|
|
|
|
|
|
|
my @emp = $query->execute(); |
54
|
|
|
|
|
|
|
# do stuff $emp[0]->name |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
my $query = $entity_manager->query('emp'); |
57
|
|
|
|
|
|
|
$query->set_offset(20); |
58
|
|
|
|
|
|
|
$query->set_limit(5); |
59
|
|
|
|
|
|
|
my @emp = $query->execute(); |
60
|
|
|
|
|
|
|
# do stuff $emp[0]->{ename} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head1 DESCRIPTION |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
Represents database query based on entity definition. |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=head1 EXPORT |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
None |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=head2 ATTRIBUTES |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=over |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=item name |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=cut |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
has '$.name' => (required => 1); |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=item cursor_callback |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=cut |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
has '&.cursor_callback' => (required => 1); |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=item condition_converter_callback |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=cut |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
has '&.condition_converter_callback' => (required => 1); |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=back |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head2 METHODS |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=over |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=item execute |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=cut |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub execute { |
105
|
|
|
|
|
|
|
my ($self, $requested_columns, @args) = @_; |
106
|
|
|
|
|
|
|
my $condition_converter_callback = $self->condition_converter_callback; |
107
|
|
|
|
|
|
|
my $condition = $condition_converter_callback->(@args); |
108
|
|
|
|
|
|
|
my ($sql, $bind_variables) = $self->query($requested_columns, $condition); |
109
|
|
|
|
|
|
|
my $cursor_callback = $self->cursor_callback; |
110
|
|
|
|
|
|
|
$cursor_callback->($self, $sql, $bind_variables); |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=item query_setup |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=cut |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
sub query_setup { |
119
|
|
|
|
|
|
|
my $self = shift; |
120
|
|
|
|
|
|
|
$self->_entity_limit_wrapper->query_setup(@_); |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
1; |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
__END__ |