Package io.jmix.core

Interface UnconstrainedDataManager

All Known Subinterfaces:
DataManager
All Known Implementing Classes:
DataManagerImpl, UnconstrainedDataManagerImpl

public interface UnconstrainedDataManager
Central interface to provide CRUD functionality for entities.

Delegates to DataStore implementations, handles references between entities from different stores.

Does not apply registered access constraints. If you want to perform CRUD operations with authorization, use DataManager instead.

  • Method Details

    • load

      @Nullable <E> E load(LoadContext<E> context)
      Loads a single entity instance.

      The depth of object graphs, starting from loaded instances, defined by FetchPlan object passed in LoadContext.

      Parameters:
      context - LoadContext object, defining what and how to load
      Returns:
      the loaded object, or null if not found
    • loadList

      <E> List<E> loadList(LoadContext<E> context)
      Loads collection of entity instances.

      The depth of object graphs, starting from loaded instances, defined by FetchPlan object passed in LoadContext.

      Parameters:
      context - LoadContext object, defining what and how to load
      Returns:
      a list of entity instances, or empty list if nothing found
    • getCount

      long getCount(LoadContext<?> context)
      Returns the number of entity instances for the given query passed in the LoadContext.
      Parameters:
      context - defines the query
      Returns:
      number of instances in the data store
    • save

      EntitySet save(SaveContext context)
      Saves a collection of entity instances to their data stores.
      Parameters:
      context - SaveContext object, containing entities and other information
      Returns:
      set of saved instances
    • save

      EntitySet save(Object... entities)
      Saves entities to their data stores.
      Parameters:
      entities - entities to save
      Returns:
      set of saved instances
    • save

      <E> E save(E entity)
      Saves the entity to its data store.
      Parameters:
      entity - entity instance
      Returns:
      saved instance
    • remove

      void remove(Object... entity)
      Removes the entities from their data stores.
      Parameters:
      entity - entity instance
    • remove

      <E> void remove(Id<E> entityId)
      Removes the entity instance from the data store by its id.
      Parameters:
      entityId - entity id
    • loadValues

      List<KeyValueEntity> loadValues(ValueLoadContext context)
      Loads list of key-value pairs.
      Parameters:
      context - defines a query for scalar values and a list of keys for returned KeyValueEntity
      Returns:
      list of KeyValueEntity instances
    • getCount

      long getCount(ValueLoadContext context)
      Returns the number of records for the given query passed in the ValueLoadContext.
      Parameters:
      context - defines the query
      Returns:
      number of records
    • load

      <E> FluentLoader<E> load(Class<E> entityClass)
      Entry point to the fluent API for loading entities.

      Usage examples:

       Customer customer = dataManager.load(Customer.class).id(someId).one();
      
       List<Customer> customers = dataManager.load(Customer.class)
            .query("select c from Customer c where c.name = :name")
            .parameter("name", "Smith")
            .maxResults(100)
            .list();
       
      Parameters:
      entityClass - class of the loaded entity
    • load

      <E> FluentLoader.ById<E> load(Id<E> entityId)
      Entry point to the fluent API for loading entities.

      Usage example:

       Customer customer = dataManager.load(customerId).one();
       
      Parameters:
      entityId - Id of the loaded entity
    • loadValues

      FluentValuesLoader loadValues(String queryString)
      Entry point to the fluent API for loading scalar values.

      Usage examples:

       List<KeyValueEntity> customerDataList = dataManager.loadValues(
                "select c.name, c.status from Customer c where c.name = :n")
            .properties("custName", "custStatus")
            .parameter("name", "Smith")
            .list();
      
       KeyValueEntity customerData = dataManager.loadValues(
                "select c.name, count(c) from Customer c group by c.name")
            .properties("custName", "custCount")
            .one();
       
      Parameters:
      queryString - query string
    • loadValue

      <T> FluentValueLoader<T> loadValue(String queryString, Class<T> valueClass)
      Entry point to the fluent API for loading a single scalar value.

      Terminal methods of this API (list, one and optional) return a single value from the first column of the query result set. You should provide the expected type of this value in the second parameter. Number types will be converted appropriately, so for example if the query returns Long and you expected Integer, the returned value will be automatically converted from Long to Integer.

      Usage examples:

       Long customerCount = dataManager.loadValue(
                "select count(c) from Customer c", Long.class).one();
       
      Parameters:
      queryString - query string
      valueClass - type of the returning value
    • create

      <T> T create(Class<T> entityClass)
      Creates a new entity instance in memory. This is a shortcut to Metadata.create().
      Parameters:
      entityClass - entity class
    • getReference

      <T> T getReference(Class<T> entityClass, Object id)
      Returns an entity instance which can be used as a reference to an object which exists in the data store.

      For example, if you are creating a User, you have to set a Group the user belongs to. If you know the group id, you could load it from the database and set to the user. This method saves you from unneeded database round trip:

       user.setGroup(dataManager.getReference(Group.class, groupId));
       dataManager.commit(user);
       
      A reference can also be used to delete an existing object by id:
       dataManager.remove(dataManager.getReference(Customer.class, customerId));
       
      Parameters:
      entityClass - entity class
      id - id of an existing object
    • getReference

      <T> T getReference(Id<T> entityId)
      Returns an entity instance which can be used as a reference to an object which exists in the data store.
      Parameters:
      entityId - id of an existing object
      See Also: