File Coverage

blib/lib/DBIx/DataModel/Statement/JDBC.pm
Criterion Covered Total %
statement 18 44 40.9
branch 0 14 0.0
condition 0 2 0.0
subroutine 6 13 46.1
pod 0 4 0.0
total 24 77 31.1


line stmt bran cond sub pod time code
1             #----------------------------------------------------------------------
2             package DBIx::DataModel::Statement::JDBC;
3             #----------------------------------------------------------------------
4 7     7   796 use strict;
  7         15  
  7         200  
5 7     7   31 use warnings;
  7         13  
  7         166  
6 7     7   30 no strict 'refs';
  7         11  
  7         160  
7              
8 7     7   31 use parent qw/DBIx::DataModel::Statement/;
  7         15  
  7         47  
9 7     7   381 use mro qw/c3/;
  7         12  
  7         31  
10 7     7   199 use DBI qw/SQL_INTEGER/;
  7         20  
  7         3851  
11              
12             # methods on the JDBC ResultSet object, without argument
13             foreach my $method (qw/size getRow
14             getMemberCount getSQLStatement
15             beforeFirst afterLast
16             isBeforeFirst isAfterLast/) {
17             *{$method} = sub {
18 0     0     my ($self) = @_;
19 0 0         $self->execute() if !$self->{sth};
20 0           $self->{sth}->jdbc_func("ResultSet.$method");
21             };
22             }
23              
24             # methods on the JDBC ResultSet object, with an INT argument
25             foreach my $method (qw/relative absolute/) {
26             *{$method} = sub {
27 0     0     my ($self, $int_arg) = @_;
28 0 0         $self->execute() if !$self->{sth};
29 0           $self->{sth}->jdbc_func([$int_arg => SQL_INTEGER], "ResultSet.$method");
30             };
31             }
32              
33              
34             # methods on the JDBC Statement object, with an INT argument
35             foreach my $method (qw/setMaxRows setQueryTimeout/) {
36             *{$method} = sub {
37 0     0     my ($self, $int_arg) = @_;
38 0 0         $self->prepare() if !$self->{sth};
39 0           $self->{sth}->jdbc_func([$int_arg => SQL_INTEGER], "Statement.$method");
40             };
41             }
42              
43             sub sqlize {
44 0     0 0   my ($self, @args) = @_;
45              
46             # merge new args into $self->{args}
47 0 0         $self->refine(@args) if @args;
48              
49             # remove -limit and -offset from args; they will be handled later in
50             # prepare() and execute(), see below
51 0           $self->{jdbc_limit} = delete $self->{args}{-limit};
52 0   0       $self->{offset} = delete $self->{args}{-offset} || 0;
53              
54 0           $self->next::method();
55             }
56              
57              
58             sub prepare {
59 0     0 0   my ($self, @args) = @_;
60 0           $self->next::method(@args);
61 0           my $limit = $self->{jdbc_limit};
62 0 0         $self->setMaxRows($limit + $self->{offset}) if $limit;
63 0           return $self;
64             }
65              
66             sub execute {
67 0     0 0   my ($self, @args) = @_;
68 0           $self->next::method(@args);
69 0 0         $self->absolute($self->{offset}) if $self->{offset};
70 0           return $self;
71             }
72              
73             sub row_count {
74 0     0 0   my ($self) = @_;
75 0 0         $self->{row_count} = $self->getMemberCount unless exists $self->{row_count};
76 0           return $self->{row_count};
77             }
78              
79             1;
80              
81             __END__