Semantic MediaWiki and related extensions
Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
SMW\SPARQLStore\RepositoryConnectors\GenericRepositoryConnector Class Reference
Inheritance diagram for SMW\SPARQLStore\RepositoryConnectors\GenericRepositoryConnector:
Inheritance graph
[legend]
Collaboration diagram for SMW\SPARQLStore\RepositoryConnectors\GenericRepositoryConnector:
Collaboration graph
[legend]

Public Member Functions

 __construct (RepositoryClient $repositoryClient, HttpRequest $httpRequest)
 
 getRepositoryClient ()
 
 getEndpoint ( $type)
 
 getLastErrorCode ()
 
 getDefaultGraph ()
 
 setConnectionTimeout ( $timeout=10)
 
 shouldPing ()
 
 ping ( $endpointType=self::ENDP_QUERY)
 
 select ( $vars, $where, $options=[], $extraNamespaces=[])
 
 getSparqlForSelect ( $vars, $where, $options=[], $extraNamespaces=[])
 
 ask ( $where, $extraNamespaces=[])
 
 getSparqlForAsk ( $where, $extraNamespaces=[])
 
 selectCount ( $variable, $where, $options=[], $extraNamespaces=[])
 
 delete ( $deletePattern, $where, $extraNamespaces=[])
 
 deleteContentByValue ( $propertyName, $objectName, $extraNamespaces=[])
 
 deleteAll ()
 
 insertDelete ( $insertPattern, $deletePattern, $where, $extraNamespaces=[])
 
 insertData ( $triples, $extraNamespaces=[])
 
 deleteData ( $triples, $extraNamespaces=[])
 
 doQuery ( $sparql)
 
 doUpdate ( $sparql)
 
 doHttpPost ( $payload)
 
 getVersion ()
 

Static Public Member Functions

static getPrefixString ( $extraNamespaces=[], $forSparql=true)
 

Public Attributes

const ENDP_QUERY = RepositoryConnection::QUERY_ENDPOINT
 
const ENDP_UPDATE = RepositoryConnection::UPDATE_ENDPOINT
 
const ENDP_DATA = RepositoryConnection::DATA_ENDPOINT
 
- Public Attributes inherited from SMW\SPARQLStore\RepositoryConnection
const QUERY_ENDPOINT = 1
 
const UPDATE_ENDPOINT = 2
 
const DATA_ENDPOINT = 4
 

Protected Member Functions

 mapHttpRequestError ( $endpoint, $sparql)
 

Protected Attributes

 $repositoryClient
 
 $httpRequest
 

Detailed Description

Basic database connector for exchanging data via SPARQL.

GNU GPL v2+

Since
1.6
Author
Markus Krötzsch

Constructor & Destructor Documentation

◆ __construct()

SMW\SPARQLStore\RepositoryConnectors\GenericRepositoryConnector::__construct ( RepositoryClient  $repositoryClient,
HttpRequest  $httpRequest 
)
Note
It is suggested to use the RepositoryConnectionProvider to create a valid instance
Since
2.2
Parameters
RepositoryClient$repositoryClient
HttpRequest$httpRequest

Member Function Documentation

◆ ask()

SMW\SPARQLStore\RepositoryConnectors\GenericRepositoryConnector::ask (   $where,
  $extraNamespaces = [] 
)

ASK wrapper. The function declares the standard namespaces wiki, swivt, rdf, owl, rdfs, property, xsd, so these do not have to be included in $extraNamespaces.

Parameters
$wherestring WHERE part of the query, without surrounding { }
$extraNamespacesarray (associative) of namespaceId => namespaceUri
Returns
RepositoryResult

Implements SMW\SPARQLStore\RepositoryConnection.

◆ delete()

SMW\SPARQLStore\RepositoryConnectors\GenericRepositoryConnector::delete (   $deletePattern,
  $where,
  $extraNamespaces = [] 
)

