Class GenericDaoUtils


  • public class GenericDaoUtils
    extends Object
    Utility class for working with entities
    Author:
    XIMA MEDIA GmbH
    • Method Detail

      • getIdsFromUUIDStrings

        public static final List<Long> getIdsFromUUIDStrings​(IEntityContext ec,
                                                             List<String> strUuids,
                                                             Object context,
                                                             Class<?> entityClass)
        Translates the list of UUID strings to a list of IDs
        Parameters:
        ec - IEntityContext to use
        strUuids - List entity UUID strings
        context - Object entity to use as context
        entityClass - Class of the entities
        Returns:
        List of entity IDs
      • getIdsFromUUIDs

        public static final List<Long> getIdsFromUUIDs​(IEntityContext ec,
                                                       List<UUID> uuids,
                                                       Object context,
                                                       Class<?> entityClass)
        Translates the list of UUIDs to a list of IDs
        Parameters:
        ec - IEntityContext to use
        uuids - List entity UUIDs
        context - Object entity to use as context
        entityClass - Class of the entities
        Returns:
        List of entity IDs. If no entity could be found for a UUID in the list, it will be omitted.
      • getIdFromUUID

        public static final Long getIdFromUUID​(IEntityContext ec,
                                               UUID uuid,
                                               Object context,
                                               Class<?> entityClass)
        Translates an entity UUID to its corresponding ID if it exists
        Parameters:
        ec - IEntityContext to use
        uuid - String entity UUID
        context - Object entity to use as context
        entityClass - Class of the entity
        Returns:
        Long ID of the entity if it exists. Otherwise null
      • getEntity

        public static final <T extends de.xima.cmn.dao.interfaces.IEntity<Long>> T getEntity​(IEntityContext ec,
                                                                                             UUID uuid,
                                                                                             Object context,
                                                                                             Class<T> entityClass)
        Gets the entity with the given UUID in the given context
        Type Parameters:
        T - the entity type
        Parameters:
        ec - IEntityContext to use
        uuid - String entity UUID
        context - Object entity to use as context
        entityClass - Class of the entity
        Returns:
        the found entity
      • getEntity

        public static final <T extends de.xima.cmn.dao.interfaces.IEntity<Long>> T getEntity​(IEntityContext ec,
                                                                                             String name,
                                                                                             Object context,
                                                                                             Class<T> entityClass)
        Gets the entity with the given name in the given context
        Type Parameters:
        T - the entity type
        Parameters:
        ec - IEntityContext to use
        name - String entity UUID
        context - Object entity to use as context
        entityClass - Class of the entity
        Returns:
        the found entity
      • getUuidContextValue

        public static final Object getUuidContextValue​(de.xima.cmn.dao.interfaces.IEntity<Long> contextEntity,
                                                       Class<?> entityClass)
      • loadPersistedEntity

        public static final <T extends de.xima.cmn.dao.interfaces.IEntity<Long>> T loadPersistedEntity​(IEntityContext ec,
                                                                                                       T entity)
        Returns entity that is persisted in the database (fully initialized) based on its UUID and CONTEXT (client, project, ...)
        Type Parameters:
        T - IEntity base entity interface
        Parameters:
        ec - IEntityContext to be used
        entity - IEntity to check if it exists in the database
        Returns:
        IEntity that is persisted in the database or null if none could be found
      • merge

        @Deprecated
        public static final <T extends de.xima.cmn.dao.interfaces.IEntity<Long>> T merge​(IEntityContext ec,
                                                                                         T entity,
                                                                                         T persisted)
        Deprecated.
      • syncEntities

        public static final void syncEntities​(de.xima.cmn.dao.interfaces.IEntity<Long> entity,
                                              de.xima.cmn.dao.interfaces.IEntity<Long> persisted)
      • syncEntities

        public static final <T extends de.xima.cmn.dao.interfaces.IEntity<Long>> T syncEntities​(IEntityContext ec,
                                                                                                T entity,
                                                                                                T persisted)
      • withTransaction

        public static <T,​E extends Throwable> T withTransaction​(IEntityContext ec,
                                                                      ITypedThrowingSupplier<T,​E> action)
                                                               throws E extends Throwable
        Invokes the given action within the context of a transaction. Starts a new transaction if none is active, then invokes the given action. When the action completes successfully, the transaction is committed. If an exception is thrown, the transaction is rolled back, and the exception is rethrown.
        Type Parameters:
        T - Type of the value returned by the action.
        E - Type of the exception that can be thrown by the action.
        Parameters:
        ec - Entity context for database operations.
        action - Action to be executed within the transaction.
        Returns:
        The result of the action.
        Throws:
        E - Exception thrown by the action.
        E extends Throwable