line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package DBD::Cassandra::dr; |
2
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:TVDW'; |
3
|
|
|
|
|
|
|
$DBD::Cassandra::dr::VERSION = '0.57'; |
4
|
|
|
|
|
|
|
# ABSTRACT: DBD::Cassandra driver handle |
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
14
|
use 5.010; |
|
1
|
|
|
|
|
3
|
|
7
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
16
|
|
8
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
28
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
444
|
use Cassandra::Client 0.10; |
|
1
|
|
|
|
|
95335
|
|
|
1
|
|
|
|
|
446
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
# "*FIX ME* Explain what the imp_data_size is, so that implementors aren't |
13
|
|
|
|
|
|
|
# practicing cargo-cult programming" - DBI::DBD docs |
14
|
|
|
|
|
|
|
$DBD::Cassandra::dr::imp_data_size = 0; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub connect { |
17
|
0
|
|
|
0
|
0
|
|
my ($drh, $dr_dsn, $user, $auth, $attr)= @_; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# Iterate through the DSN, write to $attr |
20
|
0
|
|
|
|
|
|
my $driver_prefix= 'cass_'; |
21
|
0
|
|
|
|
|
|
for my $var (split /;/, $dr_dsn) { |
22
|
0
|
|
|
|
|
|
my ($attr_name, $attr_val)= split '=', $var, 2; |
23
|
0
|
0
|
|
|
|
|
return $drh->set_err($DBI::stderr, "Can't parse DSN part '$var'") |
24
|
|
|
|
|
|
|
unless defined $attr_val; |
25
|
|
|
|
|
|
|
|
26
|
0
|
0
|
|
|
|
|
$attr_name= "cass_$attr_name" unless $attr_name =~ /\A$driver_prefix/o; |
27
|
|
|
|
|
|
|
|
28
|
0
|
|
|
|
|
|
$attr->{$attr_name}= $attr_val; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
0
|
|
0
|
|
|
|
my $keyspace= delete $attr->{cass_database} || delete $attr->{cass_db} || delete $attr->{cass_keyspace}; |
32
|
0
|
|
0
|
|
|
|
my $host= delete $attr->{cass_host} || delete $attr->{cass_hostname} || delete $attr->{cass_hosts} || delete $attr->{cass_hostnames} || 'localhost'; |
33
|
0
|
|
|
|
|
|
my $hosts= [ grep $_, split /,/, $host ]; |
34
|
0
|
|
0
|
|
|
|
my $port= delete $attr->{cass_port} || 9042; |
35
|
0
|
|
|
|
|
|
my $global_consistency= delete $attr->{cass_consistency}; |
36
|
0
|
|
|
|
|
|
my $compression= delete $attr->{cass_compression}; |
37
|
0
|
|
|
|
|
|
my $cql_version= delete $attr->{cass_cql_version}; |
38
|
0
|
|
|
|
|
|
my $read_timeout= delete $attr->{cass_read_timeout}; |
39
|
0
|
|
|
|
|
|
my $write_timeout= delete $attr->{cass_write_timeout}; |
40
|
0
|
|
|
|
|
|
my $connect_timeout= delete $attr->{cass_connect_timeout}; #XXX |
41
|
0
|
|
|
|
|
|
my $request_timeout= delete $attr->{cass_request_timeout}; |
42
|
0
|
|
|
|
|
|
my $tls= delete $attr->{cass_tls}; |
43
|
0
|
0
|
0
|
|
|
|
if ($read_timeout || $write_timeout) { |
44
|
0
|
0
|
|
|
|
|
if ($request_timeout) { |
45
|
0
|
|
|
|
|
|
warn 'Ignoring read_timeout and write_timeout settings, as request_timeout is passed'; |
46
|
|
|
|
|
|
|
} else { |
47
|
0
|
|
0
|
|
|
|
$request_timeout= ($read_timeout || 6) + ($write_timeout || 6); |
|
|
|
0
|
|
|
|
|
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
|
my $client= Cassandra::Client->new( |
52
|
|
|
|
|
|
|
contact_points => $hosts, |
53
|
|
|
|
|
|
|
port => $port, |
54
|
|
|
|
|
|
|
username => $user, |
55
|
|
|
|
|
|
|
password => $auth, |
56
|
|
|
|
|
|
|
keyspace => $keyspace, |
57
|
|
|
|
|
|
|
compression => $compression, |
58
|
|
|
|
|
|
|
default_consistency => $global_consistency, |
59
|
|
|
|
|
|
|
cql_version => $cql_version, |
60
|
|
|
|
|
|
|
request_timeout => $request_timeout, |
61
|
|
|
|
|
|
|
anyevent => 0, |
62
|
|
|
|
|
|
|
tls => $tls, |
63
|
|
|
|
|
|
|
); |
64
|
0
|
|
|
|
|
|
my ($error)= $client->call_connect; |
65
|
0
|
0
|
|
|
|
|
return $drh->set_err($DBI::stderr, "Can't connect to $dr_dsn: $error") if $error; |
66
|
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
|
my ($outer, $dbh)= DBI::_new_dbh($drh, { Name => $dr_dsn }); |
68
|
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
|
$dbh->STORE('Active', 1); |
70
|
0
|
|
|
|
|
|
$dbh->{cass_client}= $client; |
71
|
|
|
|
|
|
|
|
72
|
0
|
|
|
|
|
|
return $outer; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub data_sources { |
76
|
0
|
|
|
0
|
0
|
|
my ($drh, $attr)= @_; |
77
|
0
|
|
|
|
|
|
my @array= (qw/dbi:Cassandra/); |
78
|
0
|
|
|
|
|
|
return @array; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
0
|
0
|
|
sub disconnect_all { |
82
|
|
|
|
|
|
|
# TODO: not needed? |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
1; |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
__END__ |