DELETE wrapper. The function declares the standard namespaces wiki, swivt, rdf, owl, rdfs, property, xsd, so these do not have to be included in $extraNamespaces.

Parameters
$deletePatternstring CONSTRUCT pattern of tripples to delete
$wherestring condition for data to delete
$extraNamespacesarray (associative) of namespaceId => namespaceUri
Returns
boolean stating whether the operations succeeded

Implements SMW\SPARQLStore\RepositoryConnection.

◆ deleteAll()

SMW\SPARQLStore\RepositoryConnectors\GenericRepositoryConnector::deleteAll ( )

Convenience method for deleting all triples of the entire store

Returns
boolean

◆ deleteContentByValue()

SMW\SPARQLStore\RepositoryConnectors\GenericRepositoryConnector::deleteContentByValue (   $propertyName,
  $objectName,
  $extraNamespaces = [] 
)

Convenience method for deleting all triples that have a subject that occurs in a triple with the given property and object. This is used in SMW to delete subobjects with all their data. Some RDF stores fail on complex delete queries, hence a wrapper function is provided to allow more pedestrian implementations.

The function declares the standard namespaces wiki, swivt, rdf, owl, rdfs, property, xsd, so these do not have to be included in $extraNamespaces.

Parameters
$propertyNamestring Turtle name of marking property
$objectNamestring Turtle name of marking object/value
$extraNamespacesarray (associative) of namespaceId => namespaceUri
Returns
boolean stating whether the operations succeeded

◆ deleteData()

SMW\SPARQLStore\RepositoryConnectors\GenericRepositoryConnector::deleteData (   $triples,
  $extraNamespaces = [] 
)

DELETE DATA wrapper. The function declares the standard namespaces wiki, swivt, rdf, owl, rdfs, property, xsd, so these do not have to be included in $extraNamespaces.

Parameters
$triplesstring of triples to delete
$extraNamespacesarray (associative) of namespaceId => namespaceUri
Returns
boolean stating whether the operations succeeded

◆ doHttpPost()

SMW\SPARQLStore\RepositoryConnectors\GenericRepositoryConnector::doHttpPost (   $payload)

Execute a HTTP-based SPARQL POST request according to http://www.w3.org/2009/sparql/docs/http-rdf-update/. The method throws exceptions based on GenericHttpDatabaseConnector::mapHttpRequestError(). If errors occur and this method does not throw anything, then an empty result with an error code is returned.

Note
This protocol is not part of the SPARQL standard and may not be supported by all stores. To avoid using it, simply do not provide a data endpoint URL when configuring the SPARQL database. If used, the protocol might lead to a better performance since there is less parsing required to fetch the data from the request.
Some stores (e.g. 4Store) support another mode of posting data that may be implemented in a special database handler.
Parameters
$payloadstring Turtle serialization of data to send
Returns
boolean

Implements SMW\SPARQLStore\RepositoryConnection.

◆ doQuery()

SMW\SPARQLStore\RepositoryConnectors\GenericRepositoryConnector::doQuery (   $sparql)

Execute a SPARQL query and return an RepositoryResult object that contains the results. The method throws exceptions based on GenericHttpDatabaseConnector::mapHttpRequestError(). If errors occur and this method does not throw anything, then an empty result with an error code is returned.

Note
This function sets the graph that is to be used as part of the request. Queries should not include additional graph information.
Parameters
$sparqlstring with the complete SPARQL query (SELECT or ASK)
Returns
RepositoryResult

Implements SMW\SPARQLStore\RepositoryConnection.

◆ doUpdate()

SMW\SPARQLStore\RepositoryConnectors\GenericRepositoryConnector::doUpdate (   $sparql)

Execute a SPARQL update and return a boolean to indicate if the operations was successful. The method throws exceptions based on GenericHttpDatabaseConnector::mapHttpRequestError(). If errors occur and this method does not throw anything, then false is returned.

