org.sqlproc.engine
Class SqlOrder

java.lang.Object
  extended by org.sqlproc.engine.SqlOrder

public class SqlOrder
extends java.lang.Object

The list of ordering directives for the SQL Processor queries execution. The class layout is based on the Composite design pattern. Instances of this class can be obtained only using one of the factory methods.

For example there's a table PERSON with two columns - ID and NAME. The META SQL can be the next one:

 LIST_ALL_SQL= \
   select p.ID, p.NAME \
   from PERSON p \
   {#1 order by ID} \
   {#2 order by NAME}
 

In the case of SQL Processor invocation

 SqlEngine sqlEngine = sqlLoader.getSqlEngine("ALL");
 List<Person> list = sqlEngine.query(session, Person.class, null, SqlOrder.getAscOrder(1));
 
the output list is sorted in ascending order based on column ID.

In the case of SQL Processor invocation

 SqlEngine sqlEngine = sqlLoader.getSqlEngine("ALL");
 List<Person> list = sqlEngine.query(session, Person.class, new Object(), SqlOrder.getDescOrder(2));
 
the output list is sorted in descending order based on column NAME.

For more info please see the User's tutorial.

Author:
Vladimir Hudec

Nested Class Summary
static class SqlOrder.Order
          The enumeration for the ordering directives.
 
Field Summary
private  SqlOrder.Order orderDirrection
          The ordering direction (no ordering, ascending or descending).
private  int orderId
          The ordering id.
private  java.util.List<SqlOrder> orders
          The list of all ordering rules.
 
Constructor Summary
private SqlOrder()
          Creates a new empty ordering directives.
private SqlOrder(int orderId, SqlOrder.Order orderDirrection)
          /** Creates a new ordering rule.
 
Method Summary
 SqlOrder addAscOrder(int orderId)
          Adds one more ascending ordering rule into the list of ordering directives.
 SqlOrder addDescOrder(int orderId)
          Adds one more descending ordering rule into the list of ordering directives.
 SqlOrder addOrder(int orderId)
          Adds one more ascending or descending ordering rule into the list of ordering directives.
static SqlOrder getAscOrder(int orderId)
          The factory method.
static SqlOrder getDescOrder(int orderId)
          The factory method.
static SqlOrder getOrder()
          The factory method.
static SqlOrder getOrder(int orderId)
          The factory method.
 SqlOrder.Order getOrderDirrection()
          Returns the ordering direction (no ordering, ascending or descending).
 int getOrderId()
          Returns the ordering id.
 java.util.List<SqlOrder> getOrders()
          Returns the list of ordering directives.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

orderId

private int orderId
The ordering id. This value should correspond to the order number in META SQL {#NNN order by ...}.


orderDirrection

private SqlOrder.Order orderDirrection
The ordering direction (no ordering, ascending or descending).


orders

private java.util.List<SqlOrder> orders
The list of all ordering rules.

Constructor Detail

SqlOrder

private SqlOrder()
Creates a new empty ordering directives. This constructor is a private one to prevent an instantiation without factory methods.


SqlOrder

private SqlOrder(int orderId,
                 SqlOrder.Order orderDirrection)
/** Creates a new ordering rule. This constructor is a private one to prevent an instantiation without factory methods.

Parameters:
orderId - the ordering id
orderDirrection - the ordering direction
Method Detail

getOrder

public static SqlOrder getOrder()
The factory method.

Returns:
the empty ordering directive list

getAscOrder

public static SqlOrder getAscOrder(int orderId)
The factory method.

Parameters:
orderId - the ordering id
Returns:
the ordering directive list with one ascending ordering rule

getDescOrder

public static SqlOrder getDescOrder(int orderId)
The factory method.

Parameters:
orderId - the ordering id
Returns:
the ordering directive list with one descending ordering rule

getOrder

public static SqlOrder getOrder(int orderId)
The factory method.

Parameters:
orderId - the ordering id. Can be a negative one for a descending ordering rule.
Returns:
the ordering directive list with one ascending or descending ordering rule

addAscOrder

public SqlOrder addAscOrder(int orderId)
Adds one more ascending ordering rule into the list of ordering directives.

Parameters:
orderId - the ordering id
Returns:
the updated ordering directive list

addDescOrder

public SqlOrder addDescOrder(int orderId)
Adds one more descending ordering rule into the list of ordering directives.

Parameters:
orderId - the ordering id
Returns:
the updated ordering directive list

addOrder

public SqlOrder addOrder(int orderId)
Adds one more ascending or descending ordering rule into the list of ordering directives.

Parameters:
orderId - the ordering id. Can be a negative one for a descending ordering rule.
Returns:
the updated ordering directive list

getOrderId

public int getOrderId()
Returns the ordering id. This value should correspond to the order number in META SQL {#NNN order by ...}.

Returns:
the ordering id

getOrderDirrection

public SqlOrder.Order getOrderDirrection()
Returns the ordering direction (no ordering, ascending or descending).

Returns:
the ordering direction

getOrders

public java.util.List<SqlOrder> getOrders()
Returns the list of ordering directives.

Returns:
the list of ordering directives


Copyright © 2010. All Rights Reserved.