diff --git a/HIRS_Utils/src/main/java/hirs/persist/AbstractDbManager.java b/HIRS_Utils/src/main/java/hirs/persist/AbstractDbManager.java index 8d6b6d6a..23e3163c 100644 --- a/HIRS_Utils/src/main/java/hirs/persist/AbstractDbManager.java +++ b/HIRS_Utils/src/main/java/hirs/persist/AbstractDbManager.java @@ -42,7 +42,7 @@ import static org.hibernate.criterion.Restrictions.sqlRestriction; * * @param type of objects to manage by this manager */ -public abstract class AbstractDbManager implements CrudManager { +public abstract class AbstractDbManager implements CrudManager { private static final Logger LOGGER = LogManager.getLogger(AbstractDbManager.class); private static final int MAX_CLASS_CACHE_ENTRIES = 500; diff --git a/HIRS_Utils/src/main/java/hirs/persist/CrudManager.java b/HIRS_Utils/src/main/java/hirs/persist/CrudManager.java index 35aeeeba..c8f8989d 100644 --- a/HIRS_Utils/src/main/java/hirs/persist/CrudManager.java +++ b/HIRS_Utils/src/main/java/hirs/persist/CrudManager.java @@ -10,14 +10,13 @@ import java.util.List; * Interface defining database CRUD operations (Create, Read, Update, Delete). * @param the object type, T. */ -public interface CrudManager extends OrderedListQuerier { +public interface CrudManager extends OrderedListQuerier { /** - * Deletes all instances of the associated class. * - * @return the number of entities deleted + * @param classToSet */ - int deleteAll(); + void setClazz(Class classToSet); /** * Saves the Object in the database. If the Object had @@ -51,23 +50,6 @@ public interface CrudManager extends OrderedListQuerier { */ AbstractEntity get(String name) throws DBManagerException; - /** - * Retrieves the Object from the database. This searches the - * database for an entry whose name matches name. It then - * reconstructs the Object from the database entry. It will also - * load all the lazy fields in the given class. If the parameter recurse - * is set to true, this method will recursively descend into each of the object's fields - * to load all the lazily-loaded entities. If false, only the fields belonging to the object - * itself will be loaded. - * - * @param name name of the object - * @param recurse whether to recursively load lazy data throughout the object's structures - * @return object if found, otherwise null. - * @throws DBManagerException if unable to search the database or recreate - * the Object - */ - AbstractEntity getAndLoadLazyFields(String name, boolean recurse) - throws DBManagerException; /** * Retrieves the Object from the database. This searches the @@ -81,39 +63,20 @@ public interface CrudManager extends OrderedListQuerier { */ T get(Serializable id) throws DBManagerException; -// /** -// * Retrieves the Object from the database. This searches the -// * database for an entry whose id matches id. It then -// * reconstructs the Object from the database entry. It will also -// * load all the lazy fields in the given class. If the parameter recurse -// * is set to true, this method will recursively descend into each of the object's fields -// * to load all the lazily-loaded entities. If false, only the fields belonging to the object -// * itself will be loaded. -// * -// * @param id id of the object -// * @param recurse whether to recursively load lazy data throughout the object's structures -// * @return object if found, otherwise null. -// * @throws DBManagerException if unable to search the database or recreate -// * the Object -// */ -// AbstractEntity getAndLoadLazyFields(Serializable id, boolean recurse) -// throws DBManagerException; -// -// /** -// * Returns a list of all Ts of type clazz in the database, with no -// * additional restrictions. -// *

-// * This would be useful if T has several subclasses being -// * managed. This class argument allows the caller to limit which types of -// * T should be returned. -// * -// * @param AbstractEntity class type of Ts to search for (may be null to -// * use Class<T>) -// * @return list of T names -// * @throws DBManagerException if unable to search the database -// */ -// List getList(AbstractEntity entity) -// throws DBManagerException; + + /** + * Returns a list of all Ts of type clazz in the database, with no + * additional restrictions. + *

+ * This would be useful if T has several subclasses being + * managed. This class argument allows the caller to limit which types of + * T should be returned. + * + * @return list of T names + * @throws DBManagerException if unable to search the database + */ + List getList() + throws DBManagerException; /** * Returns a list of all Ts of type clazz in the database, with an @@ -123,29 +86,13 @@ public interface CrudManager extends OrderedListQuerier { * managed. This class argument allows the caller to limit which types of * T should be returned. * - * @param AbstractEntity class type of Ts to search for (may be null to - * use Class<T>) * @param additionalRestriction - an added Criterion to use in the query, null for none * @return list of T names * @throws DBManagerException if unable to search the database */ - List getList(AbstractEntity entity, Criterion additionalRestriction) + List getList(Criterion additionalRestriction) throws DBManagerException; - /** - * Deletes the object from the database. This removes all of the database - * entries that stored information with regards to the this object. - *

- * If the object is referenced by any other tables then this will throw a - * DBManagerException. - * - * @param name name of the object to delete - * @return true if successfully found and deleted the object - * @throws DBManagerException if unable to find the baseline or delete it - * from the database - */ - boolean delete(String name) throws DBManagerException; - /** * Deletes the object from the database. This removes all of the database * entries that stored information with regards to the this object. @@ -158,7 +105,7 @@ public interface CrudManager extends OrderedListQuerier { * @throws DBManagerException if unable to find the baseline or delete it * from the database */ - boolean delete(Serializable id) + boolean deleteById(Serializable id) throws DBManagerException; /** @@ -168,11 +115,18 @@ public interface CrudManager extends OrderedListQuerier { * If the object is referenced by any other tables then this will throw a * DBManagerException. * - * @param object object to delete + * @param entity object to delete * @return true if successfully found and deleted the object * @throws DBManagerException if unable to delete the object from the database */ - boolean delete(AbstractEntity object) throws DBManagerException; + boolean delete(T entity) throws DBManagerException; + + /** + * Deletes all instances of the associated class. + * + * @return the number of entities deleted + */ + int deleteAll(); /** * Archives the named object and updates it in the database. diff --git a/HIRS_Utils/src/main/java/hirs/persist/DBManager.java b/HIRS_Utils/src/main/java/hirs/persist/DBManager.java index 0a8fbae7..c8606f10 100644 --- a/HIRS_Utils/src/main/java/hirs/persist/DBManager.java +++ b/HIRS_Utils/src/main/java/hirs/persist/DBManager.java @@ -28,7 +28,7 @@ import java.util.Map; * archive, and delete operations for managing objects in a database. * */ -public class DBManager extends AbstractDbManager { +public class DBManager extends AbstractDbManager { private static final Logger LOGGER = LogManager.getLogger(DBManager.class); /** @@ -442,7 +442,7 @@ public class DBManager extends AbstractDbManager { * @throws DBManagerException if unable to find the baseline or delete it * from the database */ - public final boolean delete(final Serializable id) + public final boolean deleteById(final Serializable id) throws DBManagerException { return retryTemplate.execute(new RetryCallback() { @Override diff --git a/HIRS_Utils/src/main/java/hirs/persist/OrderedListQuerier.java b/HIRS_Utils/src/main/java/hirs/persist/OrderedListQuerier.java index 3a92782e..d573e42c 100644 --- a/HIRS_Utils/src/main/java/hirs/persist/OrderedListQuerier.java +++ b/HIRS_Utils/src/main/java/hirs/persist/OrderedListQuerier.java @@ -7,16 +7,16 @@ import java.util.Map; /** * Interface defining methods for getting ordered lists from a data source. Includes * properties for sorting, paging, and searching. - * @param the record type, AbstractEntity. + * @param the record type, T. */ -public interface OrderedListQuerier { +public interface OrderedListQuerier { /** * Returns a list of all Ts that are ordered by a column and * direction (ASC, DESC) that is provided by the user. This method helps * support the server-side processing in the JQuery DataTables. * - * @param entity class type of Ts to search for (may be null to + * @param clazz class type of Ts to search for (may be null to * use Class<T>) * @param columnToOrder Column to be ordered * @param ascending direction of sort @@ -30,7 +30,7 @@ public interface OrderedListQuerier { * @throws DBManagerException if unable to create the list */ FilteredRecordsList getOrderedList( - AbstractEntity entity, String columnToOrder, + Class clazz, String columnToOrder, boolean ascending, int firstResult, int maxResults, String search, Map searchableColumns) @@ -43,7 +43,7 @@ public interface OrderedListQuerier { * support the server-side processing in the JQuery DataTables. For entities that support * soft-deletes, the returned list does not contain Ts that have been soft-deleted. * - * @param entity class type of Ts to search for (may be null to + * @param clazz class type of Ts to search for (may be null to * use Class<T>) * @param columnToOrder Column to be ordered * @param ascending direction of sort @@ -58,10 +58,10 @@ public interface OrderedListQuerier { * @throws DBManagerException if unable to create the list */ @SuppressWarnings("checkstyle:parameternumber") - FilteredRecordsList getOrderedList( - AbstractEntity entity, String columnToOrder, + FilteredRecordsList getOrderedList( + Class clazz, String columnToOrder, boolean ascending, int firstResult, int maxResults, String search, Map searchableColumns, CriteriaModifier criteriaModifier) throws DBManagerException; -} +} \ No newline at end of file