Note
When this is written, it is not clear if the update protocol supports a default-graph-uri parameter. Hence the target graph for all updates is generally encoded in the query string and not fixed when sending the query. Direct callers to this function must include the graph information in the queries that they build.
Parameters
$sparqlstring with the complete SPARQL update query (INSERT or DELETE)
Returns
boolean

Implements SMW\SPARQLStore\RepositoryConnection.

◆ getDefaultGraph()

SMW\SPARQLStore\RepositoryConnectors\GenericRepositoryConnector::getDefaultGraph ( )

Get the URI of the default graph that this database connector is using, or the empty string if none is used (no graph related statements in queries/updates).

Returns
string graph UIR or empty

◆ getEndpoint()

SMW\SPARQLStore\RepositoryConnectors\GenericRepositoryConnector::getEndpoint (   $type)
Since
3.2
Parameters
string | int$type
Returns
string

◆ getLastErrorCode()

SMW\SPARQLStore\RepositoryConnectors\GenericRepositoryConnector::getLastErrorCode ( )
Since
3.2
Returns
string

◆ getPrefixString()

static SMW\SPARQLStore\RepositoryConnectors\GenericRepositoryConnector::getPrefixString (   $extraNamespaces = [],
  $forSparql = true 
)
static

Create the standard PREFIX declarations for SPARQL or Turtle, possibly with additional namespaces involved.

Parameters
$extraNamespacesarray (associative) of namespaceId => namespaceUri
$forSparqlboolean true to use SPARQL prefix syntax, false to use Turtle prefix syntax
Returns
string

◆ getRepositoryClient()

SMW\SPARQLStore\RepositoryConnectors\GenericRepositoryConnector::getRepositoryClient ( )

◆ getSparqlForAsk()

SMW\SPARQLStore\RepositoryConnectors\GenericRepositoryConnector::getSparqlForAsk (   $where,
  $extraNamespaces = [] 
)

Build the SPARQL query that is used by GenericHttpDatabaseConnector::ask(). The function declares the standard namespaces wiki, swivt, rdf, owl, rdfs, property, xsd, so these do not have to be included in $extraNamespaces.

Parameters
$wherestring WHERE part of the query, without surrounding { }
$extraNamespacesarray (associative) of namespaceId => namespaceUri
Returns
string SPARQL query

◆ getSparqlForSelect()

SMW\SPARQLStore\RepositoryConnectors\GenericRepositoryConnector::getSparqlForSelect (   $vars,
  $where,
  $options = [],
  $extraNamespaces = [] 
)

Build the SPARQL query that is used by GenericHttpDatabaseConnector::select(). The function declares the standard namespaces wiki, swivt, rdf, owl, rdfs, property, xsd, so these do not have to be included in $extraNamespaces.

Parameters
$wherestring WHERE part of the query, without surrounding { }
$extraNamespacesarray (associative) of namespaceId => namespaceUri
Returns
string SPARQL query

◆ getVersion()

SMW\SPARQLStore\RepositoryConnectors\GenericRepositoryConnector::getVersion ( )
Since
3.2
Returns
string|int

◆ insertData()

SMW\SPARQLStore\RepositoryConnectors\GenericRepositoryConnector::insertData (   $triples,
  $extraNamespaces = [] 
)

INSERT DATA wrapper. The function declares the standard namespaces wiki, swivt, rdf, owl, rdfs, property, xsd, so these do not have to be included in $extraNamespaces.

Parameters
$triplesstring of triples to insert
$extraNamespacesarray (associative) of namespaceId => namespaceUri
Returns
boolean stating whether the operations succeeded

◆ insertDelete()

SMW\SPARQLStore\RepositoryConnectors\GenericRepositoryConnector::insertDelete (   $insertPattern,
  $deletePattern,
  $where,
  $extraNamespaces = [] 
)

INSERT DELETE wrapper. The function declares the standard namespaces wiki, swivt, rdf, owl, rdfs, property, xsd, so these do not have to be included in $extraNamespaces.

