# CRUD (RDF Data)

## `SolidRDFSource`

The [SolidRDFSource](https://api.docs.inrupt.com/docs/developer-tools/api/java/inrupt-client/latest/com/inrupt/client/solid/SolidRDFSource.html) class maps to an RDF resource stored or to be stored in a Solid Pod.

A summary of parameters to the [SolidRDFSource](https://api.docs.inrupt.com/docs/developer-tools/api/java/inrupt-client/latest/com/inrupt/client/solid/SolidRDFSource.html) class constructors are as follows:

<table><thead><tr><th width="132.30255126953125">Field</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td><strong><code>identifier</code></strong></td><td><a href="https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/net/URI.html">java.net.URI</a></td><td>The URI (Uniform Resource Identifier) of the resource.</td></tr><tr><td><strong><code>dataset</code></strong></td><td><a href="https://commons.apache.org/proper/commons-rdf/apidocs/org/apache/commons/rdf/api/Dataset.html">org.apache.commons.rdf.api.Dataset</a></td><td>The <a href="https://www.w3.org/TR/rdf11-concepts/#dfn-rdf-dataset">RDF dataset</a> (i.e., the set(s) of triples) contained in the resource.</td></tr><tr><td><strong><code>headers</code></strong></td><td><a href="https://api.docs.inrupt.com/docs/developer-tools/api/java/inrupt-client/latest/com/inrupt/client/Headers.html">com.inrupt.client.Headers</a></td><td>Collection of HTTP headers.</td></tr></tbody></table>

To instantiate, specify the identifier (i.e., the URI) for the resource:

```java
// Locally instantiate a new resource
SolidRDFSource newResource = new SolidRDFSource(
      URI.create("https://pod.example.com/resource/path"));  // identifier
```

Optionally, you can also initialize the resource data during instantiation by including an [RDF dataset](https://www.w3.org/TR/rdf11-concepts/#dfn-rdf-dataset):

```java
// Locally instantiate a new resource with initial RDF Dataset
SolidRDFSource newResourcePopulated = new SolidRDFSource(
      URI.create("https://pod.example.com/resource/path"),  // identifier
      initialDataset);                                                  // dataset
```

You can extended the [SolidRDFSource](https://api.docs.inrupt.com/docs/developer-tools/api/java/inrupt-client/latest/com/inrupt/client/solid/SolidRDFSource.html) class to model a POJO (Plain Old Java Object) class as an RDF resources. See [Modeling an RDF Resource](/sdk/java-sdk/crud-rdf-data/modeling-rdf-data.md) for information on modeling POJOs as RDF resources.

### **Class Methods**

You can:

* Use the [SolidRDFSource](https://api.docs.inrupt.com/docs/developer-tools/api/java/inrupt-client/latest/com/inrupt/client/solid/SolidRDFSource.html) class [methods](https://api.docs.inrupt.com/docs/developer-tools/api/java/inrupt-client/latest/com/inrupt/client/solid/SolidRDFSource.html#method.summary) to directly interact with local [SolidRDFSource](https://api.docs.inrupt.com/docs/developer-tools/api/java/inrupt-client/latest/com/inrupt/client/solid/SolidRDFSource.html) object’s dataset or
* Or, if you have extended the class to model a POJO (Plain Old Java Object) class as an RDF resources, use that class methods/members.

  ```java
  public class Expense extends SolidRDFSource {
     // ...

  }
  ```

### **Read/Write to Pod**

To read RDF resources from your Pod or write RDF resources to your Pod (i.e., CRUD operations), the library provides [SolidSyncClient](https://api.docs.inrupt.com/docs/developer-tools/api/java/inrupt-client/latest/com/inrupt/client/solid/SolidSyncClient.html) and [SolidClient](https://api.docs.inrupt.com/docs/developer-tools/api/java/inrupt-client/latest/com/inrupt/client/solid/SolidClient.html) classes. See [CRUD Module](/sdk/java-sdk/crud-data.md) for details.

{% hint style="info" %}
When saving a new resource to a Pod (e.g., **`https://pod.example.com/container1/container2/resource`**), if any Container in the resource path does not exist (e.g., **`container1/`** and **`container2/`**), the [SolidSyncClient.create()](https://api.docs.inrupt.com/docs/developer-tools/api/java/inrupt-client/latest/com/inrupt/client/solid/SolidSyncClient.html#create\(T\)) and [SolidClient.create()](https://api.docs.inrupt.com/docs/developer-tools/api/java/inrupt-client/latest/com/inrupt/client/solid/SolidClient.html#create\(T\)) methods creates the missing containers as well.
{% endhint %}

For the CRUD operation response headers, you can use [SolidRDFSource.getHeaders()](https://api.docs.inrupt.com/docs/developer-tools/api/java/inrupt-client/latest/com/inrupt/client/solid/SolidRDFSource.html#method.summary). See [Headers](/sdk/java-sdk/crud-data/appendix-headers.md).

## Container

A [Container](/reference/glossary.md#container) is an [RDF resource](/reference/glossary.md#rdf-resource) that can contain other RDF (including other Containers) and [non-RDF resources](/reference/glossary.md#non-rdf-resource). A Container is analogous to a folder in a file system.

{% hint style="warning" %}
Container URIs always end with a slash **`/`**.
{% endhint %}

### `SolidContainer`

The [SolidContainer](https://api.docs.inrupt.com/docs/developer-tools/api/java/inrupt-client/latest/com/inrupt/client/solid/SolidContainer.html) class maps to a Container stored or to be stored in a Solid Pod. [\[1\]](#solid) The [SolidContainer](https://api.docs.inrupt.com/docs/developer-tools/api/java/inrupt-client/latest/com/inrupt/client/solid/SolidContainer.html) class extends [SolidRDFSource](https://api.docs.inrupt.com/docs/developer-tools/api/java/inrupt-client/latest/com/inrupt/client/solid/SolidRDFSource.html).

To instantiate, specify the destination URI for the Container. Container URIs always end with a slash **`/`**.

```java
// Locally instantiate a new Container.
// Container URIs ends with a slash "/"
SolidContainer newResource = new SolidContainer(
      URI.create("https://pod.example.com/container/path/"));
```

### **Class Methods**

You can use [SolidContainer](https://api.docs.inrupt.com/docs/developer-tools/api/java/inrupt-client/latest/com/inrupt/client/solid/SolidContainer.html) class [methods](https://api.docs.inrupt.com/docs/developer-tools/api/java/inrupt-client/latest/com/inrupt/client/solid/SolidContainer.html#method.summary) to interact with a Container directly. For example, to retrieve all contained resources within a Container, you can use [getResources](https://api.docs.inrupt.com/docs/developer-tools/api/java/inrupt-client/latest/com/inrupt/client/solid/SolidContainer.html#getResources\(\)).

### **Read/Write to Pod**

To read Containers from your Pod or write Containers to your Pod (i.e., CRUD operations), the library provides [SolidSyncClient](https://api.docs.inrupt.com/docs/developer-tools/api/java/inrupt-client/latest/com/inrupt/client/solid/SolidSyncClient.html) and [SolidClient](https://api.docs.inrupt.com/docs/developer-tools/api/java/inrupt-client/latest/com/inrupt/client/solid/SolidClient.html) classes.

{% hint style="info" %}
**Tip**

* Although you can instantiate and save a [SolidContainer](https://api.docs.inrupt.com/docs/developer-tools/api/java/inrupt-client/latest/com/inrupt/client/solid/SolidContainer.html) by itself, when creating a resource to a Pod (e.g., **`https://pod.example.com/container1/container2/resource`**), if any Container in the location path does not exist (e.g., **`container1/`** and **`container2/`**), the [SolidSyncClient.create()](https://api.docs.inrupt.com/docs/developer-tools/api/java/inrupt-client/latest/com/inrupt/client/solid/SolidSyncClient.html#create\(T\)) and [SolidClient.create()](https://api.docs.inrupt.com/docs/developer-tools/api/java/inrupt-client/latest/com/inrupt/client/solid/SolidClient.html#create\(T\)) methods creates the missing containers as well as the resource.
* To delete a Container, the Container must be empty.
  {% endhint %}

For the CRUD operation response headers, you can use [SolidContainer.getHeaders()](https://api.docs.inrupt.com/docs/developer-tools/api/java/inrupt-client/latest/com/inrupt/client/solid/SolidContainer.html#method.summary). See [Headers](/sdk/java-sdk/crud-data/appendix-headers.md).

## Non-RDF Resource

A [non-RDF Resource](/reference/glossary.md#non-rdf-resource) is any non-RDF binary or text file, such as **`.pdf`**, **`.jpeg`**, etc.

### `SolidNonRDFSource`

The [SolidNonRDFSource](https://api.docs.inrupt.com/docs/developer-tools/api/java/inrupt-client/latest/com/inrupt/client/solid/SolidNonRDFSource.html) class maps to a non-RDF resources stored or to be stored in a Solid Pod.

A summary of parameters to the [SolidNonRDFSource](https://api.docs.inrupt.com/docs/developer-tools/api/java/inrupt-client/latest/com/inrupt/client/solid/SolidNonRDFSource.html) class constructors are as follows:

<table><thead><tr><th width="170.88214111328125">Field</th><th width="207.2470703125">Type</th><th>Description</th></tr></thead><tbody><tr><td><strong><code>identifier</code></strong></td><td><a href="https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/net/URI.html">java.net.URI</a></td><td>The <a href="/pages/7PKZaxnnUDGdJ8gPDOqL#uri">URI</a> (Uniform Resource Identifier) of the resource.</td></tr><tr><td><strong><code>contentType</code></strong></td><td><a href="https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/String.html">java.lang.String</a></td><td>The MIME type for the file.</td></tr><tr><td><strong><code>entity</code></strong></td><td><a href="https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/io/InputStream.html">java.io.InputStream</a></td><td>Input stream of the file content.</td></tr></tbody></table>

To instantiate, specify the identifier (i.e., the URI), the content type (i.e., MIME type), and the input stream for the resource. For example, the following instantiates a SolidNonRDFSource for a **`.jpg`** file:

```java
MultipartFile file = //... Some .jpg file

// Locally instantiate a new SolidNonRDFSource.
SolidNonRDFSource newNonRDFSource = new SolidNonRDFSource(
   URI.create("https://pod.example.com/container1/somePic.jpg"),  // identifier
   file.getContentType(),                 // MIME type
   file.getInputStream());                // InputStream
```

### **Read/Write to Pod**

To read non-RDF resources from your Pod or write non-RDF resources to your Pod (i.e., CRUD operations), the library provides [SolidSyncClient](https://api.docs.inrupt.com/docs/developer-tools/api/java/inrupt-client/latest/com/inrupt/client/solid/SolidSyncClient.html) and [SolidClient](https://api.docs.inrupt.com/docs/developer-tools/api/java/inrupt-client/latest/com/inrupt/client/solid/SolidClient.html) classes. See [CRUD Module](/sdk/java-sdk/crud-data.md) for details.

{% hint style="info" %}
**Tip**

When saving a new resource to a Pod (e.g., **`https://pod.example.com/container1/container2/somePic.jpg`**), if any Container in the resource path does not exist (e.g., **`container1/`** and **`container2/`**), the [SolidSyncClient.create()](https://api.docs.inrupt.com/docs/developer-tools/api/java/inrupt-client/latest/com/inrupt/client/solid/SolidSyncClient.html#create\(T\)) and [SolidClient.create()](https://api.docs.inrupt.com/docs/developer-tools/api/java/inrupt-client/latest/com/inrupt/client/solid/SolidClient.html#create\(T\)) methods creates the missing containers as well.
{% endhint %}

For the CRUD operation response headers, you can use [SolidNonRDFSource.getHeaders()](https://api.docs.inrupt.com/docs/developer-tools/api/java/inrupt-client/latest/com/inrupt/client/solid/SolidNonRDFSource.html#method.summary). See [Headers](/sdk/java-sdk/crud-data/appendix-headers.md).


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.inrupt.com/sdk/java-sdk/crud-rdf-data.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
