# Session Manipulation API – Java API Reference

The **Session Manipulation Java API** provides runtime‑level access to **session‑scoped business objects** during CRUD and process execution.

This API allows developers to **read, modify, and inject data into the session context** before data is persisted to the database or after data is retrieved, without directly modifying the database schema.

***

### ObjectManipulation Interface

The `ObjectManipulation` interface is the core entry point for interacting with session data at runtime.

```
public static final ObjectManipulation DEFAULT = new ObjectManipulationImpl();

public <T> T get(String expr);

public <T> void set(String expr, T newvalue);

public <T> void set(String expr, T newvalue, String processName);
```

#### Method Overview

| Method                                          | Description                                |
| ----------------------------------------------- | ------------------------------------------ |
| `get(String expr)`                              | Retrieves session data using an expression |
| `set(String expr, T value)`                     | Updates session data                       |
| `set(String expr, T value, String processName)` | Updates session data with process context  |

***

### Reading Session Data (get)

The `get()` method retrieves session‑scoped data using a **runtime expression**.

#### One‑to‑One Object Access

```
ObjectManipulation.DEFAULT.get("MD1161858889");
```

Output:

```
{SOFTWARE_ASSET_ID=216, IP_ADDRESS=null, URL=null}
```

Access a specific attribute:

```
ObjectManipulation.DEFAULT.get("MD1161858889.SOFTWARE_ASSET_ID");
```

Output:

```
216
```

***

### Writing Session Data (set)

The `set()` method updates session‑scoped data at runtime.

```
ObjectManipulation.DEFAULT.set(
    "MD1161858889.SOFTWARE_ASSET_ID",
    7777
);
```

This updates the value in the session context but **does not directly persist to the database** unless a subsequent save operation occurs.

***

### Handling One‑to‑Many Data Structures

For one‑to‑many relationships, session data is represented as a **list of maps**.

#### Retrieve All Records

```
ObjectManipulation.DEFAULT.get("MD1161833204");
```

Output:

```
[
  {SOFTWARE_ASSET_ID=216, ATTACHMENT_ID=208, FILE_PATH=null, KEY={...}},
  {SOFTWARE_ASSET_ID=216, ATTACHMENT_ID=209, FILE_PATH=null, KEY={...}},
  {SOFTWARE_ASSET_ID=216, ATTACHMENT_ID=210, FILE_PATH=null, KEY={...}}
]
```

***

#### Retrieve a Specific Index

```
ObjectManipulation.DEFAULT.get("MD1161833204[0]");
```

***

#### Retrieve Attribute Values Across All Records

```
ObjectManipulation.DEFAULT.get("MD1161833204.SOFTWARE_ASSET_ID");
```

Output:

```
[216, 216, 216]
```

***

#### Retrieve Attribute by Index

```
ObjectManipulation.DEFAULT.get("MD1161833204.SOFTWARE_ASSET_ID[0]");
```

Output:

```
216
```

***

### Updating One‑to‑Many Records

To update a specific record in a collection, pass a map representing the new values.

```
HashMap map = new HashMap() {{
  put("SOFTWARE_ASSET_ID", "9999");
  put("IP_ADDRESS", "/x/y/x.pdf");
  put("URL", null);
}};

ObjectManipulation.DEFAULT.set("MD1161833204[0]", map);
```

This replaces the session data for the selected record.

***

### Inserting a New Record into a Collection

To create a new record in a one‑to‑many relationship, specify the operation type:

```
ObjectManipulation.DEFAULT.set(
    "MD1161833204",
    map,
    "INSERT"
);
```

This creates a **new session record**, which can later be persisted during a save operation.

***

### Process‑Aware Session Updates

The overloaded `set()` method allows session updates to be scoped to a specific process.

```
ObjectManipulation.DEFAULT.set(
    "MD1161833204",
    map,
    "PROCESS_NAME"
);
```

This is especially useful when session manipulation occurs during **process execution**.

***

### Summary

The **Session Manipulation Java API** enables controlled, runtime‑level data handling within ONEWEB.

Key capabilities include:

* Reading and updating session‑scoped business objects
* Supporting one‑to‑one and one‑to‑many data structures
* Modifying runtime data without immediate database persistence
* Process‑aware session manipulation
* Safe integration with CRUD and Process Runtime APIs

This API plays a critical role in **complex runtime workflows**, **process‑driven logic**, and **dynamic data handling** in the ONEWEB platform.


---

# 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.onewebstack.com/oneweb-platform-th/api-reference/session-manipulation-api/session-manipulation-api-java-api-reference.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.
