/** * Creates the given entity * * @param entity The entity to create * @return The created entity or an error message if it failed */ public EntityResponse<T> create(T entity) { try { manager.create(entity); return createEntityResponse(entity); } catch (EntityValidationException e) { return createEntityResponseError(e); } }
/** * Updates the given entity * * @param entity The entity to update * @return True if the entity saved without issue. False + Error message otherwise */ public BooleanResponse update(T entity) { try { manager.update(entity); return new BooleanResponse(true); } catch (EntityValidationException e) { return new BooleanResponse(e.getMessage()); } }
/** * Determines if an entity with the given id exists * * @param id The id of the entity to check * @return True if it exists, false otherwise */ public BooleanResponse exists(long id) { return new BooleanResponse(manager.exists(id)); }
/** * Fetches an entity with the specified id * * @param id The id of the entity to fetch * @return All of the entities or an appropriate error message */ public EntityResponse<T> get(long id) { return createEntityResponseErrorIfNull( manager.get(id), MessageFormat.format("No {0} with that id exists!", entityType.getName())); }
/** * Fetches all of the entities of this type paged * * @param startAt The start index * @param maxResults The max number of results to return * @return The entities on the page */ public EntityResponse<PagedEntity<T>> getAll(int startAt, int maxResults, SortParam sort) { return createEntityResponse(manager.getAll(startAt, maxResults, sort)); }
/** * Fetches all of the entities of this type * * @return All of the entities of this type */ public EntityResponse<List<T>> getAll() { return createEntityResponse(manager.getAll()); }