Package step.core.accessors
Class LayeredCRUDAccessor<T extends AbstractIdentifiableObject>
- java.lang.Object
-
- step.core.accessors.LayeredCRUDAccessor<T>
-
- All Implemented Interfaces:
Accessor<T>
,CRUDAccessor<T>
- Direct Known Subclasses:
LayeredFunctionAccessor
,LayeredPlanAccessor
public class LayeredCRUDAccessor<T extends AbstractIdentifiableObject> extends Object implements CRUDAccessor<T>
-
-
Constructor Summary
Constructors Constructor Description LayeredCRUDAccessor()
LayeredCRUDAccessor(List<? extends CRUDAccessor<T>> accessors)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addAccessor(CRUDAccessor<T> accessor)
T
findByAttributes(Map<String,String> attributes)
Find an object by default attributes.T
findByAttributes(Map<String,String> attributes, String attributesMapKey)
Find an object by attributes.Spliterator<T>
findManyByAttributes(Map<String,String> attributes)
Find objects by attributes.Spliterator<T>
findManyByAttributes(Map<String,String> attributes, String attributesMapKey)
Find objects by attributes.T
get(String id)
Get an object by idT
get(org.bson.types.ObjectId id)
Get an object by idprotected CRUDAccessor<T>
getAccessorForPersistence()
Iterator<T>
getAll()
List<T>
getRange(int skip, int limit)
Get the range of objects specified by the skip/limit parameters browsing the collection sorted by ID in the descending orderprotected <V> V
layeredLookup(Function<CRUDAccessor<T>,V> f)
protected <V> Spliterator<V>
layeredMerge(Function<CRUDAccessor<T>,Spliterator<V>> f)
void
pushAccessor(CRUDAccessor<T> accessor)
void
remove(org.bson.types.ObjectId id)
void
save(Collection<? extends T> entities)
Save a list of entities.T
save(T entity)
Save an entity.
-
-
-
Constructor Detail
-
LayeredCRUDAccessor
public LayeredCRUDAccessor()
-
LayeredCRUDAccessor
public LayeredCRUDAccessor(List<? extends CRUDAccessor<T>> accessors)
-
-
Method Detail
-
addAccessor
public void addAccessor(CRUDAccessor<T> accessor)
-
pushAccessor
public void pushAccessor(CRUDAccessor<T> accessor)
-
get
public T get(org.bson.types.ObjectId id)
Description copied from interface:Accessor
Get an object by id- Specified by:
get
in interfaceAccessor<T extends AbstractIdentifiableObject>
- Parameters:
id
- the UID of the object- Returns:
- the object
-
layeredLookup
protected <V> V layeredLookup(Function<CRUDAccessor<T>,V> f)
-
get
public T get(String id)
Description copied from interface:Accessor
Get an object by id- Specified by:
get
in interfaceAccessor<T extends AbstractIdentifiableObject>
- Parameters:
id
- the UID of the object- Returns:
- the object
-
findByAttributes
public T findByAttributes(Map<String,String> attributes)
Description copied from interface:Accessor
Find an object by default attributes. If multiple objects match these attributes, the first one will be returned- Specified by:
findByAttributes
in interfaceAccessor<T extends AbstractIdentifiableObject>
- Parameters:
attributes
- the map of mandatory attributes of the object to be found- Returns:
- the object
-
findManyByAttributes
public Spliterator<T> findManyByAttributes(Map<String,String> attributes)
Description copied from interface:Accessor
Find objects by attributes.- Specified by:
findManyByAttributes
in interfaceAccessor<T extends AbstractIdentifiableObject>
- Parameters:
attributes
- the map of mandatory attributes of the object to be found- Returns:
- an
Iterator
for the objects found
-
layeredMerge
protected <V> Spliterator<V> layeredMerge(Function<CRUDAccessor<T>,Spliterator<V>> f)
-
getAll
public Iterator<T> getAll()
- Specified by:
getAll
in interfaceAccessor<T extends AbstractIdentifiableObject>
-
findByAttributes
public T findByAttributes(Map<String,String> attributes, String attributesMapKey)
Description copied from interface:Accessor
Find an object by attributes. If multiple objects match these attributes, the first one will be returned- Specified by:
findByAttributes
in interfaceAccessor<T extends AbstractIdentifiableObject>
- Parameters:
attributes
- the map of mandatory attributes of the object to be foundattributesMapKey
- the string representing the name (or "key") of the attribute map- Returns:
- the object
-
findManyByAttributes
public Spliterator<T> findManyByAttributes(Map<String,String> attributes, String attributesMapKey)
Description copied from interface:Accessor
Find objects by attributes.- Specified by:
findManyByAttributes
in interfaceAccessor<T extends AbstractIdentifiableObject>
- Parameters:
attributes
- the map of mandatory attributes of the object to be foundattributesMapKey
- the string representing the name (or "key") of the attribute map- Returns:
- an
Iterator
for the objects found
-
getRange
public List<T> getRange(int skip, int limit)
Description copied from interface:Accessor
Get the range of objects specified by the skip/limit parameters browsing the collection sorted by ID in the descending order- Specified by:
getRange
in interfaceAccessor<T extends AbstractIdentifiableObject>
- Parameters:
skip
- the start index (inclusive) of the rangelimit
- the size of the range- Returns:
- a
List
containing the objects of the specified range
-
remove
public void remove(org.bson.types.ObjectId id)
- Specified by:
remove
in interfaceCRUDAccessor<T extends AbstractIdentifiableObject>
-
save
public T save(T entity)
Description copied from interface:CRUDAccessor
Save an entity. If an entity with the same id exists, it will be updated otherwise inserted.- Specified by:
save
in interfaceCRUDAccessor<T extends AbstractIdentifiableObject>
- Parameters:
entity
- the entity instance to be saved- Returns:
- the saved entity
-
save
public void save(Collection<? extends T> entities)
Description copied from interface:CRUDAccessor
Save a list of entities.- Specified by:
save
in interfaceCRUDAccessor<T extends AbstractIdentifiableObject>
- Parameters:
entities
- the list of entities to be saved
-
getAccessorForPersistence
protected CRUDAccessor<T> getAccessorForPersistence()
-
-