line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Persistence::LOB; |
2
|
|
|
|
|
|
|
|
3
|
17
|
|
|
17
|
|
106
|
use strict; |
|
17
|
|
|
|
|
36
|
|
|
17
|
|
|
|
|
700
|
|
4
|
17
|
|
|
17
|
|
97
|
use warnings; |
|
17
|
|
|
|
|
30
|
|
|
17
|
|
|
|
|
625
|
|
5
|
|
|
|
|
|
|
|
6
|
17
|
|
|
17
|
|
87
|
use vars qw($VERSION); |
|
17
|
|
|
|
|
33
|
|
|
17
|
|
|
|
|
928
|
|
7
|
17
|
|
|
17
|
|
83
|
use vars qw(@EXPORT_OK %EXPORT_TAGS $VERSION); |
|
17
|
|
|
|
|
30
|
|
|
17
|
|
|
|
|
1534
|
|
8
|
|
|
|
|
|
|
|
9
|
17
|
|
|
17
|
|
102
|
use Abstract::Meta::Class ':all'; |
|
17
|
|
|
|
|
30
|
|
|
17
|
|
|
|
|
2829
|
|
10
|
17
|
|
|
17
|
|
94
|
use Persistence::Fetchable ':all'; |
|
17
|
|
|
|
|
35
|
|
|
17
|
|
|
|
|
1723
|
|
11
|
17
|
|
|
17
|
|
96
|
use base qw(Exporter Persistence::Fetchable); |
|
17
|
|
|
|
|
29
|
|
|
17
|
|
|
|
|
6410
|
|
12
|
17
|
|
|
17
|
|
124
|
use Carp 'confess'; |
|
17
|
|
|
|
|
43
|
|
|
17
|
|
|
|
|
7924
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
$VERSION = 0.02; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
@EXPORT_OK = qw(LAZY EAGER); |
17
|
|
|
|
|
|
|
%EXPORT_TAGS = (all => \@EXPORT_OK); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 NAME |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
Persistence::LOB - LOBs mapping object. |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head1 CLASS HIERARCHY |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
Persistence::Fetchable |
26
|
|
|
|
|
|
|
| |
27
|
|
|
|
|
|
|
+----Persistence::LOB |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head1 SYNOPSIS |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
use Persistence::ORM':all'; |
32
|
|
|
|
|
|
|
use Persistence::Entity ':all'; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
my $photo_entity = Persistence::Entity->new( |
35
|
|
|
|
|
|
|
name => 'photo', |
36
|
|
|
|
|
|
|
alias => 'ph', |
37
|
|
|
|
|
|
|
primary_key => ['id'], |
38
|
|
|
|
|
|
|
columns => [ |
39
|
|
|
|
|
|
|
sql_column(name => 'id'), |
40
|
|
|
|
|
|
|
sql_column(name => 'name', unique => 1), |
41
|
|
|
|
|
|
|
], |
42
|
|
|
|
|
|
|
lobs => [ |
43
|
|
|
|
|
|
|
sql_lob(name => 'blob_content', size_column => 'doc_size'), |
44
|
|
|
|
|
|
|
] |
45
|
|
|
|
|
|
|
); |
46
|
|
|
|
|
|
|
$entity_manager->add_entities($photo_entity); |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
package Photo; |
49
|
|
|
|
|
|
|
use Abstract::Meta::Class ':all'; |
50
|
|
|
|
|
|
|
use Persistence::ORM ':all'; |
51
|
|
|
|
|
|
|
entity 'photo'; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
column 'id' => has('$.id'); |
54
|
|
|
|
|
|
|
column 'name' => has('$.name'); |
55
|
|
|
|
|
|
|
lob 'blob_content' => (attribute => has('$.image'), fetch_method => LAZY); |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
package EagerPhoto; |
59
|
|
|
|
|
|
|
use Abstract::Meta::Class ':all'; |
60
|
|
|
|
|
|
|
use Persistence::ORM ':all'; |
61
|
|
|
|
|
|
|
entity 'photo'; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
column 'id' => has('$.id'); |
64
|
|
|
|
|
|
|
column 'name' => has('$.name'); |
65
|
|
|
|
|
|
|
lob 'blob_content' => (attribute => has('$.image'), fetch_method => EAGER); |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
my ($photo) = $entity_manager->find(photo => 'Photo', id => 10); |
68
|
|
|
|
|
|
|
$photo->name('Moon'); |
69
|
|
|
|
|
|
|
$photo->set_image($moon_image); |
70
|
|
|
|
|
|
|
$entity_manager->update($photo); |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head1 DESCRIPTION |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
Represents a base class for object relationship. |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head1 EXPORT |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
LAZY EAGER NONE ALL ON_INSERT ON_UPDATE ON_DELETE method by ':all' tag. |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head2 ATTRIBUTES |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=over |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=item attribute |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=cut |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
has '$.attribute' => (required => 1); |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=item orm |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=cut |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
has '$.orm' => (associated_class => 'Persistence::ORM', the_other_end => 'lobs'); |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=item initialise |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=cut |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub initialise { |
104
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
105
|
0
|
0
|
|
|
|
|
$self->install_fetch_interceptor if ($self->fetch_method eq LAZY); |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=item install_fetch_interceptor |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=cut |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub install_fetch_interceptor { |
114
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
115
|
0
|
|
|
|
|
|
my $attribute = $self->attribute; |
116
|
0
|
|
|
|
|
|
$attribute->install_fetch_interceptor($self->lazy_fetch_handler($self->attribute)); |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=item deserialise_attribute |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
Deserializes attribute value. |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=cut |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
sub deserialise_attribute { |
127
|
0
|
|
|
0
|
1
|
|
my ($self, $this, $entity_manager, $orm) = @_; |
128
|
0
|
|
|
|
|
|
my $attribute = $self->attribute; |
129
|
0
|
|
|
|
|
|
my $entity = $entity_manager->entity($orm->entity_name); |
130
|
0
|
|
|
|
|
|
my $unique_values = $orm->unique_values($this, $entity); |
131
|
0
|
|
|
|
|
|
my $lob_column = $entity->lob($attribute->column_name); |
132
|
0
|
|
|
|
|
|
my $lob = $entity->fetch_lob($lob_column->name, $unique_values, $lob_column->size_column); |
133
|
0
|
|
|
|
|
|
my $mutator = $attribute->mutator; |
134
|
0
|
|
|
|
|
|
$this->$mutator($lob); |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
1; |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
__END__ |