Class UnconstrainedDataManagerImpl

java.lang.Object
io.jmix.core.impl.UnconstrainedDataManagerImpl
All Implemented Interfaces:
UnconstrainedDataManager
Direct Known Subclasses:
DataManagerImpl

@Primary @Component("core_UnconstrainedDataManager") public class UnconstrainedDataManagerImpl extends Object implements UnconstrainedDataManager
  • Field Details

    • SAVE_TX_PREFIX

      public static final String SAVE_TX_PREFIX
      See Also:
    • txCount

      protected static final AtomicLong txCount
    • metadata

      @Autowired protected Metadata metadata
    • metadataTools

      @Autowired protected MetadataTools metadataTools
    • entityStates

      @Autowired protected EntityStates entityStates
    • stores

      @Autowired protected Stores stores
    • dataStoreFactory

      @Autowired protected DataStoreFactory dataStoreFactory
    • fluentLoaderProvider

      @Autowired protected org.springframework.beans.factory.ObjectProvider<FluentLoader> fluentLoaderProvider
    • fluentValueLoaderProvider

      @Autowired protected org.springframework.beans.factory.ObjectProvider<FluentValueLoader> fluentValueLoaderProvider
    • fluentValuesLoaderProvider

      @Autowired protected org.springframework.beans.factory.ObjectProvider<FluentValuesLoader> fluentValuesLoaderProvider
    • crossDataStoreReferenceLoaderProvider

      @Autowired protected org.springframework.beans.factory.ObjectProvider<CrossDataStoreReferenceLoader> crossDataStoreReferenceLoaderProvider
    • extendedEntities

      @Autowired protected ExtendedEntities extendedEntities
    • properties

      @Autowired protected CoreProperties properties
    • transactionManagerLocator

      @Autowired protected TransactionManagerLocator transactionManagerLocator
  • Constructor Details

    • UnconstrainedDataManagerImpl

      public UnconstrainedDataManagerImpl()
  • Method Details

    • load

      @Nullable public <E> E load(LoadContext<E> context)
      Description copied from interface: UnconstrainedDataManager
      Loads a single entity instance.

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

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

      public <E> List<E> loadList(LoadContext<E> context)
      Description copied from interface: UnconstrainedDataManager
      Loads collection of entity instances.

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

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

      public long getCount(LoadContext<?> context)
      Description copied from interface: UnconstrainedDataManager
      Returns the number of entity instances for the given query passed in the LoadContext.
      Specified by:
      getCount in interface UnconstrainedDataManager
      Parameters:
      context - defines the query
      Returns:
      number of instances in the data store
    • save

      public EntitySet save(Object... entities)
      Description copied from interface: UnconstrainedDataManager
      Saves entities to their data stores.
      Specified by:
      save in interface UnconstrainedDataManager
      Parameters:
      entities - entities to save
      Returns:
      set of saved instances
    • save

      public <E> E save(E entity)
      Description copied from interface: UnconstrainedDataManager
      Saves the entity to its data store.
      Specified by:
      save in interface UnconstrainedDataManager
      Parameters:
      entity - entity instance
      Returns:
      saved instance
    • remove

      public void remove(Object... entities)
      Description copied from interface: UnconstrainedDataManager
      Removes the entities from their data stores.
      Specified by:
      remove in interface UnconstrainedDataManager
      Parameters:
      entities - entity instance
    • remove

      public <E> void remove(Id<E> entityId)
      Description copied from interface: UnconstrainedDataManager
      Removes the entity instance from the data store by its id.
      Specified by:
      remove in interface UnconstrainedDataManager
      Parameters:
      entityId - entity id
    • save

      public EntitySet save(SaveContext context)
      Description copied from interface: UnconstrainedDataManager
      Saves a collection of entity instances to their data stores.
      Specified by:
      save in interface UnconstrainedDataManager
      Parameters:
      context - SaveContext object, containing entities and other information
      Returns:
      set of saved instances
    • createTransactionDefinition

      protected org.springframework.transaction.TransactionDefinition createTransactionDefinition(boolean isJoinTransaction)
    • saveContextToStore

      protected Set saveContextToStore(String store, SaveContext context)
    • loadValues

      public List<KeyValueEntity> loadValues(ValueLoadContext context)
      Description copied from interface: UnconstrainedDataManager
      Loads list of key-value pairs.
      Specified by:
      loadValues in interface UnconstrainedDataManager
      Parameters:
      context - defines a query for scalar values and a list of keys for returned KeyValueEntity
      Returns:
      list of KeyValueEntity instances
    • getCount

      public long getCount(ValueLoadContext context)
      Description copied from interface: UnconstrainedDataManager
      Returns the number of records for the given query passed in the ValueLoadContext.
      Specified by:
      getCount in interface UnconstrainedDataManager
      Parameters:
      context - defines the query
      Returns:
      number of records
    • load

      public <E> FluentLoader<E> load(Class<E> entityClass)
      Description copied from interface: UnconstrainedDataManager
      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 sample$Customer c where c.name = :name")
            .parameter("name", "Smith")
            .fetchPlan("customer-fetch-plan")
            .list();
       
      Specified by:
      load in interface UnconstrainedDataManager
      Parameters:
      entityClass - class of entity that needs to be loaded
    • load

      public <E> FluentLoader.ById<E> load(Id<E> entityId)
      Description copied from interface: UnconstrainedDataManager
      Entry point to the fluent API for loading entities.

      Usage example:

       Customer customer = dataManager.load(customerId).fetchPlan("with-grade").one();
       
      Specified by:
      load in interface UnconstrainedDataManager
      Parameters:
      entityId - Id of entity that needs to be loaded
    • loadValues

      public FluentValuesLoader loadValues(String queryString)
      Description copied from interface: UnconstrainedDataManager
      Entry point to the fluent API for loading scalar values.

      Usage examples:

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

      public <T> FluentValueLoader<T> loadValue(String queryString, Class<T> valueClass)
      Description copied from interface: UnconstrainedDataManager
      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 sample$Customer c", Long.class).one();
       
      Specified by:
      loadValue in interface UnconstrainedDataManager
      Parameters:
      queryString - query string
      valueClass - type of the returning value
    • createSaveContext

      protected SaveContext createSaveContext(SaveContext context)
    • create

      public <T> T create(Class<T> entityClass)
      Description copied from interface: UnconstrainedDataManager
      Creates a new entity instance in memory. This is a shortcut to Metadata.create().
      Specified by:
      create in interface UnconstrainedDataManager
      Parameters:
      entityClass - entity class
    • getReference

      public <T> T getReference(Class<T> entityClass, Object id)
      Description copied from interface: UnconstrainedDataManager
      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));
       
      Specified by:
      getReference in interface UnconstrainedDataManager
      Parameters:
      entityClass - entity class
      id - id of an existing object
    • getReference

      public <T> T getReference(Id<T> entityId)
      Description copied from interface: UnconstrainedDataManager
      Returns an entity instance which can be used as a reference to an object which exists in the data store.
      Specified by:
      getReference in interface UnconstrainedDataManager
      Parameters:
      entityId - id of an existing object
      See Also:
    • writeCrossDataStoreReferences

      protected boolean writeCrossDataStoreReferences(Object entity, Collection<Object> allEntities)
    • readCrossDataStoreReferences

      protected void readCrossDataStoreReferences(Collection<?> entities, FetchPlan fetchPlan, MetaClass metaClass, boolean joinTransaction)
    • getStoreName

      protected String getStoreName(MetaClass metaClass)
    • getStoreName

      protected String getStoreName(@Nullable String storeName)
    • getEffectiveMetaClassFromContext

      protected <E> MetaClass getEffectiveMetaClassFromContext(LoadContext<E> context)
    • mergeConstraints

      protected List<AccessConstraint<?>> mergeConstraints(List<AccessConstraint<?>> accessConstraints)
    • getAppliedConstraints

      protected List<AccessConstraint<?>> getAppliedConstraints()