/[wait]/trunk/lib/WAIT/Database.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/lib/WAIT/Database.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 111 by dpavlin, Tue Jul 13 19:05:31 2004 UTC revision 112 by dpavlin, Tue Jul 13 19:50:13 2004 UTC
# Line 98  sub create { Line 98  sub create {
98    $self->{dir}       = $dir;    $self->{dir}       = $dir;
99    $self->{name}      = $name;    $self->{name}      = $name;
100    
   print STDERR "## dir: $dir name: $name\n";  
   
101    my $env = BerkeleyDB::Env->new(    my $env = BerkeleyDB::Env->new(
102                                  -Home => $self->path,                                  -Home => $self->path,
103                                  -Flags => DB_CREATE|DB_INIT_MPOOL|DB_INIT_CDB|DB_PRIVATE,                                  -Flags => DB_CREATE|DB_INIT_MPOOL|DB_INIT_CDB|DB_PRIVATE,
# Line 128  sub create { Line 126  sub create {
126                                            $WAIT::Database::Pagesize?(Pagesize => $WAIT::Database::Pagesize):(),                                            $WAIT::Database::Pagesize?(Pagesize => $WAIT::Database::Pagesize):(),
127                                           );                                           );
128    
 print STDERR "### created ",$self->maindbfile,"\n";  
   
129    unless (defined($self->{_attr})) {    unless (defined($self->{_attr})) {
130      die("Cannot open [".$self->maindbfile."] _attr: $BerkeleyDB::Error");      die("Cannot open [".$self->maindbfile."] _attr: $BerkeleyDB::Error");
131    }    }
# Line 172  sub open { Line 168  sub open {
168    
169    my $env;    my $env;
170    
171      return if (! -d $self->path);
172    
173    if ($mode & O_RDWR) {    if ($mode & O_RDWR) {
174      my $flags = DB_CREATE|DB_INIT_MPOOL|DB_INIT_CDB;      my $flags = DB_CREATE|DB_INIT_MPOOL|DB_INIT_CDB;
175      #warn "setting flags for envorinment 'writing'";      #warn "setting flags for envorinment 'writing'";
# Line 191  sub open { Line 189  sub open {
189      $env = "";      $env = "";
190    }    }
191    
192    warn "DEBUG: trying to open the database for _attr";    #warn "DEBUG: trying to open the database for _attr";
193    my $maindbfile = $self->maindbfile;    my $maindbfile = $self->maindbfile;
194    my $attr = BerkeleyDB::Btree->new(    my $attr = BerkeleyDB::Btree->new(
195                                      -Filename => $maindbfile,                                      -Filename => $maindbfile,
# Line 253  Close a database saving all meta data af Line 251  Close a database saving all meta data af
251  =cut  =cut
252    
253  sub close {  sub close {
254    my $self = shift;    # my $self = shift would increase refcount!
255      my $self = $_[0];
256        
257    for my $table (values %{$self->{tables}}) {    for my $table (values %{$self->{tables}}) {
258      $table->close if ref($table);      $table->close if ref($table);
# Line 272  sub close { Line 271  sub close {
271    my $dat = nfreeze $self;    my $dat = nfreeze $self;
272    $db->db_put(0, $dat);    $db->db_put(0, $dat);
273    
274      undef $db;
275    
276    #warn "DEBUG: Removing env[$env] before closing database";    #warn "DEBUG: Removing env[$env] before closing database";
277    undef $env;    undef $env;
278    #warn "DEBUG: Removed it.";    #warn "DEBUG: Removed it.";
# Line 294  by a false return value. Line 295  by a false return value.
295  =cut  =cut
296    
297  sub dispose {  sub dispose {
298    my $self = shift;    # my $self = shift would increase refcount!
299    
300    my $path;    my $path;
301    
302    if ($self && ref $self) {               # called with instance    if (ref $_[0]) {               # called with instance
303      croak "no mode" unless defined($self->{mode});      croak "no mode" unless defined($_[0]->{mode});
304      croak "Database readonly" unless $self->{mode} & (O_CREAT | O_RDWR);      croak "Database readonly" unless $_[0]->{mode} & (O_CREAT | O_RDWR);
305      $path = $self->path;      $path = $_[0]->path;
306      $self->close;      $_[0]->close;
307    } else {    } else {
308        shift;
309      my %parm = @_;      my %parm = @_;
310      my $base = $parm{directory} || '.';      my $base = $parm{directory} || '.';
311      my $name = $parm{name}      || croak "No name specified";      my $name = $parm{name}      || croak "No name specified";
# Line 311  sub dispose { Line 313  sub dispose {
313    }    }
314    croak "No such database '$path'" unless -e "$path";    croak "No such database '$path'" unless -e "$path";
315    
316      #warn "DEBUG: removing $path";
317    my $ret = rmtree($path, 0, 1);    my $ret = rmtree($path, 0, 1);
318    
319    return $ret;    return $ret;

Legend:
Removed from v.111  
changed lines
  Added in v.112

  ViewVC Help
Powered by ViewVC 1.1.26