Skip to content

Commit 9cacc99

Browse files
committed
Add Cassandra support via DBD::Cassandra
1 parent 9566d97 commit 9cacc99

9 files changed

Lines changed: 227 additions & 17 deletions

File tree

Build.PL

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,23 @@ use Module::Build;
33
# See perldoc Module::Build for details of how this works
44

55
Module::Build->new(
6-
module_name => 'Apache::Session::Browseable',
7-
license => 'perl',
8-
requires => { 'Apache::Session' => 0, 'JSON' => 0, },
9-
recommends => { 'DBI' => 0, 'Net::LDAP' => 0.38, },
10-
test_requires => { DBI => 0, 'DBD::SQLite' => 0, },
11-
dist_version => '1.3.10',
12-
autosplit => [qw(lib/Apache/Session/Browseable/_common.pm)],
6+
module_name => 'Apache::Session::Browseable',
7+
license => 'perl',
8+
requires => { 'Apache::Session' => 0, 'JSON' => 0, },
9+
recommends => {
10+
'DBI' => 0,
11+
'Net::LDAP' => 0.38,
12+
'DBD::Cassandra' => 0,
13+
'Redis' => 0,
14+
},
15+
test_requires => { DBI => 0, 'DBD::SQLite' => 0, },
16+
dist_version => '1.3.12',
17+
autosplit => [qw(lib/Apache/Session/Browseable/_common.pm)],
1318
configure_requires => { 'Module::Build' => 0, },
14-
meta_merge => {
19+
meta_merge => {
1520
resources => {
16-
repository => 'https://github.com/LemonLDAPNG/Apache-Session-Browseable'
21+
repository =>
22+
'https://github.com/LemonLDAPNG/Apache-Session-Browseable'
1723
}
1824
},
1925
)->create_build_script;

Changes

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
Revision history for Perl extension Apache::Session::Browseable.
22

3+
1.3.12
4+
- Add Cassandra support via DBD::Cassandra
5+
6+
1.3.11
7+
- Revert 1.3.10 changes
8+
39
1.3.10
410
- Add quote for fields in INSERT query
511

LICENSE

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -285,21 +285,21 @@ Definitions:
285285

286286
- "Package" refers to the collection of files distributed by the Copyright
287287
Holder, and derivatives of that collection of files created through textual
288-
modification.
288+
modification.
289289
- "Standard Version" refers to such a Package if it has not been modified,
290290
or has been modified in accordance with the wishes of the Copyright
291-
Holder.
291+
Holder.
292292
- "Copyright Holder" is whoever is named in the copyright or copyrights for
293-
the package.
293+
the package.
294294
- "You" is you, if you're thinking about copying or distributing this Package.
295295
- "Reasonable copying fee" is whatever you can justify on the basis of
296296
media cost, duplication charges, time of people involved, and so on. (You
297297
will not be required to justify it to the Copyright Holder, but only to the
298-
computing community at large as a market that must bear the fee.)
298+
computing community at large as a market that must bear the fee.)
299299
- "Freely Available" means that no fee is charged for the item itself, though
300300
there may be fees involved in handling the item. It also means that
301301
recipients of the item may redistribute it under the same conditions they
302-
received it.
302+
received it.
303303

304304
1. You may make and give away verbatim copies of the source form of the
305305
Standard Version of this Package without restriction, provided that you duplicate

MANIFEST

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
.travis.yml
21
Build.PL
32
Changes
43
COPYRIGHT
54
lib/Apache/Session/Browseable.pm
65
lib/Apache/Session/Browseable/_common.pm
6+
lib/Apache/Session/Browseable/Cassandra.pm
77
lib/Apache/Session/Browseable/DBI.pm
88
lib/Apache/Session/Browseable/File.pm
99
lib/Apache/Session/Browseable/Informix.pm
@@ -16,6 +16,7 @@ lib/Apache/Session/Browseable/PgJSON.pm
1616
lib/Apache/Session/Browseable/Postgres.pm
1717
lib/Apache/Session/Browseable/Redis.pm
1818
lib/Apache/Session/Browseable/SQLite.pm
19+
lib/Apache/Session/Browseable/Store/Cassandra.pm
1920
lib/Apache/Session/Browseable/Store/DBI.pm
2021
lib/Apache/Session/Browseable/Store/File.pm
2122
lib/Apache/Session/Browseable/Store/Informix.pm
@@ -36,6 +37,7 @@ META.json
3637
META.yml Module meta-data (added by MakeMaker)
3738
README.md
3839
rpm/Apache-Session-Browseable.spec
40+
t/Apache-Session-Browseable-Cassandra.t
3941
t/Apache-Session-Browseable-common.t
4042
t/Apache-Session-Browseable-DBI.t
4143
t/Apache-Session-Browseable-File.t

lib/Apache/Session/Browseable.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package Apache::Session::Browseable;
22

3-
our $VERSION = '1.3.10';
3+
our $VERSION = '1.3.12';
44

55
print STDERR "Use a sub module of Apache::Session::Browseable such as Apache::Session::Browseable::File";
66

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package Apache::Session::Browseable::Cassandra;
2+
3+
use strict;
4+
5+
use Apache::Session;
6+
use Apache::Session::Lock::Null;
7+
use Apache::Session::Browseable::Store::Cassandra;
8+
use Apache::Session::Generate::SHA256;
9+
use Apache::Session::Serialize::JSON;
10+
use Apache::Session::Browseable::DBI;
11+
12+
our $VERSION = '1.3.12';
13+
our @ISA = qw(Apache::Session::Browseable::DBI Apache::Session);
14+
15+
sub populate {
16+
my $self = shift;
17+
18+
$self->{object_store} =
19+
new Apache::Session::Browseable::Store::Cassandra $self;
20+
$self->{lock_manager} = new Apache::Session::Lock::Null $self;
21+
$self->{generate} = \&Apache::Session::Generate::SHA256::generate;
22+
$self->{validate} = \&Apache::Session::Generate::SHA256::validate;
23+
$self->{serialize} = \&Apache::Session::Serialize::JSON::serialize;
24+
$self->{unserialize} = \&Apache::Session::Serialize::JSON::unserialize;
25+
26+
return $self;
27+
}
28+
29+
1;
30+
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
package Apache::Session::Browseable::Store::Cassandra;
2+
3+
use strict;
4+
5+
use Apache::Session::Store::DBI;
6+
use Apache::Session::Browseable::Store::DBI;
7+
use Apache::Session::Browseable::Store::Cassandra;
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+
my $self = shift;
18+
my $session = shift;
19+
20+
return if ( defined $self->{dbh} );
21+
22+
if ( exists $session->{args}->{Handle} ) {
23+
$self->{dbh} = $session->{args}->{Handle};
24+
return;
25+
}
26+
27+
my $datasource = $session->{args}->{DataSource}
28+
|| $DataSource;
29+
my $username = $session->{args}->{UserName}
30+
|| $UserName;
31+
my $password = $session->{args}->{Password}
32+
|| $Password;
33+
34+
$self->{dbh} =
35+
DBI->connect( $datasource, $username, $password, { RaiseError => 1 } )
36+
|| die $DBI::errstr;
37+
38+
#If we open the connection, we close the connection
39+
$self->{disconnect} = 1;
40+
}
41+
42+
sub materialize {
43+
my $self = shift;
44+
my $session = shift;
45+
46+
$self->connection($session);
47+
48+
local $self->{dbh}->{RaiseError} = 1;
49+
local $self->{dbh}->{LongReadLen} =
50+
$session->{args}->{LongReadLen} || 8 * 2**10;
51+
52+
if ( !defined $self->{materialize_sth} ) {
53+
$self->{materialize_sth} = $self->{dbh}->prepare_cached(
54+
qq{
55+
SELECT a_session FROM sessions WHERE id = ? FOR UPDATE}
56+
);
57+
}
58+
59+
$self->{materialize_sth}->bind_param( 1, $session->{data}->{_session_id} );
60+
$self->{materialize_sth}->execute;
61+
62+
my $results = $self->{materialize_sth}->fetchrow_arrayref;
63+
64+
if ( !( defined $results ) ) {
65+
die "Object does not exist in the data store";
66+
}
67+
68+
$self->{materialize_sth}->finish;
69+
70+
$session->{serialized} = $results->[0];
71+
}
72+
73+
sub DESTROY {
74+
my $self = shift;
75+
76+
if ( $self->{disconnect} ) {
77+
$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 <mike.langen@tamedia.ch>, based
150+
on the original for Oracle.
151+
152+
=head1 SEE ALSO
153+
154+
L<Apache::Session>, L<Apache::Session::Store::DBI>
155+
1;
156+

lib/Apache/Session/Browseable/Store/SQLite.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ Apache::Session. Session data is stored in a SQLite database.
124124
125125
=head1 SCHEMA
126126
127-
To use this module, you will need at least these columns in a table
127+
To use this module, you will need at least these columns in a table
128128
called 'sessions', or another name if you supply the TableName parameter.
129129
130130
id char(32) # or however long your session IDs are.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
use Test::More;
2+
3+
plan skip_all => "Optional modules (DBD::Cassandra) not installed"
4+
unless eval {
5+
require DBD::Cassandra;
6+
};
7+
8+
plan tests => 1;
9+
10+
use_ok('Apache::Session::Browseable::Cassandra');

0 commit comments

Comments
 (0)