com.github.drinkjava2.hibernate.pagination.LimitHelper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jdialects Show documentation
Show all versions of jdialects Show documentation
jDialects is a pagination and DDL tool support ~80 databases, run on JDK8 or above
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or .
*/
package com.github.drinkjava2.hibernate.pagination;
/**
* A helper for dealing with LimitHandler implementations
*
* @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com)
* @author Yong Zhu(modify)
*/
public class LimitHelper {
/**
* Is a max row limit indicated?
*
* @param selection
* The row selection options
*
* @return Whether a max row limit was indicated
*/
private LimitHelper() {
}
public static boolean hasMaxRows(RowSelection selection) {
return selection != null && selection.getMaxRows() != null && selection.getMaxRows() > 0;
}
/**
* Should limit be applied?
*
* @param limitHandler
* The limit handler
* @param selection
* The row selection
*
* @return Whether limiting is indicated
*/
public static boolean useLimit(LimitHandler limitHandler, RowSelection selection) {
return limitHandler.supportsLimit() && hasMaxRows(selection);
}
/**
* Is a first row limit indicated?
*
* @param selection
* The row selection options
*
* @return Whether a first row limit in indicated
*/
public static boolean hasFirstRow(RowSelection selection) {
return getFirstRow(selection) > 0;
}
/**
* Retrieve the indicated first row for pagination
*
* @param selection
* The row selection options
*
* @return The first row
*/
public static int getFirstRow(RowSelection selection) {
return (selection == null || selection.getFirstRow() == null) ? 0 : selection.getFirstRow();
}
}