Skip to content

Store

Overview

Module

Store is the untyped, Hibernate-backed CRUD facade for dynamic entities. Each call addresses an entity by its logical name (matching the name() attribute of an @Entity annotation on a registered client class) and exchanges data as JSON strings — a convenient shape for scripted callers and for endpoints that proxy arbitrary entity names.

For typed CRUD over an @Entity-annotated client class with compile-time field checks, prefer org.eclipse.dirigible.components.data.store.java.JavaEntityStore (resolve it through BeanProvider.getBean(JavaEntityStore.class) inside a controller method). The two stores sit on the same Hibernate session — changes from one are immediately visible to the other.

Key Features:

  • Entity-by-name addressing: Operate on any registered @Entity without compile-time coupling to its class.
  • JSON wire shape: Reads and writes use JSON strings — friendly to HTTP boundaries.
  • Shared session: Backed by the same Hibernate session as JavaEntityStore, so typed and untyped calls interleave safely.
  • Listing options: list, count, and find accept an options JSON for filtering, paging, sorting, and example-based search.
  • Metadata helpers: getEntityName, getTableName, getIdName, and getIdColumn resolve the physical mapping for a logical entity.

Example Usage:

java
import org.eclipse.dirigible.sdk.db.Store;

// Insert
Object savedId = Store.save("Customer", "{\"name\":\"Acme\",\"active\":true}");

// Read by ID
String json = Store.get("Customer", savedId.toString());

// List with options (paging, ordering)
String page = Store.list("Customer", "{\"$limit\":50,\"$offset\":0,\"$orderBy\":\"name\"}");

// Count
long total = Store.count("Customer", null);

// Update (existing ID inside the JSON)
Store.update("Customer", "{\"id\":\"42\",\"name\":\"Acme Corp\"}");

// Delete
Store.deleteEntry("Customer", "42");

Methods

save(entityName, json)

Persists a new entity instance from its JSON representation.

java
public static Object save(String entityName, String json);
ParameterTypeDescription
entityNameStringLogical name of the entity (matches @Entity.name() or the simple class name).
jsonStringJSON object describing the new entity.

Returns

  • Type: Object
  • Description: The generated identifier of the saved entity.

upsert(entityName, json)

Inserts or updates an entity instance from its JSON representation, depending on whether its identifier already exists.

java
public static void upsert(String entityName, String json);
ParameterTypeDescription
entityNameStringLogical name of the entity.
jsonStringJSON object describing the entity; must include the ID for an update.

Returns

  • Type: void

update(entityName, json)

Updates an existing entity instance from its JSON representation.

java
public static void update(String entityName, String json);
ParameterTypeDescription
entityNameStringLogical name of the entity.
jsonStringJSON object describing the entity; must include the ID.

Returns

  • Type: void

list(entityName, optionsJson)

Lists entity instances, optionally filtered by an options JSON (paging, sorting, projections).

java
public static String list(String entityName, String optionsJson);
ParameterTypeDescription
entityNameStringLogical name of the entity.
optionsJsonStringJSON object with listing options (limit, offset, order, filter); may be null.

Returns

  • Type: String
  • Description: JSON array of matching entity instances.

count(entityName, optionsJson)

Counts entity instances matching the supplied options.

java
public static long count(String entityName, String optionsJson);
ParameterTypeDescription
entityNameStringLogical name of the entity.
optionsJsonStringJSON object with filter options; may be null for a total count.

Returns

  • Type: long
  • Description: The number of matching entities.

find(entityName, exampleJson, limit, offset)

Finds entity instances by example — non-null fields of exampleJson form equality predicates.

java
public static String find(String entityName, String exampleJson, int limit, int offset);
ParameterTypeDescription
entityNameStringLogical name of the entity.
exampleJsonStringJSON object whose populated fields are treated as equality filters.
limitintMaximum number of results to return.
offsetintNumber of results to skip.

Returns

  • Type: String
  • Description: JSON array of matching entity instances.

get(entityName, id)

Loads a single entity instance by its primary key.

java
public static String get(String entityName, java.io.Serializable id);
ParameterTypeDescription
entityNameStringLogical name of the entity.
idjava.io.SerializablePrimary-key value of the entity to load.

Returns

  • Type: String
  • Description: JSON object for the entity, or null if no row matches.

deleteEntry(entityName, id)

Deletes an entity instance by its primary key.

java
public static void deleteEntry(String entityName, java.io.Serializable id);
ParameterTypeDescription
entityNameStringLogical name of the entity.
idjava.io.SerializablePrimary-key value of the entity to delete.

Returns

  • Type: void

getEntityName(name)

Resolves the canonical entity name for a logical name (mainly useful for tooling).

java
public static String getEntityName(String name);
ParameterTypeDescription
nameStringLogical entity name.

Returns

  • Type: String
  • Description: The canonical entity name as registered in the metamodel.

getTableName(name)

Returns the physical table name for a logical entity name.

java
public static String getTableName(String name);
ParameterTypeDescription
nameStringLogical entity name.

Returns

  • Type: String
  • Description: The physical database table name.

getIdName(name)

Returns the name of the ID field on the entity.

java
public static String getIdName(String name);
ParameterTypeDescription
nameStringLogical entity name.

Returns

  • Type: String
  • Description: The Java field name marked with @Id.

getIdColumn(name)

Returns the physical column name backing the entity's ID field.

java
public static String getIdColumn(String name);
ParameterTypeDescription
nameStringLogical entity name.

Returns

  • Type: String
  • Description: The database column backing the ID field.

Released under the EPL-2.0 License.