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

com.github.drinkjava2.hibernate.pagination.LimitHelper Maven / Gradle / Ivy

Go to download

jDialects is a pagination and DDL tool support ~80 databases, run on JDK8 or above

There is a newer version: 5.0.13.jre8
Show newest version
/*
 * 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();
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy