15 |
package WAIT::Index; |
package WAIT::Index; |
16 |
use WAIT::IndexScan; |
use WAIT::IndexScan; |
17 |
use strict; |
use strict; |
18 |
use DB_File; |
use BerkeleyDB; |
19 |
use Fcntl; |
use Fcntl; |
20 |
use vars qw($VERSION); |
use vars qw($VERSION); |
21 |
|
|
22 |
$VERSION = "1.801"; # Table.pm tests if we are loaded by checking $VERSION |
$VERSION = "2.000"; # Table.pm tests if we are loaded by checking $VERSION |
23 |
|
|
24 |
sub new { |
sub new { |
25 |
my $type = shift; |
my $type = shift; |
26 |
my %parm = @_; |
my %parm = @_; |
27 |
my $self = {}; |
my $self = {}; |
28 |
|
|
29 |
unless ($self->{file} = $parm{file}) { |
for my $x (qw(file attr env subname maindbfile tablename)) { |
30 |
require Carp; |
unless ($self->{$x} = $parm{$x}) { |
31 |
Carp::croak("No file specified"); |
require Carp; |
32 |
|
Carp::croak("No $x specified"); |
33 |
|
} |
34 |
} |
} |
35 |
unless ($self->{attr} = $parm{attr}) { |
bless $self, ref($type) || $type; |
36 |
|
} |
37 |
|
|
38 |
|
for my $accessor (qw(maindbfile tablename subname)) { |
39 |
|
no strict 'refs'; |
40 |
|
*{$accessor} = sub { |
41 |
|
my($self) = @_; |
42 |
|
return $self->{$accessor} if $self->{$accessor}; |
43 |
require Carp; |
require Carp; |
44 |
Carp::croak("No attributes specified"); |
Carp::confess("accessor $accessor not there"); |
45 |
} |
} |
|
bless $self, ref($type) || $type; |
|
46 |
} |
} |
47 |
|
|
48 |
sub drop { |
sub drop { |
63 |
if (exists $self->{dbh}) { |
if (exists $self->{dbh}) { |
64 |
$self->{dbh}; |
$self->{dbh}; |
65 |
} else { |
} else { |
66 |
$self->{dbh} = tie(%{$self->{db}}, 'DB_File', $file, |
my $flags; |
67 |
$self->{mode}, 0664, $DB_BTREE); |
if ($self->{mode} & O_RDWR) { |
68 |
|
$flags = DB_CREATE; # | DB_INIT_MPOOL | DB_INIT_CDB; |
69 |
|
# warn "Flags on index $file set to 'writing'"; |
70 |
|
} else { |
71 |
|
$flags = DB_RDONLY; |
72 |
|
# warn "Flags on index $file set to 'readonly'"; |
73 |
|
} |
74 |
|
$self->{dbh} = tie(%{$self->{db}}, 'BerkeleyDB::Btree', |
75 |
|
# Filename => $file, |
76 |
|
Filename => $self->maindbfile, |
77 |
|
$self->{env} ? (Env => $self->{env}) : (), |
78 |
|
Subname => join("/",$self->tablename,$self->subname), |
79 |
|
Mode => 0664, |
80 |
|
Flags => $flags, |
81 |
|
$WAIT::Database::Cachesize?(Cachesize => $WAIT::Database::Cachesize):(), |
82 |
|
$WAIT::Database::Pagesize?(Pagesize => $WAIT::Database::Pagesize):(), |
83 |
|
) or die $BerkeleyDB::Error; |
84 |
} |
} |
85 |
} |
} |
86 |
|
|
144 |
|
|
145 |
delete $self->{scans} if defined $self->{scans}; |
delete $self->{scans} if defined $self->{scans}; |
146 |
|
|
147 |
|
delete $self->{env}; |
148 |
if ($self->{dbh}) { |
if ($self->{dbh}) { |
149 |
delete $self->{dbh}; |
delete $self->{dbh}; |
150 |
untie %{$self->{db}}; |
untie %{$self->{db}}; |
151 |
delete $self->{db}; |
for my $att (qw(db file maindbfile)) { |
152 |
|
delete $self->{$att}; |
153 |
|
} |
154 |
} |
} |
155 |
} |
} |
156 |
|
|