All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.leanix.dropkit.persistence.OffsetRequest Maven / Gradle / Ivy

There is a newer version: 2.0.5
Show newest version
package net.leanix.dropkit.persistence;

import org.hibernate.NullPrecedence;

import net.leanix.dropkit.BusinessLogicException;

/**
 * Object that represents data of a paginated request.
 *
 *
 */
public class OffsetRequest extends AbstractPageRequest {

    private int offset;

    public OffsetRequest(int offset, int size, String sort, int maxSize) throws BusinessLogicException {
        super(size, sort, maxSize);
        this.offset = offset;
    }

    /**
     * Creates a new PageRequest for a single page.
     * 
     * @param offset
     *            Number of the requested page.
     * @param size
     *            Size of the requested page.
     * @param sort
     *            Sorting of the data set.
     * @param maxSize
     *            Max size allowed for the requested page size.
     * @param nullPrecedence
     *            Specifies how nulls are sorted.
     * @throws net.leanix.dropkit.BusinessLogicException
     */
    public OffsetRequest(int offset, int size, String sort, int maxSize, NullPrecedence nullPrecedence)
            throws BusinessLogicException {
        this(offset, size, sort, maxSize);
        this.nullPrecedence = nullPrecedence;
    }

    public final void setOffset(int offset) throws BusinessLogicException {
        if (offset < 0) {
            throw new BusinessLogicException("Negative page values not allowed.", 400);
        }
        this.offset = offset;
    }

    /**
     * Disables paging by setting page and size to zero and maxSize to -1.
     */
    public void removePagingParams() {
        offset = -1;
        size = 0;
        this.setMaxSize(-1);
    }

    @Override
    public Integer computeOffset() {
        return offset >= 0 ? offset : null;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy