File Coverage

blib/lib/Apache/Session/Browseable/Store/Cassandra.pm
Criterion Covered Total %
statement 12 40 30.0
branch 0 10 0.0
condition 0 13 0.0
subroutine 4 7 57.1
pod 0 2 0.0
total 16 72 22.2


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         32  
4              
5 1     1   532 use Apache::Session::Store::DBI;
  1         736  
  1         30  
6 1     1   456 use Apache::Session::Browseable::Store::DBI;
  1         3  
  1         30  
7 1     1   7 use Apache::Session::Browseable::Store::Cassandra;
  1         2  
  1         472  
8              
9             our @ISA = qw(Apache::Session::Browseable::Store::DBI);
10             our $VERSION = '1.3.12';
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 char(32) # or however long your session IDs are.
111             a_session lvarchar
112              
113             To create this schema, you can execute this command using the sqlplus program:
114              
115             CREATE TABLE sessions (
116             id char(32) not null primary key,
117             a_session lvarchar
118             );
119              
120             If you use some other command, ensure that there is a unique index on the
121             table's id column.
122              
123             =head1 CONFIGURATION
124              
125             The module must know what datasource, username, and password to use when
126             connecting to the database. These values can be set using the options hash
127             (see Apache::Session documentation). The options are DataSource, UserName,
128             and Password.
129              
130             Example:
131              
132             tie %hash, 'Apache::Session::Cassandra', $id, {
133             DataSource => 'dbi:Cassandra:database',
134             UserName => 'database_user',
135             Password => 'K00l'
136             };
137              
138             Instead, you may pass in an already-opened DBI handle to your database.
139              
140             tie %hash, 'Apache::Session::Cassandra', $id, {
141             Handle => $dbh
142             };
143              
144             The last option is LongReadLen, which specifies the maximum size of the session
145             object. If not supplied, the default maximum size is 8 KB.
146              
147             =head1 AUTHOR
148              
149             This module was written by Mike Langen , based
150             on the original for Oracle.
151              
152             =head1 SEE ALSO
153              
154             L, L
155             1;
156