| RDF-Query documentation | Contained in the RDF-Query distribution. |
RDF::Query::Plan::NamedGraph - Executable query plan for named graphs.
This document describes RDF::Query::Plan::NamedGraph version 2.907.
Beyond the methods documented below, this class inherits methods from the RDF::Query::Plan class.
new ( $graph, $plan )execute ( $execution_context )nextclosegraphReturns the graph variable.
patternReturns the query plan that will be used with each named graph in the model.
distinctReturns true if the pattern is guaranteed to return distinct results.
orderedReturns true if the pattern is guaranteed to return ordered results.
plan_node_nameReturns the string name of this plan node, suitable for use in serialization.
plan_prototypeReturns a list of scalar identifiers for the type of the content (children) nodes of this plan node. See RDF::Query::Plan for a list of the allowable identifiers.
plan_node_dataReturns the data for this plan node that corresponds to the values described by
the signature returned by plan_prototype.
Gregory Todd Williams <gwilliams@cpan.org>
| RDF-Query documentation | Contained in the RDF-Query distribution. |
# RDF::Query::Plan::NamedGraph # -----------------------------------------------------------------------------
package RDF::Query::Plan::NamedGraph; use strict; use warnings; use Scalar::Util qw(blessed); use base qw(RDF::Query::Plan); ###################################################################### our ($VERSION); BEGIN { $VERSION = '2.907'; } ######################################################################
sub new { my $class = shift; my $graph = shift; my $plan = shift; my $self = $class->SUPER::new( $graph, $plan ); $self->[0]{referenced_variables} = [ $plan->referenced_variables ]; my $l = Log::Log4perl->get_logger("rdf.query.plan.namedgraph"); $l->trace('constructing named graph plan...'); return $self; }
sub execute ($) { my $self = shift; my $context = shift; if ($self->state == $self->OPEN) { throw RDF::Query::Error::ExecutionError -text => "NamedGraph plan can't be executed while already open"; } my $l = Log::Log4perl->get_logger("rdf.query.plan.namedgraph"); $l->trace('executing named graph plan'); my $model = $context->model; my $graphs = $model->get_contexts; $self->[0]{graphs} = $graphs; $self->[0]{bound} = $context->bound || {}; $self->[0]{context} = $context; if (my $g = $self->[0]{graphs}->next) { my %bound = %{ $self->[0]{bound} }; $bound{ $self->graph->name } = $g; my $ctx = $context->copy( bound => \%bound ); my $plan = $self->pattern; $l->trace("Executing named graph pattern with graph " . $g->as_string . ": " . $plan->sse); $plan->execute( $ctx ); $self->[0]{current_graph} = $g; } $self->state( $self->OPEN ); $self; }
sub next { my $self = shift; unless ($self->state == $self->OPEN) { throw RDF::Query::Error::ExecutionError -text => "next() cannot be called on an un-open NAMED GRAPH"; } my $context = $self->[0]{context}; my $l = Log::Log4perl->get_logger("rdf.query.plan.namedgraph"); while (1) { unless ($self->[0]{current_graph}) { return; } my $row = $self->pattern->next; if ($row) { my $g = $self->[0]{current_graph}; if (my $rg = $row->{ $self->graph->name }) { unless ($rg->equal( $g )) { next; } } $row->{ $self->graph->name } = $g; return $row; } else { my $g = $self->[0]{graphs}->next; unless (blessed($g)) { return; } my %bound = %{ $self->[0]{bound} }; $bound{ $self->graph->name } = $g; my $ctx = $self->[0]{context}->copy( bound => \%bound ); my $plan = $self->pattern; if ($plan->state == $plan->OPEN) { $plan->close(); } $l->trace("Executing named graph pattern with graph " . $g->as_string); $plan->execute( $ctx ); $self->[0]{current_graph} = $g; } } }
sub close { my $self = shift; unless ($self->state == $self->OPEN) { throw RDF::Query::Error::ExecutionError -text => "close() cannot be called on an un-open NAMED GRAPH"; } delete $self->[0]{current_graph}; my $plan = $self->pattern; if ($plan->state == $plan->OPEN) { $plan->close(); } $self->SUPER::close(); }
sub graph { my $self = shift; return $self->[1]; }
sub pattern { my $self = shift; return $self->[2]; }
sub distinct { my $self = shift; return $self->pattern->distinct; }
sub ordered { my $self = shift; return []; }
sub plan_node_name { return 'named-graph'; }
sub plan_prototype { my $self = shift; return qw(N P); }
sub plan_node_data { my $self = shift; return ($self->graph, $self->pattern); } 1; __END__