Interface ObjectCRUDHandler

    • Method Detail

      • load

        <T> T load​(java.lang.String id,
                   Context ctx)
            throws ObjectNotFoundException
        Gets an object instance by it's id.
        Parameters:
        id - for which the object is needed
        ctx - context specifying the loaded attributes of the returned object as well as application settings
        Returns:
        the object instance for given id loaded with attributes defined in context
        Throws:
        ObjectNotFoundException - if no object with the given id could be found
      • delete

        <T> void delete​(T object,
                        Context ctx)
                 throws ObjectDeletionException
        Deletes given object from the system.
        Parameters:
        object - which should get deleted
        ctx - context specifying application settings
        Throws:
        ObjectDeletionException - if the given object could not be deleted
      • delete

        default <T> ObjectFacadeOperationResult<T> delete​(java.util.Collection<T> objects,
                                                          Context ctx)
        Deletes many given objects from the system.
        Default implementation calls delete(Object, Context) in a loop and does not publish OBJECTS_DELETED_EVENT event.
        Parameters:
        objects - which should get deleted
        ctx -
        Returns:
        Result of the operation containing both successful and failed objects. Should never be null.
      • create

        <T> T create​(java.lang.String typeId,
                     Context ctx)
              throws ObjectCreationException
        Creates a new object in the system using given object data.
        Parameters:
        typeId - the data for creation of object in system
        ctx - context specifying the loaded attributes of the returned object as well as application settings
        Returns:
        the created object with attributes loaded as specified in context
        Throws:
        ObjectCreationException - if the object couldn't be created, like an object with the specified id already exists
      • save

        <T> T save​(T object,
                   Context ctx)
            throws ObjectSavingException
        Persist an object by given object data.
        Parameters:
        object - the data for updating an object in system
        ctx - context specifying the loaded attributes of the returned object as well as application settings
        Returns:
        the updated object
        Throws:
        ObjectSavingException - if the object couldn't be persisted, like a unique attribute was updated to be non-unique
      • save

        default <T> ObjectFacadeOperationResult<T> save​(java.util.Collection<T> objects,
                                                        Context ctx)
        Persist objects by given collection data.
        Parameters:
        objects - the data for updating objects in system.
        ctx - context specifying the loaded attributes of the returned object as well as application settings.
        Returns:
        ObjectFacadeOperationResult object.
      • reload

        <T> T reload​(T object,
                     Context ctx)
              throws ObjectNotFoundException
        Gets a fresh instance of the given object. Usually it re-fetches a domain object from the persistence layer, but could also just return the same instance, if the object is not managed.
        Parameters:
        object - The object that should be refreshed.
        ctx - context specifying the loaded attributes of the returned object as well as application settings
        Returns:
        A new instance of the given object, or the object itself, if it's not managed.
        Throws:
        ObjectNotFoundException - If the current object couldn't be found (could be deleted in the mean time).
      • reload

        default <T> ObjectFacadeOperationResult<T> reload​(java.util.Collection<T> objects,
                                                          Context ctx)
        Gets a fresh instance of the given collection of objects. Usually it re-fetches a domain object from the persistence layer, but could also just return the same instance, if the object is not managed. If an item in collection couldn't be found (could be deleted in the mean time) then item won't be added to collection
        Parameters:
        objects - The collection of object that should be refreshed.
        ctx - context specifying the loaded attributes of the returned object as well as application settings
        Returns:
        Two collections: one with objects that succeeded reloading (new instances of the given objects, or the object itself, if it's not managed) and second collection with objects that failed to be reloaded.
      • isNew

        default <T> boolean isNew​(T object)
        Tells if an object has been created and has not been saved yet.
        Type Parameters:
        T - object type.
        Parameters:
        object - the object to check.
        Returns:
        true if an object has been created and has not been saved yet.
      • isModified

        default <T> boolean isModified​(T object)
        Tells if an object is not persisted or has unsaved changes.
        Type Parameters:
        T - object type.
        Parameters:
        object - the object to check.
        Returns:
        true if an object has been modified.
      • isDeleted

        default <T> boolean isDeleted​(T object)
        Tells if an object was once persisted, but now is deleted
        Type Parameters:
        T - object type.
        Parameters:
        object - the object to check.
        Returns:
        true if an object has been deleted
      • clone

        default <T> T clone​(T objectToClone,
                            Context ctx)
                     throws ObjectCloningException
        Clone an object by given object data.
        Parameters:
        objectToClone - - source object to be cloned.
        ctx - context specifying the loaded attributes of the returned object as well as application settings.
        Returns:
        ObjectFacadeOperationResult object.
        Throws:
        ObjectCloningException - if cannot perform the clone.
      • getObjectId

        default <T> java.lang.Object getObjectId​(T object)
        Parameters:
        object - The object which identifier should be returned
        Returns:
        object identifier