Class SingleEntityQuery<E extends BaseEntity>

    • Constructor Detail

      • SingleEntityQuery

        public SingleEntityQuery​(Class<E> type)
    • Method Detail

      • where

        public SingleEntityQuery<E> where​(com.github.collinalpert.lambda2sql.functions.SqlPredicate<E> predicate)
        Sets or appends a WHERE clause for the DQL statement.
        Parameters:
        predicate - The predicate describing the WHERE clause.
        Returns:
        This EntityQuery object, now with an (appended) WHERE clause.
      • orWhere

        public SingleEntityQuery<E> orWhere​(com.github.collinalpert.lambda2sql.functions.SqlPredicate<E> predicate)
        Sets or appends an OR WHERE clause to the DQL statement.
        Parameters:
        predicate - The predicate describing the OR WHERE clause.
        Returns:
        This EntityQuery object, now with an (appended) OR WHERE clause.
      • project

        public <R> SingleQueryable<R> project​(com.github.collinalpert.lambda2sql.functions.SqlFunction<E,​R> projection)
        Selects only a single column from a table. This is meant if you don't want to fetch an entire entity from the database.
        Type Parameters:
        R - The type of the column you want to retrieve.
        Parameters:
        projection - The column to project to.
        Returns:
        A queryable containing the projection.
      • first

        public Optional<E> first()
        Gets the first record of a result. This method should be used when only one record is expected, i.e. when filtering by a unique identifier such as an id.
        Specified by:
        first in interface SingleQueryable<E extends BaseEntity>
        Returns:
        The first row as an entity wrapped in an Optional if there is at least one row. Otherwise Optional.empty() is returned.
      • getQuery

        public String getQuery()
        Builds the query from the set query options.
        Specified by:
        getQuery in interface SingleQueryable<E extends BaseEntity>
        Returns:
        The DQL statement for getting data from the database.
      • buildWhereClause

        protected void buildWhereClause​(StringBuilder builder,
                                        String tableName)
        Builds the WHERE clause in a select statement.
        Parameters:
        builder - The StringBuilder to append the clause to.
        tableName - The name of the table the where clause will affect.
      • getTableName

        public String getTableName()
        Gets the table name which this query targets.
        Returns:
        The table name which this query targets.