Package step.core.accessors
Class AbstractCRUDAccessor<T extends AbstractIdentifiableObject>
- java.lang.Object
-
- step.core.accessors.AbstractAccessor
-
- step.core.accessors.AbstractCRUDAccessor<T>
-
- All Implemented Interfaces:
Accessor<T>
,CRUDAccessor<T>
- Direct Known Subclasses:
ControllerSettingAccessorImpl
,ExecutionAccessorImpl
,ExecutionTaskAccessorImpl
,FunctionAccessorImpl
,PlanAccessorImpl
,ReportNodeAccessorImpl
,ResourceAccessorImpl
,ResourceRevisionAccessorImpl
,ScreenInputAccessorImpl
,StagingContextAccessorImpl
,UserAccessorImpl
,ViewModelAccessorImpl
public class AbstractCRUDAccessor<T extends AbstractIdentifiableObject> extends AbstractAccessor implements CRUDAccessor<T>
-
-
Field Summary
Fields Modifier and Type Field Description protected org.jongo.MongoCollection
collection
-
Fields inherited from class step.core.accessors.AbstractAccessor
mongoClientSession
-
-
Constructor Summary
Constructors Constructor Description AbstractCRUDAccessor(MongoClientSession clientSession, String collectionName, Class<T> entityClass)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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 idIterator<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 String
queryByAttributes(Map<String,String> attributes)
protected String
queryByAttributes(Map<String,String> attributes, String attributesMapKey)
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.-
Methods inherited from class step.core.accessors.AbstractAccessor
createOrUpdateCompoundIndex, createOrUpdateIndex, createOrUpdateTTLIndex, getJongoCollection, getMongoCollection
-
-
-
-
Constructor Detail
-
AbstractCRUDAccessor
public AbstractCRUDAccessor(MongoClientSession clientSession, String collectionName, Class<T> entityClass)
-
-
Method Detail
-
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
-
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
-
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
-
queryByAttributes
protected String queryByAttributes(Map<String,String> attributes, String attributesMapKey)
-
getAll
public Iterator<T> getAll()
- Specified by:
getAll
in interfaceAccessor<T extends AbstractIdentifiableObject>
-
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
-
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
-
-