From: Rob Kinyon Date: Mon, 28 Dec 2009 01:10:57 +0000 (-0500) Subject: Fixed how classname is stored X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=dbsrgits%2FDBM-Deep.git;a=commitdiff_plain;h=1f1f7e243d8ac1a2bcc84aa838b29bb9fbb110b0 Fixed how classname is stored --- diff --git a/etc/mysql_tables.sql b/etc/mysql_tables.sql index b6d8dc0..840b0b8 100644 --- a/etc/mysql_tables.sql +++ b/etc/mysql_tables.sql @@ -5,6 +5,7 @@ CREATE TABLE refs ( id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,ref_type ENUM( 'H', 'A' ) NOT NULL DEFAULT 'H' ,refcount BIGINT UNSIGNED NOT NULL DEFAULT 1 + ,classname LONGTEXT ); CREATE TABLE datas ( @@ -13,7 +14,6 @@ CREATE TABLE datas ( ,data_type ENUM( 'S', 'R' ) DEFAULT 'S' ,`key` LONGTEXT NOT NULL ,value LONGTEXT - ,class LONGTEXT ,FOREIGN KEY (ref_id) REFERENCES refs (id) ON DELETE CASCADE ON UPDATE CASCADE ,UNIQUE INDEX (ref_id, `key` (900) ) diff --git a/lib/DBM/Deep/Engine/DBI.pm b/lib/DBM/Deep/Engine/DBI.pm index 34b1ca2..6d7a533 100644 --- a/lib/DBM/Deep/Engine/DBI.pm +++ b/lib/DBM/Deep/Engine/DBI.pm @@ -101,7 +101,10 @@ sub get_classname { my $self = shift; my ($obj) = @_; - return; + my $sector = $self->load_sector( $obj->_base_offset, 'refs' ) + or return; + + return $sector->get_classname; } sub make_reference { diff --git a/lib/DBM/Deep/Sector/DBI/Reference.pm b/lib/DBM/Deep/Sector/DBI/Reference.pm index 7775ce8..761f268 100644 --- a/lib/DBM/Deep/Sector/DBI/Reference.pm +++ b/lib/DBM/Deep/Sector/DBI/Reference.pm @@ -15,9 +15,11 @@ sub _init { my $e = $self->engine; unless ( $self->offset ) { + my $classname = Scalar::Util::blessed( delete $self->{data} ); $self->{offset} = $self->engine->storage->write_to( refs => undef, - ref_type => $self->type, + ref_type => $self->type, + classname => $classname, ); } else { @@ -61,7 +63,6 @@ sub write_data { data_type => 'S', key => $args->{key}, value => $args->{value}{data}, - class => $args->{value}{class}, ); $args->{value}->reload; @@ -74,7 +75,6 @@ sub write_data { data_type => 'R', key => $args->{key}, value => $args->{value}{offset}, - class => $args->{value}{class}, ); } } @@ -98,7 +98,12 @@ sub delete_key { sub get_classname { my $self = shift; - return; + my ($rows) = $self->engine->storage->read_from( + 'refs', $self->offset, + qw( classname ), + ); + return unless @$rows; + return $rows->[0]{classname}; } sub data { diff --git a/lib/DBM/Deep/Sector/DBI/Scalar.pm b/lib/DBM/Deep/Sector/DBI/Scalar.pm index ba22e5b..4d5d41b 100644 --- a/lib/DBM/Deep/Sector/DBI/Scalar.pm +++ b/lib/DBM/Deep/Sector/DBI/Scalar.pm @@ -13,10 +13,10 @@ sub _init { if ( $self->offset ) { my ($rows) = $self->engine->storage->read_from( datas => $self->offset, - qw( id data_type key value class ), + qw( id data_type key value ), ); - $self->{$_} = $rows->[0]{$_} for qw( data_type key value class ); + $self->{$_} = $rows->[0]{$_} for qw( data_type key value ); } return;