Interface Repository


  • public interface Repository
    A repository holds the connections to data base server, allowing it to be queried through Queryable objects. Repository instances must be thread-safe and usually a single instance is enough per application.
    Since:
    0.6.0
    Author:
    Alisson Gomes
    • Method Detail

      • get

        <T> T get​(Queryable queryable)
        Get one object instance from repository using a query.
        Type Parameters:
        T - generic type to be returned
        Parameters:
        queryable - The Query name with yours parameters
        Returns:
        Return the object that matches with query. A null reference is returned if the query no match anyone object.
        Throws:
        net.sf.jkniv.sqlegance.QueryNotFoundException - when not found the query name
        net.sf.jkniv.sqlegance.NonUniqueResultException - when select or select with group by recovery more one objects
      • get

        <T> T get​(Queryable queryable,
                  Class<T> returnType)
        Get one object instance of type returnType from repository using a query.
        Type Parameters:
        T - type of object returned
        Parameters:
        queryable - The Query name with yours parameters
        returnType - overload the returned type from XML file
        Returns:
        Return the object returnTypethat matches with query. A null reference is returned if the query no match anyone object.
        Throws:
        net.sf.jkniv.sqlegance.QueryNotFoundException - when not found the query name
        net.sf.jkniv.sqlegance.NonUniqueResultException - when select or select with group by recovery more one objects
      • get

        <T,​R> T get​(Queryable queryable,
                          ResultRow<T,​R> customResultRow)
        Get one object instance from repository using a query.
        Type Parameters:
        T - type of object returned
        R - raw type from repository API (Like ResultSet from JDBC)
        Parameters:
        queryable - The Query name with yours parameters
        customResultRow - Customized extractor to process each row from query
        Returns:
        Return the object returnType that matches with query. A null reference is returned if the query no match anyone object.
        Throws:
        net.sf.jkniv.sqlegance.QueryNotFoundException - when not found the query name
        net.sf.jkniv.sqlegance.NonUniqueResultException - when select or select with group by recovery more one objects
      • get

        <T> T get​(T object)
        Get one object instance from repository using a object as parameter.
        Type Parameters:
        T - type of object returned
        Parameters:
        object - object that contains the parameters to retrieve the entity.
        Returns:
        Return the object returnType that matches with query. A null reference is returned if the query no match anyone object.
        Throws:
        net.sf.jkniv.sqlegance.QueryNotFoundException - when not found the query name
        net.sf.jkniv.sqlegance.NonUniqueResultException - when select or select with group by recovery more one objects
      • get

        <T> T get​(Class<T> returnType,
                  Object object)
        Get one object instance of type returnType from repository using a object as parameter.
        Type Parameters:
        T - type of object returned
        Parameters:
        returnType - overload the returned type from XML file
        object - parameters from query to retrieve the object
        Returns:
        Return the object returnType that matches with query. A null reference is returned if the query no match anyone object.
        Throws:
        net.sf.jkniv.sqlegance.QueryNotFoundException - when not found the query name
        net.sf.jkniv.sqlegance.NonUniqueResultException - when select or select with group by recovery more one objects
      • scalar

        <T> T scalar​(Queryable queryable)
        Retrieve a number, numerical quantity, string, date, boolean, some primitive value (wrapped), the type is checked against jdbc data type.
        • java.math.BigDecimal
        • java.lang.Boolean
        • java.lang.Byte
        • java.lang.Double
        • java.lang.Float
        • java.lang.Integer
        • java.lang.Long
        • java.lang.Short
        • java.lang.String
        • java.lang.Character
        • java.util.Date
        Type Parameters:
        T - the single type to be returned
        Parameters:
        queryable - The Query name with yours parameters
        Returns:
        Scalar value
        Throws:
        net.sf.jkniv.sqlegance.QueryNotFoundException - when not found the query name
        net.sf.jkniv.sqlegance.NonUniqueResultException - when select or select with group by recovery more one objects
      • enrich

        boolean enrich​(Queryable queryable)
        Use the Queryable to retrieve data and appends the result to Queryable.getParams() parameters, where for each get method must have a correspondent set.
        Parameters:
        queryable - Query with yours parameters
        Returns:
        return true if the objects was enriched, false otherwise.
        Throws:
        net.sf.jkniv.sqlegance.QueryNotFoundException - when not found the query name
        net.sf.jkniv.sqlegance.NonUniqueResultException - if your Queryable doesn't return one unique value
      • list

        <T> List<T> list​(Queryable queryable)
        Retrieve a set of objects T from repository using a query.
        Type Parameters:
        T - generic type to be returned
        Parameters:
        queryable - The Query name with yours parameters
        Returns:
        Return a set of object that matches with query. A empty list is returned if the query no match anyone object.
        Throws:
        net.sf.jkniv.sqlegance.QueryNotFoundException - when not found the query name
      • list

        <T> List<T> list​(Queryable queryable,
                         Class<T> returnType)
        Retrieve a set of objects returnType from repository using a query.
        Type Parameters:
        T - type of object returned
        Parameters:
        queryable - The Query name with yours parameters
        returnType - overload the returned type from XML file
        Returns:
        Return a set of object that matches with query. A empty list is returned if the query no match anyone object.
        Throws:
        net.sf.jkniv.sqlegance.QueryNotFoundException - when not found the query name
      • list

        <T,​R> List<T> list​(Queryable queryable,
                                 ResultRow<T,​R> customResultRow)
        Retrieve a set of objects T from repository using a query.
        Type Parameters:
        T - type of object returned
        R - raw type from repository API (Like ResultSet from JDBC)
        Parameters:
        queryable - The Query name with yours parameters
        customResultRow - Customized extractor to process each row from query
        Returns:
        Return a set of object that matches with query. A empty list is returned if the query no match anyone object.
        Throws:
        net.sf.jkniv.sqlegance.QueryNotFoundException - when not found the query name
      • add

        int add​(Queryable queryable)
        Add a new object to repository.
        Parameters:
        queryable - name of query must be executed to add object to repository
        Returns:
        Return the number of objects inserted.
        Throws:
        net.sf.jkniv.sqlegance.QueryNotFoundException - when not found the query name
      • add

        <T> int add​(T entity)
        Add a new object to repository.
        Type Parameters:
        T - type of object returned
        Parameters:
        entity - object to be added to repository
        Returns:
        Return the number of objects inserted.
        Throws:
        IllegalArgumentException - when entity is null
      • update

        int update​(Queryable queryable)
        Update many objects in repository.
        Parameters:
        queryable - The Query name with yours parameters
        Returns:
        Return the number of objects updated.
        Throws:
        net.sf.jkniv.sqlegance.QueryNotFoundException - when not found the query name
        IllegalArgumentException - when the query is different from update sentence
      • update

        <T> T update​(T entity)
        Update object(s) in repository.
        Type Parameters:
        T - type of object returned
        Parameters:
        entity - update the repository with a entity values mapped at query.
        Returns:
        the instance that was updated to
        Throws:
        IllegalArgumentException - when entity is null
      • remove

        int remove​(Queryable queryable)
        Execute a query to remove one or many objects from repository.
        Parameters:
        queryable - The Query name with yours parameters
        Returns:
        the number of rows removed.
        Throws:
        IllegalArgumentException - when the query is different from delete
      • remove

        <T> int remove​(T entity)
        Remove the entity from repository.
        Type Parameters:
        T - type of object returned
        Parameters:
        entity - object with the parameters
        Returns:
        the number of objects removed.
        Throws:
        IllegalArgumentException - when entity is null
      • flush

        void flush()
        Push the queries from buffer to repository.
      • close

        void close()
        Close the connection with the database. After close the repository any query cannot be executed against the database then all subsequent access to the repository throw a RepositoryException
      • containsQuery

        boolean containsQuery​(String name)
      • dsl

        <T> T dsl()
        A domain-specific languages (DSL) from native API: JPA, Couchbase, Cassandra etc.
        Type Parameters:
        T - a generic type from DSL API
        Returns:
        the DSL API to build dynamic queries
        Throws:
        UnsupportedDslOperationException - when the repository does not supports DSL