1 package Bio
::DB
::SeqFeature
::Store
::bdb
;
6 Bio::DB::SeqFeature::Store::bdb - fetch and store objects from a BerkeleyDB
10 This is a partial implementation -- just enough has been implemented so that we can
11 fetch and store objects. It is used as a temporary failsafe store by the GFF3Loader module
16 use base
'Bio::DB::SeqFeature::Store';
17 use Bio
::DB
::GFF
::Util
::Rearrange
'rearrange';
19 use Fcntl
qw(O_RDWR O_CREAT);
20 use File
::Temp
'tempdir';
21 use File
::Path
'rmtree';
24 # object initialization
29 $is_temporary) = rearrange
([['DSN','DIR','DIRECTORY'],
30 ['TMP','TEMP','TEMPORARY']
32 $directory ||= $is_temporary ? File
::Spec
->tmpdir : '.';
33 $directory = tempdir
(__PACKAGE__
.'_XXXXXX',TMPDIR
=>1,CLEANUP
=>1,DIR
=>$directory) if $is_temporary;
34 -d
$directory && -w _
or $self->throw("Can't write into the directory $directory");
35 $self->default_settings;
36 $self->directory($directory);
37 $self->temporary($is_temporary);
40 tie
(%h,'DB_File',$self->path,O_RDWR
|O_CREAT
,0666,$DB_HASH) or $self->throw("Couldn't tie: $!");
51 my $primary_id = $obj->primary_id;
52 $primary_id = $db->{'.next_id'}++ unless defined $primary_id;
53 $db->{$primary_id} = $self->freeze($obj);
54 $obj->primary_id($primary_id);
62 my ($object,$primary_id) = @_;
64 $self->throw("$object is not in database") unless exists $db->{$primary_id};
65 $db->{$primary_id} = $self->freeze($object);
72 my $obj = $self->thaw($db->{$id},$id);
78 my $d = $self->setting('db');
79 $self->setting(db
=>shift) if @_;
85 my $d = $self->setting('directory');
86 $self->setting(directory
=>shift) if @_;
92 my $d = $self->setting('temporary');
93 $self->setting(temporary
=>shift) if @_;
99 return $self->directory .'/' . 'feature.bdb';
106 rmtree
($self->directory,0,1) if $self->temporary;