Package gov.niem.tools.api.db.base
Class BaseEntityService<T extends BaseEntity>
java.lang.Object
gov.niem.tools.api.db.base.BaseEntityService<T>
- Direct Known Subclasses:
ComponentService
,FacetService
,ModelService
,NamespaceService
,StewardService
,SubpropertyService
,VersionService
Abstract class that provides basic database operations for data model items.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionAdds the given object to the database.protected static void
assertFieldNotNullAndNotEmpty
(String fieldName, String fieldValue) Checks that the given field value is not null and not empty.abstract void
assertRequiredLocalFields
(T entity) Checks that the object has the required fields.abstract void
assertUnique
(T entity) Checks that the object will be unique and will not clash with another object in the database.void
Deletes the object in the database with the id from the given object.Modifies the object in the database with the given id with the fields from the given object.abstract T
Finds an object based on the given object fields.findOneOptional
(T object) Optionally finds an object based on the given object fields.protected String
getNotFoundException
(String label) Throws an exception for when an entity was not found in the database.void
Gets an object from the database matching the given object criteria.Syncs the given plain object with object information from the database.saveExisting
(T object) Saves changes in the database to the existing object based on the object id.Adds the object to the database.void
throwNotFound
(BaseEntity entity) Throws an exception for when an entity was not found in the database.void
throwNotFound
(BaseEntity entity, String label) Throws an exception for when an entity was not found in the database.void
throwNotFound
(String entityClassName, String label) Throws an exception for when an entity was not found in the database.void
throwNotUnique
(BaseEntity entity) Throws an exception for when an entity with the same required fields already exists in the database.void
throwNotUnique
(BaseEntity entity, String label) Throws an exception for when an entity with the same required fields already exists in the database.void
throwNotUnique
(String entityClassName, String label) Throws an exception for when an entity with the same required fields already exists in the database.
-
Constructor Details
-
BaseEntityService
public BaseEntityService()
-
-
Method Details
-
repository
-
getEntityClassName
-
loadId
Gets an object from the database matching the given object criteria.- Throws:
EntityNotFoundException
-
add
Adds the given object to the database.- Throws:
Exception
-
edit
Modifies the object in the database with the given id with the fields from the given object.- Throws:
Exception
-
delete
Deletes the object in the database with the id from the given object.- Throws:
Exception
-
saveNew
Adds the object to the database.- Throws:
Exception
-
saveExisting
Saves changes in the database to the existing object based on the object id.- Throws:
Exception
-
merge
Syncs the given plain object with object information from the database. -
findOne
Finds an object based on the given object fields.- Throws:
EntityNotFoundException
-
findOneOptional
Optionally finds an object based on the given object fields. -
assertRequiredLocalFields
Checks that the object has the required fields.- Throws:
FieldNotFoundException
-
assertUnique
Checks that the object will be unique and will not clash with another object in the database.- Throws:
EntityNotUniqueException
-
assertFieldNotNullAndNotEmpty
protected static void assertFieldNotNullAndNotEmpty(String fieldName, String fieldValue) throws FieldNotFoundException Checks that the given field value is not null and not empty.- Throws:
FieldNotFoundException
-
getNotFoundException
Throws an exception for when an entity was not found in the database. -
throwNotFound
Throws an exception for when an entity was not found in the database.- Throws:
EntityNotFoundException
-
throwNotFound
Throws an exception for when an entity was not found in the database.- Throws:
EntityNotFoundException
-
throwNotFound
Throws an exception for when an entity was not found in the database.- Throws:
EntityNotFoundException
-
throwNotUnique
Throws an exception for when an entity with the same required fields already exists in the database.- Throws:
EntityNotUniqueException
-
throwNotUnique
Throws an exception for when an entity with the same required fields already exists in the database.- Throws:
EntityNotUniqueException
-
throwNotUnique
Throws an exception for when an entity with the same required fields already exists in the database.- Throws:
EntityNotUniqueException
-