Interface ObjectCRUDHandler
-
- All Known Subinterfaces:
ObjectFacade,ObjectFacadeStrategy
- All Known Implementing Classes:
DefaultObjectFacade,PermissionAwareObjectFacade
public interface ObjectCRUDHandlerInterface providing methods for basic CRUD operations. Don't implement this interface directly but use one of its sub-interfaces.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringOBJECT_CREATED_EVENTstatic java.lang.StringOBJECTS_DELETED_EVENTstatic java.lang.StringOBJECTS_UPDATED_EVENT
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default <T> Tclone(T objectToClone, Context ctx)Clone an object by given object data.<T> Tcreate(java.lang.String typeId, Context ctx)Creates a new object in the system using given object data.default <T> ObjectFacadeOperationResult<T>delete(java.util.Collection<T> objects, Context ctx)Deletes many given objects from the system.
Default implementation callsdelete(Object, Context)in a loop and does not publishOBJECTS_DELETED_EVENTevent.<T> voiddelete(T object, Context ctx)Deletes given object from the system.default <T> java.lang.ObjectgetObjectId(T object)default <T> booleanisDeleted(T object)Tells if an object was once persisted, but now is deleteddefault <T> booleanisModified(T object)Tells if an object is not persisted or has unsaved changes.default <T> booleanisNew(T object)Tells if an object has been created and has not been saved yet.<T> Tload(java.lang.String id, Context ctx)Gets an object instance by it's id.default <T> ObjectFacadeOperationResult<T>reload(java.util.Collection<T> objects, Context ctx)Gets a fresh instance of the given collection of objects.<T> Treload(T object, Context ctx)Gets a fresh instance of the given object.default <T> ObjectFacadeOperationResult<T>save(java.util.Collection<T> objects, Context ctx)Persist objects by given collection data.<T> Tsave(T object, Context ctx)Persist an object by given object data.
-
-
-
Field Detail
-
OBJECTS_DELETED_EVENT
static final java.lang.String OBJECTS_DELETED_EVENT
- See Also:
- Constant Field Values
-
OBJECT_CREATED_EVENT
static final java.lang.String OBJECT_CREATED_EVENT
- See Also:
- Constant Field Values
-
OBJECTS_UPDATED_EVENT
static final java.lang.String OBJECTS_UPDATED_EVENT
- See Also:
- Constant Field Values
-
-
Method Detail
-
load
<T> T load(java.lang.String id, Context ctx) throws ObjectNotFoundExceptionGets an object instance by it's id.- Parameters:
id- for which the object is neededctx- 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 ObjectDeletionExceptionDeletes given object from the system.- Parameters:
object- which should get deletedctx- 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 callsdelete(Object, Context)in a loop and does not publishOBJECTS_DELETED_EVENTevent.- Parameters:
objects- which should get deletedctx-- 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 ObjectCreationExceptionCreates a new object in the system using given object data.- Parameters:
typeId- the data for creation of object in systemctx- 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 ObjectSavingExceptionPersist an object by given object data.- Parameters:
object- the data for updating an object in systemctx- 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 ObjectNotFoundExceptionGets 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 ObjectCloningExceptionClone 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
-
-