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:
BaseVersionEntityService,ModelService,StewardService
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 voidassertFieldNotNullAndNotEmpty(String fieldName, String fieldValue) Checks that the given field value is not null and not empty.abstract voidassertRequiredLocalFields(T entity) Checks that the object has the required fields.abstract voidassertUnique(T entity) Checks that the object will be unique and will not clash with another object in the database.longcount()Counts the total number of entries.voidDeletes 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 TFinds an object based on the given object fields.findOneOptional(T object) Optionally finds an object based on the given object fields.protected StringgetNotFoundException(String label) Throws an exception for when an entity was not found in the database.voidGets 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.voidthrowNotFound(BaseEntity entity) Throws an exception for when an entity was not found in the database.voidthrowNotFound(BaseEntity entity, String label) Throws an exception for when an entity was not found in the database.voidthrowNotFound(String entityClassName, String label) Throws an exception for when an entity was not found in the database.voidthrowNotUnique(BaseEntity entity) Throws an exception for when an entity with the same required fields already exists in the database.voidthrowNotUnique(BaseEntity entity, String label) Throws an exception for when an entity with the same required fields already exists in the database.voidthrowNotUnique(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. -
count
public long count()Counts the total number of entries. -
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
-