Class SPARQLRepository
java.lang.Object
org.eclipse.rdf4j.repository.base.AbstractRepository
org.eclipse.rdf4j.repository.sparql.SPARQLRepository
- All Implemented Interfaces:
HttpClientDependent
,SessionManagerDependent
,Repository
public class SPARQLRepository
extends AbstractRepository
implements HttpClientDependent, SessionManagerDependent
A proxy class to access any SPARQL 1.1 endpoint.
- Author:
- James Leigh
-
Field Summary
Fields inherited from class org.eclipse.rdf4j.repository.base.AbstractRepository
logger
-
Constructor Summary
ConstructorDescriptionSPARQLRepository
(String endpointUrl) Create a new SPARQLRepository using the supplied endpoint URL for queries and updates.SPARQLRepository
(String queryEndpointUrl, String updateEndpointUrl) Create a new SPARQLRepository using the supplied query endpoint URL for queries, and the supplied update endpoint URL for updates. -
Method Summary
Modifier and TypeMethodDescriptionprotected SPARQLProtocolSession
Deprecated.protected SPARQLProtocolSession
Creates a newSPARQLProtocolSession
object.void
enableQuadMode
(boolean flag) Activate quad mode for thisSPARQLRepository
, i.e.Get the additional HTTP headers which will be usedOpens a connection to this repository that can be used for querying and updating the contents of the repository.Get the directory where data and logging for this repository is stored.final org.apache.http.client.HttpClient
HttpClient
that has been assigned or has been used by this object.HttpClientSessionManager
that has been assigned or has been used by this object.Retrieve the passThroughEnabled setting to be used for any newly createdRepositoryConnection
s.Gets a ValueFactory for this Repository.protected void
boolean
Checks whether this repository is writable, i.e.void
setAdditionalHttpHeaders
(Map<String, String> additionalHttpHeaders) Set additional HTTP headers to be included in every request to the server, which may be required for certain unusual server configurations.void
setDataDir
(File dataDir) Set the directory where data and logging for this repository is stored.void
setHttpClient
(org.apache.http.client.HttpClient httpClient) Assign anHttpClient
that this object should use.void
Assign anHttpClientSessionManager
that this object should use.void
setPassThroughEnabled
(Boolean passThroughEnabled) Set the passThroughEnabled configuration.void
setUsernameAndPassword
(String username, String password) Set the username and password to use for authenticating with the remote repository.protected void
toString()
Methods inherited from class org.eclipse.rdf4j.repository.base.AbstractRepository
init, isInitialized, shutDown
-
Constructor Details
-
SPARQLRepository
Create a new SPARQLRepository using the supplied endpoint URL for queries and updates.- Parameters:
endpointUrl
- a SPARQL endpoint URL. May not be null.
-
SPARQLRepository
Create a new SPARQLRepository using the supplied query endpoint URL for queries, and the supplied update endpoint URL for updates.- Parameters:
queryEndpointUrl
- a SPARQL endpoint URL for queries. May not be null.updateEndpointUrl
- a SPARQL endpoint URL for updates. May not be null.- Throws:
IllegalArgumentException
- if one of the supplied endpoint URLs is null.
-
-
Method Details
-
getHttpClientSessionManager
Description copied from interface:SessionManagerDependent
HttpClientSessionManager
that has been assigned or has been used by this object. The life cycle might not be or might be tied to this object, depending on whetherHttpClientSessionManager
was passed to or created by this object respectively.- Specified by:
getHttpClientSessionManager
in interfaceSessionManagerDependent
- Returns:
- a
HttpClientSessionManager
instance or null
-
setHttpClientSessionManager
Description copied from interface:SessionManagerDependent
Assign anHttpClientSessionManager
that this object should use. The life cycle of the givenHttpClientSessionManager
is independent of this object. Closing or shutting down this object does not have any impact on the given client. Callers must ensure that the given client is properly closed elsewhere.- Specified by:
setHttpClientSessionManager
in interfaceSessionManagerDependent
- Parameters:
client
-
-
getHttpClient
public final org.apache.http.client.HttpClient getHttpClient()Description copied from interface:HttpClientDependent
HttpClient
that has been assigned or has been used by this object. The life cycle might not be or might be tied to this object, depending on whetherHttpClient
was passed to or created by this object respectively.- Specified by:
getHttpClient
in interfaceHttpClientDependent
- Returns:
- an
HttpClient
instance or null
-
setHttpClient
public void setHttpClient(org.apache.http.client.HttpClient httpClient) Description copied from interface:HttpClientDependent
Assign anHttpClient
that this object should use. The life cycle of the givenHttpClient
is independent of this object. Closing or shutting down this object does not have any impact on the given client. Callers must ensure that the given client is properly closed elsewhere.- Specified by:
setHttpClient
in interfaceHttpClientDependent
- Parameters:
httpClient
-
-
createSPARQLProtocolSession
Creates a newSPARQLProtocolSession
object. The life-cycle of this is per-connection.- Returns:
- a SPARQLProtocolSession object.
-
createHTTPClient
Deprecated.usecreateSPARQLProtocolSession()
instead -
getConnection
Description copied from interface:Repository
Opens a connection to this repository that can be used for querying and updating the contents of the repository. Created connections need to be closed to make sure that any resources they keep hold of are released. The best way to do this is to use a try-with-resources block, as follows:try (RepositoryConnection conn = repository.getConnection()) { // perform operations on the connection }
Note that
RepositoryConnection
is not guaranteed to be thread-safe! The recommended pattern for repository access in a multi-threaded application is to share the Repository object between threads, but have each thread create and use its ownRepositoryConnection
s.- Specified by:
getConnection
in interfaceRepository
- Returns:
- A connection that allows operations on this repository.
- Throws:
RepositoryException
- If something went wrong during the creation of the Connection.
-
getDataDir
Description copied from interface:Repository
Get the directory where data and logging for this repository is stored.- Specified by:
getDataDir
in interfaceRepository
- Returns:
- the directory where data for this repository is stored.
-
getValueFactory
Description copied from interface:Repository
Gets a ValueFactory for this Repository.- Specified by:
getValueFactory
in interfaceRepository
- Returns:
- A repository-specific ValueFactory.
-
initializeInternal
- Specified by:
initializeInternal
in classAbstractRepository
- Throws:
RepositoryException
-
isWritable
Description copied from interface:Repository
Checks whether this repository is writable, i.e. if the data contained in this repository can be changed. The writability of the repository is determined by the writability of the Sail that this repository operates on.- Specified by:
isWritable
in interfaceRepository
- Throws:
RepositoryException
-
setDataDir
Description copied from interface:Repository
Set the directory where data and logging for this repository is stored.- Specified by:
setDataDir
in interfaceRepository
- Parameters:
dataDir
- the directory where data for this repository is stored
-
setUsernameAndPassword
Set the username and password to use for authenticating with the remote repository.- Parameters:
username
- the username. Setting this to null will disable authentication.password
- the password. Setting this to null will disable authentication.
-
shutDownInternal
- Specified by:
shutDownInternal
in classAbstractRepository
- Throws:
RepositoryException
-
toString
-
getAdditionalHttpHeaders
-
setAdditionalHttpHeaders
Set additional HTTP headers to be included in every request to the server, which may be required for certain unusual server configurations. This will only take effect on connections subsequently returned bygetConnection()
.- Parameters:
additionalHttpHeaders
- a map containing pairs of header names and values. May be null
-
enableQuadMode
public void enableQuadMode(boolean flag) Activate quad mode for thisSPARQLRepository
, i.e. for retrieval of statements also retrieve the graph.Note: the setting is only applied in newly created
SPARQLConnection
s as the setting is an immutable configuration of a connection instance.- Parameters:
flag
- flag to enable or disable the quad mode- See Also:
-
getPassThroughEnabled
Retrieve the passThroughEnabled setting to be used for any newly createdRepositoryConnection
s.- Returns:
- the passThroughEnabled setting. May be
null
if not explicitly configured. - See Also:
-
setPassThroughEnabled
Set the passThroughEnabled configuration. Changing this will influence behavior of any newRepositoryConnection
s, but not of existing ones.- Parameters:
passThroughEnabled
- the passThroughEnabled to set- See Also:
-
createSPARQLProtocolSession()
instead