Class BaseService<T extends BaseEntity>

  • Direct Known Subclasses:
    BaseCodeAndDescriptionService

    public class BaseService<T extends BaseEntity>
    extends java.lang.Object
    Author:
    Collin Alpert

    Class that provides base functionality for all service classes. Every service class must extend this class.

    • Constructor Summary

      Constructors 
      Constructor Description
      BaseService​(java.lang.Class<T> clazz)
      Constructor for the base class of all services.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean create​(T instance)
      Creates a Java entity on the database.
      void delete​(long id)
      Deletes a row by an id.
      void delete​(T instance)
      Deletes the corresponding row on the database.
      java.util.List<T> getAll()  
      java.util.Optional<T> getById​(long id)  
      protected java.sql.ResultSet getByPredicate​(SqlPredicate<T> predicate, DBConnection connection)  
      java.util.List<T> getMultiple​(SqlPredicate<T> predicate)  
      java.util.Optional<T> getSingle​(SqlPredicate<T> predicate)  
      boolean update​(T instance)
      Applies updates to an entity on the database.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • BaseService

        public BaseService​(java.lang.Class<T> clazz)
        Constructor for the base class of all services. It is possible to create instances of it.
        Parameters:
        clazz - The entity class corresponding to this service class.
    • Method Detail

      • create

        public boolean create​(T instance)
        Creates a Java entity on the database.
        Parameters:
        instance - The instance to create on the database.
        Returns:
        True if the INSERT was successful, false if not.
      • getByPredicate

        protected java.sql.ResultSet getByPredicate​(SqlPredicate<T> predicate,
                                                    DBConnection connection)
        Parameters:
        predicate - The SqlPredicate for constraints on the SELECT query.
        connection - A connection to execute the query on.
        Returns:
        A ResultSet by a predicate.
      • getSingle

        public java.util.Optional<T> getSingle​(SqlPredicate<T> predicate)
        Parameters:
        predicate - The SqlPredicate to add constraints to a SELECT query.
        Returns:
        An entity matching the result of the query.
      • getMultiple

        public java.util.List<T> getMultiple​(SqlPredicate<T> predicate)
        Parameters:
        predicate - The SqlPredicate to add constraints to a SELECT query.
        Returns:
        A list of entities matching the result of the query.
      • getById

        public java.util.Optional<T> getById​(long id)
        Parameters:
        id - The id of the desired entity.
        Returns:
        Gets an entity by its id.
      • getAll

        public java.util.List<T> getAll()
        Returns:
        All entities in this table.
      • update

        public boolean update​(T instance)
        Applies updates to an entity on the database.
        Parameters:
        instance - The instance to update on the interface.
        Returns:
        True if the update is successful, false if not.
      • delete

        public void delete​(T instance)
        Deletes the corresponding row on the database.
        Parameters:
        instance - The instance to delete on the database.
      • delete

        public void delete​(long id)
        Deletes a row by an id.
        Parameters:
        id - The row with this id to delete.