net.leanix.dropkit.persistence.OffsetRequest Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of leanix-dropkit-persistence Show documentation
Show all versions of leanix-dropkit-persistence Show documentation
Base functionality for persistence in leanIX dropwizard-based services
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