Package org.eclipse.rdf4j.spring.support

## Class RDF4JTemplate

- java.lang.Object
- - org.eclipse.rdf4j.spring.support.RDF4JTemplate

-     public class RDF4JTemplate
      extends Object

  Since:
    4.0.0
  Author:
    Florian Kleedorfer, Gabriel Pickl

- - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `RDF4JTemplate​(RepositoryConnectionFactory repositoryConnectionFactory, OperationInstantiator operationInstantiator)` |

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `<T> T` | `applyToConnection​(Function<RepositoryConnection,​T> fun)` |
    `void` | `associate​(IRI fromResource, IRI property, Collection<IRI> toResources, boolean deleteOtherOutgoing, boolean deleteOtherIcoming)` |
    `void` | `consumeConnection​(Consumer<RepositoryConnection> fun)` |
    `void` | `delete​(IRI id)` | Deletes the specified resource: all triples are deleted in which `id` is the subject or the object.
    `void` | `delete​(IRI start, List<PropertyPath> propertyPaths)` | Deletes the specified resource and all resources `R` reached via any of the specified property paths.
    `void` | `deleteTriplesWithSubject​(IRI id)` |
    `IRI` | `getNewUUID()` | Returns a UUID IRI (schema: 'urn:uuid').
    `Supplier<String>` | `getStringSupplierFromResourceContent​(String resourceName)` | Returns a `` that returns the String content of the specified resource (as obtained by a `ResourceLoader`).
    `GraphQueryEvaluationBuilder` | `graphQuery​(Class<?> owner, String operationName, Supplier<String> queryStringSupplier)` | Uses a cached `GraphQuery` if one is available under the specified `operationName` for the `RepositoryConnection` that is used, otherwise the query string is obtained from the specified supplier, a new GraphQuery is instantiated and cached for future calls to this method.
    `GraphQueryEvaluationBuilder` | `graphQuery​(Class<?> owner, NamedSparqlSupplier namedSparqlSupplier)` | Uses the provided `NamedSparqlSupplier` for calling `graphQuery(Class, String, Supplier)`.
    `GraphQueryEvaluationBuilder` | `graphQuery​(String graphQueryString)` | Bypassing any caches, generates a new GraphQuery from the specified SPARQL string and returns a Builder for its evaluation.
    `GraphQueryEvaluationBuilder` | `graphQueryFromResource​(Class<?> owner, String resourceName)` | Reads the query from the specified resource and provides it through a `` in `graphQuery(Class, String, Supplier)`, using the `resourceName` as the `operationName`.
    `TupleQueryEvaluationBuilder` | `tupleQuery​(Class<?> owner, String operationName, Supplier<String> queryStringSupplier)` | Uses a cached `TupleQuery` if one is available under the specified `operationName` for the `RepositoryConnection` that is used, otherwise the query string is obtained from the specified supplier, a new TupleQuery is instantiated and cached for future calls to this method.
    `TupleQueryEvaluationBuilder` | `tupleQuery​(Class<?> owner, NamedSparqlSupplier namedSparqlSupplier)` | Uses the provided `NamedSparqlSupplier` for calling `tupleQuery(Class, String, Supplier)`.
    `TupleQueryEvaluationBuilder` | `tupleQuery​(String queryString)` | Bypassing any caches, generates a new TupleQuery from the specified SPARQL string and returns a Builder for its evaluation.
    `TupleQueryEvaluationBuilder` | `tupleQueryFromResource​(Class<?> owner, String resourceName)` | Reads the query from the specified resource and provides it through a `` in `tupleQuery(Class, String, Supplier)`, using the `resourceName` as the `operationName`.
    `UpdateExecutionBuilder` | `update​(Class<?> owner, String operationName, Supplier<String> updateStringSupplier)` | Uses a cached `Update` if one is available under the specified `operationName` for the `RepositoryConnection` that is used, otherwise the query string is obtained from the specified supplier, a new Update is instantiated and cached for future calls to this method.
    `UpdateExecutionBuilder` | `update​(Class<?> owner, NamedSparqlSupplier namedSparqlSupplier)` | Uses the provided `NamedSparqlSupplier` for calling `update(Class, String, Supplier)`.
    `UpdateExecutionBuilder` | `update​(String updateString)` | Bypassing any caches, generates a new Update from the specified SPARQL string and returns a Builder for its execution.
    `UpdateExecutionBuilder` | `updateFromResource​(Class<?> owner, String resourceName)` | Reads the update from the specified resource and provides it through a `` in `update(Class, String, Supplier)`, using the `resourceName` as the `operationName`.
    `UpdateWithModelBuilder` | `updateWithBuilder()` |
    `UpdateExecutionBuilder` | `updateWithoutCachingStatement​(String updateString)` |

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### RDF4JTemplate

          public RDF4JTemplate​(RepositoryConnectionFactory repositoryConnectionFactory,
                               OperationInstantiator operationInstantiator)

  - ### Method Detail

    - #### consumeConnection

          public void consumeConnection​(Consumer<RepositoryConnection> fun)

    - #### applyToConnection

          public <T> T applyToConnection​(Function<RepositoryConnection,​T> fun)

    - #### update

          public UpdateExecutionBuilder update​(String updateString)

      Bypassing any caches, generates a new Update from the specified SPARQL string and returns a Builder for its execution. Should be avoided in favor of one of the methods that apply caching unless the update is not reusable.

    - #### update

          public UpdateExecutionBuilder update​(Class<?> owner,
                                               String operationName,
                                               Supplier<String> updateStringSupplier)

      Uses a cached `Update` if one is available under the specified `operationName` for the `RepositoryConnection` that is used, otherwise the query string is obtained from the specified supplier, a new Update is instantiated and cached for future calls to this method. Note: this call is equivalent to `update(String)` if operation caching is disabled.
      Parameters:
        `owner` - the class of the client requesting the update, used to generate a cache key in combination with the operation name
        `operationName` - name of the operation that, within the scope of the client, identifies the update
        `updateStringSupplier` - supplies the sparql of the update if needed

    - #### updateFromResource

          public UpdateExecutionBuilder updateFromResource​(Class<?> owner,
                                                           String resourceName)

      Reads the update from the specified resource and provides it through a `` in `update(Class, String, Supplier)`, using the `resourceName` as the `operationName`.

    - #### update

          public UpdateExecutionBuilder update​(Class<?> owner,
                                               NamedSparqlSupplier namedSparqlSupplier)

      Uses the provided `NamedSparqlSupplier` for calling `update(Class, String, Supplier)`.

    - #### updateWithoutCachingStatement

          public UpdateExecutionBuilder updateWithoutCachingStatement​(String updateString)

    - #### updateWithBuilder

          public UpdateWithModelBuilder updateWithBuilder()

    - #### tupleQuery

          public TupleQueryEvaluationBuilder tupleQuery​(String queryString)

      Bypassing any caches, generates a new TupleQuery from the specified SPARQL string and returns a Builder for its evaluation. Should be avoided in favor of one of the methods that apply caching unless the query is not reusable.

    - #### tupleQuery

          public TupleQueryEvaluationBuilder tupleQuery​(Class<?> owner,
                                                        String operationName,
                                                        Supplier<String> queryStringSupplier)

      Uses a cached `TupleQuery` if one is available under the specified `operationName` for the `RepositoryConnection` that is used, otherwise the query string is obtained from the specified supplier, a new TupleQuery is instantiated and cached for future calls to this method.

    - #### tupleQueryFromResource

          public TupleQueryEvaluationBuilder tupleQueryFromResource​(Class<?> owner,
                                                                    String resourceName)

      Reads the query from the specified resource and provides it through a `` in `tupleQuery(Class, String, Supplier)`, using the `resourceName` as the `operationName`.

    - #### tupleQuery

          public TupleQueryEvaluationBuilder tupleQuery​(Class<?> owner,
                                                        NamedSparqlSupplier namedSparqlSupplier)

      Uses the provided `NamedSparqlSupplier` for calling `tupleQuery(Class, String, Supplier)`.

    - #### graphQuery

          public GraphQueryEvaluationBuilder graphQuery​(String graphQueryString)

      Bypassing any caches, generates a new GraphQuery from the specified SPARQL string and returns a Builder for its evaluation. Should be avoided in favor of one of the methods that apply caching unless the query is not reusable.

    - #### graphQuery

          public GraphQueryEvaluationBuilder graphQuery​(Class<?> owner,
                                                        String operationName,
                                                        Supplier<String> queryStringSupplier)

      Uses a cached `GraphQuery` if one is available under the specified `operationName` for the `RepositoryConnection` that is used, otherwise the query string is obtained from the specified supplier, a new GraphQuery is instantiated and cached for future calls to this method.

    - #### graphQueryFromResource

          public GraphQueryEvaluationBuilder graphQueryFromResource​(Class<?> owner,
                                                                    String resourceName)

      Reads the query from the specified resource and provides it through a `` in `graphQuery(Class, String, Supplier)`, using the `resourceName` as the `operationName`.

    - #### graphQuery

          public GraphQueryEvaluationBuilder graphQuery​(Class<?> owner,
                                                        NamedSparqlSupplier namedSparqlSupplier)

      Uses the provided `NamedSparqlSupplier` for calling `graphQuery(Class, String, Supplier)`.

    - #### deleteTriplesWithSubject

          public void deleteTriplesWithSubject​(IRI id)

    - #### delete

          public void delete​(IRI id)

      Deletes the specified resource: all triples are deleted in which `id` is the subject or the object.
      Parameters:
        `id` -

    - #### delete

          public void delete​(IRI start,
                             List<PropertyPath> propertyPaths)

      Deletes the specified resource and all resources `R` reached via any of the specified property paths. Deletion means that all triples are removed in which `start` or any resource in `R` are the subject or the object.
      Parameters:
        `start` - the initial resource to be deleted
        `propertyPaths` - paths by which to reach more resources to be deleted.

    - #### associate

          public void associate​(IRI fromResource,
                                IRI property,
                                Collection<IRI> toResources,
                                boolean deleteOtherOutgoing,
                                boolean deleteOtherIcoming)

    - #### getStringSupplierFromResourceContent

          public Supplier<String> getStringSupplierFromResourceContent​(String resourceName)

      Returns a `` that returns the String content of the specified resource (as obtained by a `ResourceLoader`). The resource's content is read once when this method is called (revealing any problem reading the resource early on.

    - #### getNewUUID

          public IRI getNewUUID()

      Returns a UUID IRI (schema: 'urn:uuid'). Actual implementation depends on the `uuidSource` that has been configured. See `UUIDSource` and `org.eclipse.rdf4j.spring.uuidsource` for details.