| 1 | package Apache::Session::Browseable::Store::Cassandra; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | |||||||||||||||||||||
| 5 | 1 | ▶ | use Apache::Session::Store::DBI; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 1 | ▶ | use Apache::Session::Browseable::Store::DBI; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 1 | ▶ | use Apache::Session::Browseable::Store::Cassandra; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | 1 | our @ISA = qw(Apache::Session::Browseable::Store::DBI); | |||||||||||||||||||
| 10 | 1 | our $VERSION = '1.3.13'; | |||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | 1 | our $DataSource = undef; | |||||||||||||||||||
| 13 | 1 | our $UserName = undef; | |||||||||||||||||||
| 14 | 1 | our $Password = undef; | |||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | 0 | ▶ | sub connection { | ||||||||||||||||||
|
Subroutine
connection: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||||||||||||
| 17 | 0 | my $self = shift; | |||||||||||||||||||
| 18 | 0 | my $session = shift; | |||||||||||||||||||
| 19 | |||||||||||||||||||||
| 20 | 0 | ▶ | return if ( defined $self->{dbh} ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 21 | |||||||||||||||||||||
| 22 | 0 | ▶ | if ( exists $session->{args}->{Handle} ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 23 | 0 | $self->{dbh} = $session->{args}->{Handle}; | |||||||||||||||||||
| 24 | 0 | return; | |||||||||||||||||||
| 25 | } | ||||||||||||||||||||
| 26 | |||||||||||||||||||||
| 27 | my $datasource = $session->{args}->{DataSource} | ||||||||||||||||||||
| 28 | 0 | ▶ | || $DataSource; | ||||||||||||||||||
|
Condition0%0/3
$session->{'args'}{'DataSource'} || $Apache::Session::Browseable::Store::Cassandra::DataSource
MC/DC0%0/2
$session->{'args'}{'DataSource'} || $Apache::Session::Browseable::Store::Cassandra::DataSource
$session->{'args'}{'DataSource'}
$Apache::Session::Browseable::Store::Cassandra::DataSource
Truth table0%0/3
A || B
A= $session->{'args'}{'DataSource'}B= $Apache::Session::Browseable::Store::Cassandra::DataSource
| |||||||||||||||||||||
| 29 | my $username = $session->{args}->{UserName} | ||||||||||||||||||||
| 30 | 0 | ▶ | || $UserName; | ||||||||||||||||||
|
Condition0%0/3
$session->{'args'}{'UserName'} || $Apache::Session::Browseable::Store::Cassandra::UserName
MC/DC0%0/2
$session->{'args'}{'UserName'} || $Apache::Session::Browseable::Store::Cassandra::UserName
$session->{'args'}{'UserName'}
$Apache::Session::Browseable::Store::Cassandra::UserName
Truth table0%0/3
A || B
A= $session->{'args'}{'UserName'}B= $Apache::Session::Browseable::Store::Cassandra::UserName
| |||||||||||||||||||||
| 31 | my $password = $session->{args}->{Password} | ||||||||||||||||||||
| 32 | 0 | ▶ | || $Password; | ||||||||||||||||||
|
Condition0%0/3
$session->{'args'}{'Password'} || $Apache::Session::Browseable::Store::Cassandra::Password
MC/DC0%0/2
$session->{'args'}{'Password'} || $Apache::Session::Browseable::Store::Cassandra::Password
$session->{'args'}{'Password'}
$Apache::Session::Browseable::Store::Cassandra::Password
Truth table0%0/3
A || B
A= $session->{'args'}{'Password'}B= $Apache::Session::Browseable::Store::Cassandra::Password
| |||||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | $self->{dbh} = | ||||||||||||||||||||
| 35 | 0 | ▶ | DBI->connect( $datasource, $username, $password, { RaiseError => 1 } ) | ||||||||||||||||||
|
Condition0%0/2
'DBI'->connect($datasource, $username, $password, {'RaiseError', 1}) || die($DBI::errstr)
MC/DC0%0/1
'DBI'->connect($datasource, $username, $password, {'RaiseError', 1}) || die($DBI::errstr)
'DBI'->connect($datasource, $username, $password, {'RaiseError', 1})
Truth table0%0/2
A
A= '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 | 0 | ▶ | sub materialize { | ||||||||||||||||||
|
Subroutine
materialize: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||
| 43 | 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 | ▶ | $session->{args}->{LongReadLen} || 8 * 2**10; | ||||||||||||||||||
|
Condition0%0/2
$session->{'args'}{'LongReadLen'} || 8192
MC/DC0%0/1
$session->{'args'}{'LongReadLen'} || 8192
$session->{'args'}{'LongReadLen'}
Truth table0%0/2
A
A= $session->{'args'}{'LongReadLen'}
| |||||||||||||||||||||
| 51 | |||||||||||||||||||||
| 52 | 0 | ▶ | if ( !defined $self->{materialize_sth} ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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 | ▶ | if ( !( defined $results ) ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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 | 0 | ▶ | sub DESTROY { | ||||||||||||||||||
|
Subroutine
DESTROY: not called CC=2 SCAR=17.9
| |||||||||||||||||||||
| 74 | 0 | my $self = shift; | |||||||||||||||||||
| 75 | |||||||||||||||||||||
| 76 | 0 | ▶ | if ( $self->{disconnect} ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 77 | 0 | $self->{dbh}->disconnect; | |||||||||||||||||||
| 78 | } | ||||||||||||||||||||
| 79 | } | ||||||||||||||||||||
| 80 | |||||||||||||||||||||
| 81 | 1 | 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 SEE ALSO | ||||||||||||||||||||
| 142 | |||||||||||||||||||||
| 143 | L<Apache::Session>, L<Apache::Session::Store::DBI> | ||||||||||||||||||||
| 144 | |||||||||||||||||||||
| 145 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||
| 146 | |||||||||||||||||||||
| 147 | =encoding utf8 | ||||||||||||||||||||
| 148 | |||||||||||||||||||||
| 149 | Copyright (C): | ||||||||||||||||||||
| 150 | |||||||||||||||||||||
| 151 | =over | ||||||||||||||||||||
| 152 | |||||||||||||||||||||
| 153 | =item 2009-2025 by Xavier Guimard | ||||||||||||||||||||
| 154 | |||||||||||||||||||||
| 155 | =item 2013-2025 by Clément Oudot | ||||||||||||||||||||
| 156 | |||||||||||||||||||||
| 157 | =item 2019-2025 by Maxime Besson | ||||||||||||||||||||
| 158 | |||||||||||||||||||||
| 159 | =item 2013-2025 by Worteks | ||||||||||||||||||||
| 160 | |||||||||||||||||||||
| 161 | =item 2023-2025 by Linagora | ||||||||||||||||||||
| 162 | |||||||||||||||||||||
| 163 | =back | ||||||||||||||||||||
| 164 | |||||||||||||||||||||
| 165 | This library is free software; you can redistribute it and/or modify | ||||||||||||||||||||
| 166 | it under the same terms as Perl itself, either Perl version 5.10.1 or, | ||||||||||||||||||||
| 167 | at your option, any later version of Perl 5 you may have available. | ||||||||||||||||||||
| 168 | |||||||||||||||||||||
| 169 | =cut | ||||||||||||||||||||