Interface EntityFactory


  • public interface EntityFactory
    EntityFactory interface
    Author:
    bramk, bartk
    • Method Detail

      • find

        <T> T find​(WmId primaryKey,
                   Class<T> entityClass,
                   PersistenceContext persistenceContext)
        Looks up an entity by its id
        Type Parameters:
        T - entity type.
        Parameters:
        primaryKey - the id identifying the entity to load
        entityClass - class of the entity.
        persistenceContext - persistence context for the operation.
        Returns:
        the requested entity or null if it wasn't found
      • find

        Object find​(WmId primaryKey,
                    String entityClassname,
                    PersistenceContext persistenceContext)
        Looks up an entity by its id
        Parameters:
        primaryKey - the id identifying the entity to load
        entityClassname - classname of the entity to load
        persistenceContext -
        Returns:
        the requested entity or null if it wasn't found
      • persist

        <T> T persist​(T entity,
                      PersistenceContext persistenceContext)
        Persists an entity which is not yet persisted (i.e. which doesn't have its' WmId filled in yet)
        Type Parameters:
        T - The type of the entity to persist
        Parameters:
        entity - The entity to persist
        persistenceContext -
        Returns:
        The persisted entity with its WmId filled in.
      • copy

        <T> T copy​(T entity,
                   PersistenceContext persistenceContext)
        Copies an entity and the entire tree of its children. This method traverses all @Child relations.
        Type Parameters:
        T - The type of the entity to copy
        Parameters:
        entity - The entity to copy
        persistenceContext -
        Returns:
        The copied entity.
      • delete

        void delete​(Object entity,
                    PersistenceContext persistenceContext)
             throws DomainException
        Deletes an entity from the persistence backend
        Parameters:
        entity - The entity to be deleted
        persistenceContext -
        Throws:
        DomainException - when something went wrong while deleting the entity
      • save

        <T> T save​(T entity,
                   PersistenceContext persistenceContext)
            throws DomainException
        Saves an entity that was persisted before (i.e. which does have its' WmId filled in)
        Type Parameters:
        T - The type of the entity to persist
        Parameters:
        entity - The entity to persist
        persistenceContext -
        Returns:
        The entity
        Throws:
        DomainException - when something went wrong while saving the entity
      • getAll

        <T> Set<T> getAll​(Class<T> entity,
                          PersistenceContext persistenceContext)
        Returns all entities of the specified type.
        Type Parameters:
        T - type of the entity.
        Parameters:
        entity - the Class of the requested type
        persistenceContext - persistence context for the operation.
        Returns:
        set of all entities of the given type.
      • getInstance

        <T> T getInstance​(Class<T> entityClass)
        Returns a newly created instance of the requested Class or an instance implementing the requested interface if the Class is an interface. In order to persist such an entity, invoke the persist() method.
        Type Parameters:
        T - The type of Class to instantiate
        Parameters:
        entityClass - The Class to get an instance of (is generally the interface of the required Class)
        Returns:
        a newly created instance of the requested Class
      • getInstance

        Object getInstance​(String entityClassname)
        Returns a newly created instance of the requested Class or an instance implementing the requested interface if the Class is an interface. In order to persist such an entity, invoke the persist() method.
        Parameters:
        entityClassname - The Class to get an instance of (is generally the interface of the required Class)
        Returns:
        a newly created instance of the requested Class
      • listEntityDefinitions

        List<EntityDefinition> listEntityDefinitions()
        Return the list of EntityDefinitions for this factory.
        Returns:
      • setComponent

        void setComponent​(Component component)
        Sets the component for which this entity factory is created
        Parameters:
        component - component for which this entity factory is created
      • getComponent

        Component getComponent()
        Gets the component for which this entity factory was created
        Returns:
        component for which this entity factory was created
      • getEntityDomainClassName

        String getEntityDomainClassName()
        Gets the classname for the EntityDomain to register with
        Returns:
        the classname of a class implementing EntityDomain
      • removeProperty

        <T> void removeProperty​(T entity,
                                String property,
                                PersistenceContext context)
        Remove named property from the persistent image of the given entity.
        Type Parameters:
        T - type of the entity.
        Parameters:
        entity - entity for property removal.
        property - name of the property to remove.
        context - persistence context.