Class CRUDServiceImpl<KeyType extends java.io.Serializable,ValueType extends Timestamped<KeyType>>
- java.lang.Object
-
- ca.corefacility.bioinformatics.irida.service.impl.CRUDServiceImpl<KeyType,ValueType>
-
- Type Parameters:
KeyType
- Key in the database for the type storedValueType
- Type of object stored by this service
- All Implemented Interfaces:
CRUDService<KeyType,ValueType>
- Direct Known Subclasses:
AnalysisServiceImpl
,AnalysisSubmissionServiceImpl
,AnnouncementServiceImpl
,GenomeAssemblyServiceImpl
,IridaClientDetailsServiceImpl
,MetadataTemplateServiceImpl
,NcbiExportSubmissionServiceImpl
,PasswordResetServiceImpl
,ProjectEventServiceImpl
,ProjectServiceImpl
,ProjectSubscriptionServiceImpl
,ReferenceFileServiceImpl
,RemoteAPIServiceImpl
,SampleServiceImpl
,SequencingObjectServiceImpl
,SequencingRunServiceImpl
,UserGroupServiceImpl
,UserServiceImpl
,WorkflowNamedParametersServiceImpl
public class CRUDServiceImpl<KeyType extends java.io.Serializable,ValueType extends Timestamped<KeyType>> extends java.lang.Object implements CRUDService<KeyType,ValueType>
A universal CRUD service for all types. Specialized services should extend this class to get basic CRUD methods for free.
-
-
Field Summary
Fields Modifier and Type Field Description protected static java.lang.String
CREATED_DATE_SORT_PROPERTY
protected IridaJpaRepository<ValueType,KeyType>
repository
protected javax.validation.Validator
validator
protected java.lang.Class<ValueType>
valueType
-
Constructor Summary
Constructors Constructor Description CRUDServiceImpl(IridaJpaRepository<ValueType,KeyType> repository, javax.validation.Validator validator, java.lang.Class<ValueType> valueType)
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description long
count()
How many entities ofType
exist in the database?ValueType
create(ValueType object)
Create a new object in the persistence store.void
delete(KeyType id)
Delete the object with the specified identifier from the database.java.lang.Boolean
exists(KeyType id)
Check to see if an identifier forType
exists in the database.java.lang.Iterable<ValueType>
findAll()
List all objects ofType
in the database.org.springframework.data.history.Revisions<java.lang.Integer,ValueType>
findRevisions(KeyType id)
Find all of the revisions for the specified identifier.org.springframework.data.domain.Page<org.springframework.data.history.Revision<java.lang.Integer,ValueType>>
findRevisions(KeyType id, org.springframework.data.domain.Pageable pageable)
Returns aPage
of revisions for the entity with the given id.org.springframework.data.domain.Page<ValueType>
list(int page, int size, org.springframework.data.domain.Sort sort)
List objects ofType
in the database, limited to some specific pageorg.springframework.data.domain.Page<ValueType>
list(int page, int size, org.springframework.data.domain.Sort.Direction order)
List objects ofType
in the database, limited to some specific page, ordered by calling thecompareTo
method on the class.org.springframework.data.domain.Page<ValueType>
list(int page, int size, org.springframework.data.domain.Sort.Direction order, java.lang.String... sortProperties)
List objects ofType
in the database, limited to some specific page.ValueType
read(KeyType id)
Read the object type by unique identifier.java.lang.Iterable<ValueType>
readMultiple(java.lang.Iterable<KeyType> idents)
Read multiple objects by the given collection of identifiersorg.springframework.data.domain.Page<ValueType>
search(org.springframework.data.jpa.domain.Specification<ValueType> specification, int page, int size, org.springframework.data.domain.Sort.Direction order, java.lang.String... sortProperties)
Deprecated.org.springframework.data.domain.Page<ValueType>
search(org.springframework.data.jpa.domain.Specification<ValueType> specification, org.springframework.data.domain.Pageable pageRequest)
Search for an entity ofType
andPageRequest
ValueType
update(ValueType object)
Update an objectValueType
updateFields(KeyType id, java.util.Map<java.lang.String,java.lang.Object> updatedFields)
Update properties of the given object by given fields.java.util.List<ValueType>
updateMultiple(java.util.Collection<ValueType> objects)
Update multiple objects at once
-
-
-
Field Detail
-
CREATED_DATE_SORT_PROPERTY
protected static final java.lang.String CREATED_DATE_SORT_PROPERTY
- See Also:
- Constant Field Values
-
repository
protected final IridaJpaRepository<ValueType extends Timestamped<KeyType>,KeyType extends java.io.Serializable> repository
-
validator
protected final javax.validation.Validator validator
-
valueType
protected final java.lang.Class<ValueType extends Timestamped<KeyType>> valueType
-
-
Constructor Detail
-
CRUDServiceImpl
public CRUDServiceImpl(IridaJpaRepository<ValueType,KeyType> repository, javax.validation.Validator validator, java.lang.Class<ValueType> valueType)
-
-
Method Detail
-
create
@Transactional public ValueType create(ValueType object) throws javax.validation.ConstraintViolationException, EntityExistsException
Create a new object in the persistence store.- Specified by:
create
in interfaceCRUDService<KeyType extends java.io.Serializable,ValueType extends Timestamped<KeyType>>
- Parameters:
object
- The object to persist.- Returns:
- The object as it was persisted in the database. May modify the identifier of the object when returned.
- Throws:
javax.validation.ConstraintViolationException
- If the object being persisted cannot be validated by validation rules associated with the object.EntityExistsException
- If the object being persisted violates uniqueness constraints in the database.
-
read
@Transactional(readOnly=true) public ValueType read(KeyType id) throws EntityNotFoundException
Read the object type by unique identifier.- Specified by:
read
in interfaceCRUDService<KeyType extends java.io.Serializable,ValueType extends Timestamped<KeyType>>
- Parameters:
id
- The unique identifier for this object.- Returns:
- The object corresponding to the unique identifier.
- Throws:
EntityNotFoundException
- If the identifier does not exist in the database.
-
delete
@Transactional public void delete(KeyType id) throws EntityNotFoundException
Delete the object with the specified identifier from the database.- Specified by:
delete
in interfaceCRUDService<KeyType extends java.io.Serializable,ValueType extends Timestamped<KeyType>>
- Parameters:
id
- The identifier of the object to delete.- Throws:
EntityNotFoundException
- If no object with the specified identifier exists in the database.
-
findAll
@Transactional(readOnly=true) public java.lang.Iterable<ValueType> findAll()
List all objects ofType
in the database.- Specified by:
findAll
in interfaceCRUDService<KeyType extends java.io.Serializable,ValueType extends Timestamped<KeyType>>
- Returns:
- All objects of the specified
Type
in the database.
-
exists
@Transactional(readOnly=true) public java.lang.Boolean exists(KeyType id)
Check to see if an identifier forType
exists in the database.- Specified by:
exists
in interfaceCRUDService<KeyType extends java.io.Serializable,ValueType extends Timestamped<KeyType>>
- Parameters:
id
- The identifier to check for.- Returns:
true
if the identifier exists,false
otherwise.
-
list
@Transactional(readOnly=true) public org.springframework.data.domain.Page<ValueType> list(int page, int size, org.springframework.data.domain.Sort.Direction order, java.lang.String... sortProperties) throws java.lang.IllegalArgumentException
List objects ofType
in the database, limited to some specific page.- Specified by:
list
in interfaceCRUDService<KeyType extends java.io.Serializable,ValueType extends Timestamped<KeyType>>
- Parameters:
page
- the specific page to use.size
- the size of the pages used to compute the number of pages.order
- the order of the sort.sortProperties
- the properties used to sort the collection.- Returns:
- the list of users within the specified range.
- Throws:
java.lang.IllegalArgumentException
- If theType
has no public propertysortProperty
.
-
list
@Transactional(readOnly=true) public org.springframework.data.domain.Page<ValueType> list(int page, int size, org.springframework.data.domain.Sort sort) throws java.lang.IllegalArgumentException
List objects ofType
in the database, limited to some specific page- Specified by:
list
in interfaceCRUDService<KeyType extends java.io.Serializable,ValueType extends Timestamped<KeyType>>
- Parameters:
page
- the specific page to usesize
- the size of the pagessort
- ASort
object for ordering the results- Returns:
- a list of objects in the given range
- Throws:
java.lang.IllegalArgumentException
-
count
@Transactional(readOnly=true) public long count()
How many entities ofType
exist in the database?- Specified by:
count
in interfaceCRUDService<KeyType extends java.io.Serializable,ValueType extends Timestamped<KeyType>>
- Returns:
- the number of entities in the database.
-
updateFields
@Transactional public ValueType updateFields(KeyType id, java.util.Map<java.lang.String,java.lang.Object> updatedFields) throws javax.validation.ConstraintViolationException, EntityExistsException, InvalidPropertyException
Update properties of the given object by given fields. The object must have a valid identifier prior to being passed to this method.- Specified by:
updateFields
in interfaceCRUDService<KeyType extends java.io.Serializable,ValueType extends Timestamped<KeyType>>
- Parameters:
id
- The identifier of the object to update.updatedFields
- the object properties that should be updated.- Returns:
- The object as it was persisted in the database. May modify the identifier of the object when returned.
- Throws:
javax.validation.ConstraintViolationException
- If the object being persisted cannot be validated by validation rules associated with the object.EntityExistsException
- If the object being persisted violates uniqueness constraints in the database.InvalidPropertyException
- If the updated properties map contains a property name that does not exist on the domain model.
-
update
public ValueType update(ValueType object)
Update an object- Specified by:
update
in interfaceCRUDService<KeyType extends java.io.Serializable,ValueType extends Timestamped<KeyType>>
- Parameters:
object
- The object to update- Returns:
- The updated object
-
updateMultiple
@Transactional public java.util.List<ValueType> updateMultiple(java.util.Collection<ValueType> objects)
Update multiple objects at once- Specified by:
updateMultiple
in interfaceCRUDService<KeyType extends java.io.Serializable,ValueType extends Timestamped<KeyType>>
- Parameters:
objects
- the objects to update- Returns:
- the updated objects
-
list
@Transactional(readOnly=true) public org.springframework.data.domain.Page<ValueType> list(int page, int size, org.springframework.data.domain.Sort.Direction order)
List objects ofType
in the database, limited to some specific page, ordered by calling thecompareTo
method on the class.- Specified by:
list
in interfaceCRUDService<KeyType extends java.io.Serializable,ValueType extends Timestamped<KeyType>>
- Parameters:
page
- the specific page to use.size
- the size of the pages used to compute the number of pages.order
- the order of the sort.- Returns:
- the list of users within the specified range.
-
readMultiple
@Transactional(readOnly=true) public java.lang.Iterable<ValueType> readMultiple(java.lang.Iterable<KeyType> idents)
Read multiple objects by the given collection of identifiers- Specified by:
readMultiple
in interfaceCRUDService<KeyType extends java.io.Serializable,ValueType extends Timestamped<KeyType>>
- Parameters:
idents
- The unique identifiers of the objects to read- Returns:
- A collection of the requested objects
-
search
@Deprecated @Transactional(readOnly=true) public org.springframework.data.domain.Page<ValueType> search(org.springframework.data.jpa.domain.Specification<ValueType> specification, int page, int size, org.springframework.data.domain.Sort.Direction order, java.lang.String... sortProperties)
Deprecated.Search for an entity ofType
with a given specification- Specified by:
search
in interfaceCRUDService<KeyType extends java.io.Serializable,ValueType extends Timestamped<KeyType>>
- Parameters:
specification
- The search specificationpage
- The page numbersize
- the size of the pageorder
- the order of the page sortsortProperties
- The properties to sort on- Returns:
- a Page of Type
-
search
@Transactional(readOnly=true) public org.springframework.data.domain.Page<ValueType> search(org.springframework.data.jpa.domain.Specification<ValueType> specification, org.springframework.data.domain.Pageable pageRequest)
Search for an entity ofType
andPageRequest
- Specified by:
search
in interfaceCRUDService<KeyType extends java.io.Serializable,ValueType extends Timestamped<KeyType>>
- Parameters:
specification
- The searchSpecification
pageRequest
- ThePageRequest
- Returns:
- a
Page
ofType
-
findRevisions
@Transactional(readOnly=true) public org.springframework.data.history.Revisions<java.lang.Integer,ValueType> findRevisions(KeyType id)
Find all of the revisions for the specified identifier.- Specified by:
findRevisions
in interfaceCRUDService<KeyType extends java.io.Serializable,ValueType extends Timestamped<KeyType>>
- Parameters:
id
- the identifier to find revisions for.- Returns:
- the collection of revisions for the identifier.
-
findRevisions
@Transactional(readOnly=true) public org.springframework.data.domain.Page<org.springframework.data.history.Revision<java.lang.Integer,ValueType>> findRevisions(KeyType id, org.springframework.data.domain.Pageable pageable)
Returns aPage
of revisions for the entity with the given id.- Specified by:
findRevisions
in interfaceCRUDService<KeyType extends java.io.Serializable,ValueType extends Timestamped<KeyType>>
- Parameters:
id
- the identifier to find revisions for.pageable
- the page specification.- Returns:
- the page of revisions for the specified resource.
-
-