From: <chr...@us...> - 2006-06-14 22:51:34
|
Revision: 891 Author: chromatic Date: 2006-06-14 15:51:20 -0700 (Wed, 14 Jun 2006) ViewCVS: http://svn.sourceforge.net/everydevel/?rev=891&view=rev Log Message: ----------- r17847@windwheel: chromatic | 2006-06-14 15:51:03 -0700 Moved more database-related methods around to get SQLite working. Added basic tests for Everything::DB. They don't run yet, but they will. Modified Paths: -------------- trunk/ebase/MANIFEST trunk/ebase/lib/Everything/DB.pm trunk/ebase/lib/Everything/Node/nodetype.pm trunk/ebase/lib/Everything/Node.pm trunk/ebase/lib/Everything/NodeBase.pm trunk/ebase/lib/Everything/Test/NodeBase.pm Added Paths: ----------- trunk/ebase/lib/Everything/Test/DB.pm Property Changed: ---------------- trunk/ebase/ Property changes on: trunk/ebase ___________________________________________________________________ Name: svk:merge - a6810612-c0f9-0310-9d3e-a9e4af8c5745:/ebase/offline:17845 + a6810612-c0f9-0310-9d3e-a9e4af8c5745:/ebase/offline:17847 Modified: trunk/ebase/MANIFEST =================================================================== --- trunk/ebase/MANIFEST 2006-06-14 22:21:11 UTC (rev 890) +++ trunk/ebase/MANIFEST 2006-06-14 22:51:20 UTC (rev 891) @@ -124,6 +124,7 @@ lib/Everything/NodeBase/Workspace.pm lib/Everything/NodeCache.pm lib/Everything/Security.pm +lib/Everything/Test/DB.pm lib/Everything/Test/NodeBase.pm lib/Everything/Test/NodeBase/Workspace.pm lib/Everything/Util.pm Modified: trunk/ebase/lib/Everything/DB.pm =================================================================== --- trunk/ebase/lib/Everything/DB.pm 2006-06-14 22:21:11 UTC (rev 890) +++ trunk/ebase/lib/Everything/DB.pm 2006-06-14 22:51:20 UTC (rev 891) @@ -13,10 +13,12 @@ use warnings; use DBI; +use Scalar::Util 'weaken'; sub new { my ($class, %args) = @_; + weaken( $args{nb} ); bless \%args, $class; } @@ -520,7 +522,7 @@ return unless ($TYPE); - $this->getRef($TYPE); + $this->{nb}->getRef($TYPE); $NODE = $this->{cache}->getCachedNodeByName( $node, $$TYPE{title} ); return $NODE if ( defined $NODE ); @@ -862,6 +864,57 @@ return @allTypes; } +=head2 C<getNodetypeTables> + +Returns an array of all the tables that a given nodetype joins on. +This will create the array, if it has not already created it. + +=over 4 + +=item * TYPE + +The string name or integer Id of the nodetype + +=item * addnode + +if true, add 'node' to list. Defaults to false. + +=back + +Returns a reference to an array that contains the names of the tables to join +on. If the nodetype does not join on any tables, the array is empty. + +=cut + +sub getNodetypeTables +{ + my ( $this, $TYPE, $addNode ) = @_; + my @tablelist; + + return unless $TYPE; + + # We need to short circuit on nodetype and nodemethod, otherwise we + # get inf recursion. + if ( ( $TYPE eq '1' ) or ( ( ref $TYPE ) && ( $TYPE->{node_id} == 1 ) ) ) + { + push @tablelist, 'nodetype'; + } + elsif ( ref $TYPE && $TYPE->{title} eq 'nodemethod' ) + { + push @tablelist, 'nodemethod'; + } + else + { + $this->{nb}->getRef($TYPE); + my $tables = $TYPE->getTableArray(); + push @tablelist, @$tables if $tables; + } + + push @tablelist, 'node' if $addNode; + + return \@tablelist; +} + =head2 C<dropNodeTable> Drop (delete) a table from the database. Note!!! This is permanent! You will Modified: trunk/ebase/lib/Everything/Node/nodetype.pm =================================================================== --- trunk/ebase/lib/Everything/Node/nodetype.pm 2006-06-14 22:21:11 UTC (rev 890) +++ trunk/ebase/lib/Everything/Node/nodetype.pm 2006-06-14 22:51:20 UTC (rev 891) @@ -109,6 +109,7 @@ Everything::logErrors("Missing '$field'") unless defined $this->{$field}; + $PARENT->{$field} ||= ''; if ( $this->{$field} eq '-1' ) { $this->{$field} = $PARENT->{$field}; Modified: trunk/ebase/lib/Everything/Node.pm =================================================================== --- trunk/ebase/lib/Everything/Node.pm 2006-06-14 22:21:11 UTC (rev 890) +++ trunk/ebase/lib/Everything/Node.pm 2006-06-14 22:51:20 UTC (rev 891) @@ -296,7 +296,6 @@ =cut - =head2 C<assignType> This is an "private" function that should never be needed to be called from @@ -317,6 +316,8 @@ { $$this{type} = $$this{DB}->getType( $$this{type_nodetype} ); } + + bless $this, 'Everything::Node::'. $this->{type}->{title}; } =cut Modified: trunk/ebase/lib/Everything/NodeBase.pm =================================================================== --- trunk/ebase/lib/Everything/NodeBase.pm 2006-06-14 22:21:11 UTC (rev 890) +++ trunk/ebase/lib/Everything/NodeBase.pm 2006-06-14 22:51:20 UTC (rev 891) @@ -84,7 +84,10 @@ $this->{staticNodetypes} = $staticNodetypes ? 1 : 0; my $storage_class = 'Everything::DB::' . $storage; - $this->{storage} = $storage_class->new( cache => $this->{cache} ); + $this->{storage} = $storage_class->new( + nb => $this, + cache => $this->{cache} + ); $this->{storage}->databaseConnect( $dbname, $host, $user, $pass ); $this->{nodetypeModules} = $this->buildNodetypeModules(); @@ -524,57 +527,6 @@ These methods are private. Don't call them. They won't call you. -=head2 C<getNodetypeTables> - -Returns an array of all the tables that a given nodetype joins on. -This will create the array, if it has not already created it. - -=over 4 - -=item * TYPE - -The string name or integer Id of the nodetype - -=item * addnode - -if true, add 'node' to list. Defaults to false. - -=back - -Returns a reference to an array that contains the names of the tables to join -on. If the nodetype does not join on any tables, the array is empty. - -=cut - -sub getNodetypeTables -{ - my ( $this, $TYPE, $addNode ) = @_; - my @tablelist; - - return unless $TYPE; - - # We need to short circuit on nodetype and nodemethod, otherwise we - # get inf recursion. - if ( ( $TYPE eq '1' ) or ( ( ref $TYPE ) && ( $TYPE->{node_id} == 1 ) ) ) - { - push @tablelist, 'nodetype'; - } - elsif ( ref $TYPE && $TYPE->{title} eq 'nodemethod' ) - { - push @tablelist, 'nodemethod'; - } - else - { - $this->getRef($TYPE); - my $tables = $TYPE->getTableArray(); - push @tablelist, @$tables if $tables; - } - - push @tablelist, 'node' if $addNode; - - return \@tablelist; -} - =head2 C<getRef> This makes sure that we have an array of node hashes, not node ids. Added: trunk/ebase/lib/Everything/Test/DB.pm =================================================================== --- trunk/ebase/lib/Everything/Test/DB.pm (rev 0) +++ trunk/ebase/lib/Everything/Test/DB.pm 2006-06-14 22:51:20 UTC (rev 891) @@ -0,0 +1,31 @@ +sub test_get_nodetype_tables :Test( 7 ) +{ + my $self = shift; + my $nb = $self->{nb}; + my $storage = $self->{storage}; + + ok( ! $nb->getNodetypeTables(), + 'getNodetypeTables() should return false without type' ); + + is_deeply( $nb->getNodetypeTables( 1 ), [ 'nodetype' ], + '... and should return nodetype given nodetype id' ); + + is_deeply( $nb->getNodetypeTables( { node_id => 1 } ), [ 'nodetype' ], + '... or nodetype node' ); + + is_deeply( $nb->getNodetypeTables( { title => 'nodemethod', node_id => 0 }), + [ 'nodemethod' ], + '... or should return nodemethod if given nodemethod node' ); + + $nb->mock( getRef => sub { $_[1] = $storage } ); + $storage->set_series( getTableArray => [qw( foo bar )] ); + + is_deeply( $nb->getNodetypeTables( 'bar' ), [qw( foo bar )], + '... or calling getTableArray() on promoted node' ); + + is_deeply( $nb->getNodetypeTables( 'baz' ), [], + '... returning nothing if there are no nodetype tables' ); + + is_deeply( $nb->getNodetypeTables( 'flaz', 1 ), [ 'node' ], + '... but adding node if addNode flag is true' ); +} Property changes on: trunk/ebase/lib/Everything/Test/DB.pm ___________________________________________________________________ Name: svn:mime-type + text/plain; charset=UTF-8 Name: svn:eol-style + native Modified: trunk/ebase/lib/Everything/Test/NodeBase.pm =================================================================== --- trunk/ebase/lib/Everything/Test/NodeBase.pm 2006-06-14 22:21:11 UTC (rev 890) +++ trunk/ebase/lib/Everything/Test/NodeBase.pm 2006-06-14 22:51:20 UTC (rev 891) @@ -350,6 +350,8 @@ is( join( '-', @$args ), "$nb-table-0", '... passing table name' ); } +=cut + sub test_get_nodetype_tables :Test( 7 ) { my $self = shift; @@ -382,6 +384,8 @@ '... but adding node if addNode flag is true' ); } +=cut + sub test_get_ref :Test( 5 ) { my $self = shift; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |