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.StringCREATED_DATE_SORT_PROPERTYprotected IridaJpaRepository<ValueType,KeyType>repositoryprotected javax.validation.Validatorvalidatorprotected 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 longcount()How many entities ofTypeexist in the database?ValueTypecreate(ValueType object)Create a new object in the persistence store.voiddelete(KeyType id)Delete the object with the specified identifier from the database.java.lang.Booleanexists(KeyType id)Check to see if an identifier forTypeexists in the database.java.lang.Iterable<ValueType>findAll()List all objects ofTypein 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 aPageof 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 ofTypein 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 ofTypein the database, limited to some specific page, ordered by calling thecompareTomethod 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 ofTypein the database, limited to some specific page.ValueTyperead(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 ofTypeandPageRequestValueTypeupdate(ValueType object)Update an objectValueTypeupdateFields(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:
createin 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:
readin 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:
deletein 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 ofTypein the database.- Specified by:
findAllin interfaceCRUDService<KeyType extends java.io.Serializable,ValueType extends Timestamped<KeyType>>- Returns:
- All objects of the specified
Typein the database.
-
exists
@Transactional(readOnly=true) public java.lang.Boolean exists(KeyType id)
Check to see if an identifier forTypeexists in the database.- Specified by:
existsin interfaceCRUDService<KeyType extends java.io.Serializable,ValueType extends Timestamped<KeyType>>- Parameters:
id- The identifier to check for.- Returns:
trueif the identifier exists,falseotherwise.
-
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 ofTypein the database, limited to some specific page.- Specified by:
listin 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 theTypehas 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 ofTypein the database, limited to some specific page- Specified by:
listin interfaceCRUDService<KeyType extends java.io.Serializable,ValueType extends Timestamped<KeyType>>- Parameters:
page- the specific page to usesize- the size of the pagessort- ASortobject 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 ofTypeexist in the database?- Specified by:
countin 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:
updateFieldsin 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:
updatein 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:
updateMultiplein 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 ofTypein the database, limited to some specific page, ordered by calling thecompareTomethod on the class.- Specified by:
listin 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:
readMultiplein 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 ofTypewith a given specification- Specified by:
searchin 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 ofTypeandPageRequest- Specified by:
searchin interfaceCRUDService<KeyType extends java.io.Serializable,ValueType extends Timestamped<KeyType>>- Parameters:
specification- The searchSpecificationpageRequest- ThePageRequest- Returns:
- a
PageofType
-
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:
findRevisionsin 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 aPageof revisions for the entity with the given id.- Specified by:
findRevisionsin 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.
-
-