Package com.axelor.db

Interface Repository<T extends Model>

Type Parameters:
T - the domain model type the repository manages
All Known Implementing Classes:
AbstractMetaJsonModelRepository, AbstractMFARepository, AbstractUserRepository, AbstractUserTokenRepository, AuditLogRepository, DMSFileRepository, DMSFileTagRepository, DMSPermissionRepository, GroupRepository, JpaRepository, MailAddressRepository, MailFlagsRepository, MailFollowerRepository, MailMessageRepository, MetaActionMenuRepository, MetaActionRepository, MetaAttachmentRepository, MetaAttrsRepository, MetaEnumRepository, MetaFieldRepository, MetaFileRepository, MetaFilterRepository, MetaHelpRepository, MetaJsonFieldRepository, MetaJsonModelRepository, MetaJsonRecordRepository, MetaMenuRepository, MetaModelRepository, MetaModuleRepository, MetaPermissionRepository, MetaPermissionRuleRepository, MetaScheduleParamRepository, MetaScheduleRepository, MetaSelectItemRepository, MetaSelectRepository, MetaSequenceRepository, MetaThemeRepository, MetaTranslationRepository, MetaViewCustomRepository, MetaViewRepository, MFARepository, PasswordResetTokenRepository, PermissionRepository, RoleRepository, TeamRepository, TeamTaskRepository, TeamTopicRepository, UserRepository, UserTokenRepository

public interface Repository<T extends Model>
The repository interface defines common data access methods.
  • Method Summary

    Modifier and Type
    Method
    Description
    all()
    Get the Query instance of the managed domain class.
    copy(T entity, boolean deep)
    Create a duplicate copy of the given entity.

    In case of deep copy, one-to-many records are duplicated.
    Create a new instance of the domain model with the given default values.
    Return list of properties on the domain model managed by this repository.
    find(Long id)
    Finds an entity by its primary key.
    Finds an entity by its primary key.
    Find multiple entities by their primary key.
    void
    Synchronize the persistence context to the underlying database.
    Retrieves a reference (proxy) to an entity instance with the specified ID without immediately loading its state from the database.
    Populate the given json map with additional data.
    void
    refresh(T entity)
    Refresh the state of the instance from the database, overwriting changes made to the entity, if any.
    void
    remove(T entity)
    Remove the given entity.
    save(T entity)
    Save the given entity.
    Validate the given json map before persisting.
  • Method Details

    • fields

      List<Property> fields()
      Return list of properties on the domain model managed by this repository.
      Returns:
      list of Property
    • all

      Query<T> all()
      Get the Query instance of the managed domain class.
      Returns:
      instance of Query
    • create

      T create(Map<String,Object> values)
      Create a new instance of the domain model with the given default values.
      Parameters:
      values - the default values
      Returns:
      an instance of the domain model managed by this repository
    • copy

      T copy(T entity, boolean deep)
      Create a duplicate copy of the given entity.

      In case of deep copy, one-to-many records are duplicated. Otherwise, one-to-many records will be skipped.
      Parameters:
      entity - the entity bean to copy
      deep - whether to create a deep copy
      Returns:
      a copy of the given entity
    • find

      T find(Long id)
      Finds an entity by its primary key.
      Parameters:
      id - the entity id to load
      Returns:
      entity found by the given id, null otherwise
    • findById

      Optional<T> findById(Long id)
      Finds an entity by its primary key.
      Parameters:
      id - the entity id to load
      Returns:
      an Optional containing the found entity, or Optional#empty() if not found
    • findByIds

      List<T> findByIds(List<Long> ids)
      Find multiple entities by their primary key.

      WARNING: The list may contain NULL elements if an id was not found. The list size and order will match the input ids.

      Parameters:
      ids - The ids to load
      Returns:
      list of all the matched records
    • getReferenceById

      T getReferenceById(Long id)
      Retrieves a reference (proxy) to an entity instance with the specified ID without immediately loading its state from the database.

      This method delegates to EntityManager.getReference(Class, Object). It is designed for performance optimization, particularly when you need to associate an entity (set a foreign key) without the overhead of a database SELECT query.

      Note: The returned object is likely a dynamic proxy. The database will only be accessed when you invoke a method on the proxy (other than getting the ID). If the entity does not exist in the database, an EntityNotFoundException will be thrown at the time of that access, not at the time of calling this method.

      Parameters:
      id - the primary key of the entity
      Returns:
      a managed entity proxy instance with the state lazily fetched
      Throws:
      jakarta.persistence.EntityNotFoundException - if the entity state is accessed, and the entity does not exist in the database
      See Also:
      • EntityManager.getReference(Class, Object)
    • save

      T save(T entity)
      Save the given entity.

      Depending on the implementation, it may return same entity or a copy of it. For example JPA implementation may return a copy if the given entity can't be managed.

      Parameters:
      entity - the entity object to save
      Returns:
      an instance of the entity with saved state
    • remove

      void remove(T entity)
      Remove the given entity.
      Parameters:
      entity - the entity object
    • refresh

      void refresh(T entity)
      Refresh the state of the instance from the database, overwriting changes made to the entity, if any.
      Parameters:
      entity - the entity object to refresh
    • flush

      void flush()
      Synchronize the persistence context to the underlying database.
    • validate

      Map<String,Object> validate(Map<String,Object> json, Map<String,Object> context)
      Validate the given json map before persisting.

      This method is called before the json map is converted to model object.

      Parameters:
      json - the json map to validate
      context - the context
      Returns:
      validated json map
    • populate

      Map<String,Object> populate(Map<String,Object> json, Map<String,Object> context)
      Populate the given json map with additional data.

      This method is called before returning the json data as response.

      Parameters:
      json - the json map to populate
      context - the context
      Returns:
      the json map itself