org.sakaiproject.genericdao.api.search.Order Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of generic-dao Show documentation
Show all versions of generic-dao Show documentation
Generic Dao is a Java package which allows a developer to skip writing
DAOs for their persistence objects when they are using Spring and/or Hibernate.
The package was originally created by Aaron Zeckoski for the Evaluation System
project but was repackaged to make it distributable by request. It is used in the
RSF framework (http://www2.caret.cam.ac.uk/rsfwiki/). Note about the BeanUtils
provided dependency: BeanUtils is not required if you are not using it in your
project. Note about the Hibernate provided dependency: Hibernate is not required
if you are not using it in your project.
The newest version!
/**
* $Id$
* $URL$
* Order.java - genericdao - Aug 3, 2008 12:43:54 PM - azeckoski
**************************************************************************
* Copyright (c) 2008 Aaron Zeckoski
* Licensed under the Apache License, Version 2.0
*
* A copy of the Apache License has been included in this
* distribution and is available at: http://www.apache.org/licenses/LICENSE-2.0.txt
*
* Aaron Zeckoski (azeckoski @ gmail.com) (aaronz @ vt.edu) (aaron @ caret.cam.ac.uk)
*/
package org.sakaiproject.genericdao.api.search;
/**
* A simple bean which defines the order to return the results of a search
* Example usage:
* Order ota = new Order("title"); // order by title ascending
* Order otd = new Order("title", false); // order by title descending
*
* @author Aaron Zeckoski ([email protected])
*/
public class Order {
/**
* the name of the field (property) in the persisted object
*/
public String property;
/**
* the name of the field (property) in the persisted object
*/
public String getProperty() {
return property;
}
public void setProperty(String property) {
this.property = property;
}
/**
* if true then the return order is ascending,
* if false then return order is descending
*/
public boolean ascending = true;
/**
* if true then the return order is ascending,
* if false then return order is descending
*/
public boolean isAscending() {
return ascending;
}
public void setAscending(boolean ascending) {
this.ascending = ascending;
}
/**
* a simple order for a property which is ascending
* @param property the name of the field (property) in the persisted object
*/
public Order(String property) {
this.property = property;
this.ascending = true;
}
/**
* define an order for a property
* @param property the name of the field (property) in the persisted object
* @param ascending if true then the return order is ascending,
* if false then return order is descending
*/
public Order(String property, boolean ascending) {
this.property = property;
this.ascending = ascending;
}
@Override
public boolean equals(Object obj) {
if (null == obj)
return false;
if (!(obj instanceof Order))
return false;
else {
Order castObj = (Order) obj;
boolean eq = (this.property == null ? castObj.property == null : this.property.equals(castObj.property))
&& this.ascending == castObj.ascending;
return eq;
}
}
@Override
public int hashCode() {
String hashStr = this.getClass().getName() + ":" + this.property + ":" + this.ascending;
return hashStr.hashCode();
}
@Override
public String toString() {
return "order::prop:" + property + ",asc:" + ascending;
}
}