org.pojava.persistence.query
Class AbstractQuery

java.lang.Object
  extended by org.pojava.persistence.query.AbstractQuery
Direct Known Subclasses:
SqlQuery

public abstract class AbstractQuery
extends Object

An AbstractQuery represents the row selection (and not the column selection) aspects of a search criteria. It is used by Dao methods to perform some operation upon a definable set of rows, such as deleting, listing, or processing. The primary goal of this approach is to abstract the persistence implementation details away from your business layer, so your code behaves the same way when you switch implementations, say from one database to another, or from a local database to a web service or to an API for an Enterprise Service Bus. A typical SQL-only Query could just extend SqlQuery (which already extends AbstractQuery). A very basic query could look like the following: public class AnimalQuery extends SqlQuery { public AnimalQuery forNumberOfLegs(int legs) { String legStr=new Integer(legs).toString(); super.sql.clear(); super.sql.append("WHERE legs=" + legStr); return this; } } If you created your own custom provider, say, for an XML query using xpath, your class may look like this (note that your business layer still defines the number of legs the same way for either implementation): public class AnimalQuery extends SqlQuery implements XpathProvider { private String xpath=null; public AnimalQuery forNumberOfLegs(int legs) { String legStr=new Integer(legs).toString(); super.sql.clear(); super.sql.append("WHERE legs=" + legStr); this.xpath="//ANIMALS/ANIMAL[@legs='" + legStr + "']"; return this; } public String generateXpath() { return xpath; } } For either implementation, your business layer would typically make a call similar to this: ... AnimalQuery legQuery=new AnimalQuery().forNumberOfLegs(4); List animals=AnimalDao.listByQuery(transaction, legQuery); ...

Author:
John Pile

Constructor Summary
AbstractQuery()
          Default constructor
 
Method Summary
 int getMaxRows()
          Show the maximum of rows returnable by the driver.
 void setMaxRows(int maxRows)
          Limit the number of rows returnable by the driver.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractQuery

public AbstractQuery()
Default constructor

Method Detail

getMaxRows

public int getMaxRows()
Show the maximum of rows returnable by the driver.

Returns:
maximum allowed rows in dataset.

setMaxRows

public void setMaxRows(int maxRows)
Limit the number of rows returnable by the driver.

Parameters:
maxRows -


Copyright © 2011. All Rights Reserved.