line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Apache::Session::Browseable::Store::Cassandra; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
7
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
44
|
|
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
516
|
use Apache::Session::Store::DBI; |
|
1
|
|
|
|
|
713
|
|
|
1
|
|
|
|
|
30
|
|
6
|
1
|
|
|
1
|
|
423
|
use Apache::Session::Browseable::Store::DBI; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
30
|
|
7
|
1
|
|
|
1
|
|
7
|
use Apache::Session::Browseable::Store::Cassandra; |
|
1
|
|
|
|
|
12
|
|
|
1
|
|
|
|
|
476
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our @ISA = qw(Apache::Session::Browseable::Store::DBI); |
10
|
|
|
|
|
|
|
our $VERSION = '1.3.13'; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $DataSource = undef; |
13
|
|
|
|
|
|
|
our $UserName = undef; |
14
|
|
|
|
|
|
|
our $Password = undef; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub connection { |
17
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
18
|
0
|
|
|
|
|
|
my $session = shift; |
19
|
|
|
|
|
|
|
|
20
|
0
|
0
|
|
|
|
|
return if ( defined $self->{dbh} ); |
21
|
|
|
|
|
|
|
|
22
|
0
|
0
|
|
|
|
|
if ( exists $session->{args}->{Handle} ) { |
23
|
0
|
|
|
|
|
|
$self->{dbh} = $session->{args}->{Handle}; |
24
|
0
|
|
|
|
|
|
return; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
my $datasource = $session->{args}->{DataSource} |
28
|
0
|
|
0
|
|
|
|
|| $DataSource; |
29
|
|
|
|
|
|
|
my $username = $session->{args}->{UserName} |
30
|
0
|
|
0
|
|
|
|
|| $UserName; |
31
|
|
|
|
|
|
|
my $password = $session->{args}->{Password} |
32
|
0
|
|
0
|
|
|
|
|| $Password; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
$self->{dbh} = |
35
|
0
|
|
0
|
|
|
|
DBI->connect( $datasource, $username, $password, { RaiseError => 1 } ) |
36
|
|
|
|
|
|
|
|| die $DBI::errstr; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
#If we open the connection, we close the connection |
39
|
0
|
|
|
|
|
|
$self->{disconnect} = 1; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub materialize { |
43
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
44
|
0
|
|
|
|
|
|
my $session = shift; |
45
|
|
|
|
|
|
|
|
46
|
0
|
|
|
|
|
|
$self->connection($session); |
47
|
|
|
|
|
|
|
|
48
|
0
|
|
|
|
|
|
local $self->{dbh}->{RaiseError} = 1; |
49
|
|
|
|
|
|
|
local $self->{dbh}->{LongReadLen} = |
50
|
0
|
|
0
|
|
|
|
$session->{args}->{LongReadLen} || 8 * 2**10; |
51
|
|
|
|
|
|
|
|
52
|
0
|
0
|
|
|
|
|
if ( !defined $self->{materialize_sth} ) { |
53
|
|
|
|
|
|
|
$self->{materialize_sth} = $self->{dbh}->prepare_cached( |
54
|
0
|
|
|
|
|
|
qq{ |
55
|
|
|
|
|
|
|
SELECT a_session FROM sessions WHERE id = ? FOR UPDATE} |
56
|
|
|
|
|
|
|
); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
0
|
|
|
|
|
|
$self->{materialize_sth}->bind_param( 1, $session->{data}->{_session_id} ); |
60
|
0
|
|
|
|
|
|
$self->{materialize_sth}->execute; |
61
|
|
|
|
|
|
|
|
62
|
0
|
|
|
|
|
|
my $results = $self->{materialize_sth}->fetchrow_arrayref; |
63
|
|
|
|
|
|
|
|
64
|
0
|
0
|
|
|
|
|
if ( !( defined $results ) ) { |
65
|
0
|
|
|
|
|
|
die "Object does not exist in the data store"; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
0
|
|
|
|
|
|
$self->{materialize_sth}->finish; |
69
|
|
|
|
|
|
|
|
70
|
0
|
|
|
|
|
|
$session->{serialized} = $results->[0]; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub DESTROY { |
74
|
0
|
|
|
0
|
|
|
my $self = shift; |
75
|
|
|
|
|
|
|
|
76
|
0
|
0
|
|
|
|
|
if ( $self->{disconnect} ) { |
77
|
0
|
|
|
|
|
|
$self->{dbh}->disconnect; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
1; |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=pod |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head1 NAME |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
Apache::Session::Browseable::Store::Cassandra - Store persistent data in a Cassandra database |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head1 SYNOPSIS |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
use Apache::Session::Browseable::Store::Cassandra; |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
my $store = new Apache::Session::Browseable::Store::Cassandra; |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
$store->insert($ref); |
96
|
|
|
|
|
|
|
$store->update($ref); |
97
|
|
|
|
|
|
|
$store->materialize($ref); |
98
|
|
|
|
|
|
|
$store->remove($ref); |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head1 DESCRIPTION |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
Apache::Session::Browseable::Store::Cassandra fulfills the storage interface of |
103
|
|
|
|
|
|
|
Apache::Session. Session data is stored in a Cassandra database. |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head1 SCHEMA |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
To use this module, you will need at least these columns in a table |
108
|
|
|
|
|
|
|
called 'sessions': |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
id text |
111
|
|
|
|
|
|
|
a_session text |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
To create this schema, you can execute this command using cqlsh: |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
CREATE TABLE sessions ( |
116
|
|
|
|
|
|
|
id text PRIMARY KEY, |
117
|
|
|
|
|
|
|
a_session text |
118
|
|
|
|
|
|
|
); |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=head1 CONFIGURATION |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
The module must know what datasource, username, and password to use when |
123
|
|
|
|
|
|
|
connecting to the database. These values can be set using the options hash |
124
|
|
|
|
|
|
|
(see Apache::Session documentation). The options are DataSource, UserName, |
125
|
|
|
|
|
|
|
and Password. |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
Example: |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
tie %hash, 'Apache::Session::Cassandra', $id, { |
130
|
|
|
|
|
|
|
DataSource => 'dbi:Cassandra:host=localhost;keyspace=llng', |
131
|
|
|
|
|
|
|
UserName => 'database_user', |
132
|
|
|
|
|
|
|
Password => 'K00l' |
133
|
|
|
|
|
|
|
}; |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
Instead, you may pass in an already-opened DBI handle to your database. |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
tie %hash, 'Apache::Session::Cassandra', $id, { |
138
|
|
|
|
|
|
|
Handle => $dbh |
139
|
|
|
|
|
|
|
}; |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=head1 AUTHOR |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
This module was written by Mike Langen , based |
144
|
|
|
|
|
|
|
on the original for Oracle. |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=head1 SEE ALSO |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
L, L |
149
|
|
|
|
|
|
|
1; |
150
|
|
|
|
|
|
|
|