Parameters
$insertPatternstring CONSTRUCT pattern of tripples to insert
$deletePatternstring CONSTRUCT pattern of tripples to delete
$wherestring condition for data to delete
$extraNamespacesarray (associative) of namespaceId => namespaceUri
Returns
boolean stating whether the operations succeeded

◆ mapHttpRequestError()

SMW\SPARQLStore\RepositoryConnectors\GenericRepositoryConnector::mapHttpRequestError (   $endpoint,
  $sparql 
)
protected
Parameters
$endpointstring URL of endpoint that was used
$sparqlstring query that caused the problem

◆ ping()

SMW\SPARQLStore\RepositoryConnectors\GenericRepositoryConnector::ping (   $endpointType = self::ENDP_QUERY)

Check if the database can be contacted.

Todo:
SPARQL endpoints sometimes return errors if no (valid) query is posted. The current implementation tries to catch this, but this might not be entirely correct. Especially, the SPARQL 1.1 HTTP error codes for Update are not defined yet (April 15 2011).
Parameters
$pingQueryEndpointboolean true if the query endpoint should be pinged, false if the update endpoint should be pinged
Returns
boolean to indicate success

◆ select()

SMW\SPARQLStore\RepositoryConnectors\GenericRepositoryConnector::select (   $vars,
  $where,
  $options = [],
  $extraNamespaces = [] 
)

SELECT wrapper. The function declares the standard namespaces wiki, swivt, rdf, owl, rdfs, property, xsd, so these do not have to be included in $extraNamespaces.

Parameters
$varsmixed array or string, field name(s) to be retrieved, can be '*'
$wherestring WHERE part of the query, without surrounding { }
$optionsarray (associative) of options, e.g. array( 'LIMIT' => '10' )
$extraNamespacesarray (associative) of namespaceId => namespaceUri
Returns
RepositoryResult

Implements SMW\SPARQLStore\RepositoryConnection.

◆ selectCount()

SMW\SPARQLStore\RepositoryConnectors\GenericRepositoryConnector::selectCount (   $variable,
  $where,
  $options = [],
  $extraNamespaces = [] 
)

SELECT wrapper for counting results. The function declares the standard namespaces wiki, swivt, rdf, owl, rdfs, property, xsd, so these do not have to be included in $extraNamespaces.

Parameters
$variablestring variable name or '*'
$wherestring WHERE part of the query, without surrounding { }
$optionsarray (associative) of options, e.g. array('LIMIT' => '10')
$extraNamespacesarray (associative) of namespaceId => namespaceUri
Returns
RepositoryResult

◆ setConnectionTimeout()

SMW\SPARQLStore\RepositoryConnectors\GenericRepositoryConnector::setConnectionTimeout (   $timeout = 10)
Since
2.0
Parameters
integer$timeoutin seconds

◆ shouldPing()

SMW\SPARQLStore\RepositoryConnectors\GenericRepositoryConnector::shouldPing ( )
Since
3.2
Returns
boolean

Member Data Documentation

◆ ENDP_DATA

const SMW\SPARQLStore\RepositoryConnectors\GenericRepositoryConnector::ENDP_DATA = RepositoryConnection::DATA_ENDPOINT

Flag denoting endpoints being capable of SPARQL HTTP graph management

◆ ENDP_QUERY

const SMW\SPARQLStore\RepositoryConnectors\GenericRepositoryConnector::ENDP_QUERY = RepositoryConnection::QUERY_ENDPOINT

Flag denoting endpoints being capable of querying

◆ ENDP_UPDATE

const SMW\SPARQLStore\RepositoryConnectors\GenericRepositoryConnector::ENDP_UPDATE = RepositoryConnection::UPDATE_ENDPOINT

Flag denoting endpoints being capable of updating


The documentation for this class was generated from the following file:

About | General disclaimer | Privacy policy