velosurf.context
Class AttributeReference

java.lang.Object
  extended by velosurf.context.AttributeReference
All Implemented Interfaces:
java.lang.Iterable

public class AttributeReference
extends java.lang.Object
implements java.lang.Iterable

Context wrapper for attributes.

Author:
Claude Brisson

Field Summary
private  Attribute attribute
          The wrapped attribute.
private  java.lang.String order
          Specified 'order by' clause specified for this attribute reference.
private  java.util.Map<java.lang.String,java.lang.Object> params
          The map this attribute reference applies to.
private  java.util.List<java.lang.String> refineCriteria
          Specified refining criteria defined on this attribute reference.
 
Constructor Summary
AttributeReference(java.util.Map<java.lang.String,java.lang.Object> params, Attribute attribute)
          Constructor.
 
Method Summary
 void clearRefinement()
          Clears any refinement made on this attribute.
 java.util.Map getInstanceMap()
          Get all the rows in a map firstcol->instance FIXME: better in Attribute than in AttributeReference
 java.util.Map getMap()
          Get all the rows in a map firstcol->secondcol.
 java.util.List getRows()
          Gets all the rows in a list of maps.
 java.util.List getScalars()
          Gets a list of scalars
 java.util.Iterator iterator()
          Called by the #foreach directive.
 void refine(java.lang.String criterium)
          Refines this attribute's reference result.
 void setOrder(java.lang.String order)
          Specify an 'order by' clause for this attribute reference result.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

refineCriteria

private java.util.List<java.lang.String> refineCriteria
Specified refining criteria defined on this attribute reference.


order

private java.lang.String order
Specified 'order by' clause specified for this attribute reference.


params

private java.util.Map<java.lang.String,java.lang.Object> params
The map this attribute reference applies to.


attribute

private Attribute attribute
The wrapped attribute.

Constructor Detail

AttributeReference

public AttributeReference(java.util.Map<java.lang.String,java.lang.Object> params,
                          Attribute attribute)
Constructor.

Parameters:
params - the parameters map this attribute reference applies to
attribute - the wrapped attribute
Method Detail

refine

public void refine(java.lang.String criterium)

Refines this attribute's reference result. The provided criterium will be added to the 'where' clause (or a 'where' clause will be added).

This method can be called several times, thus allowing a field-by-field handling of an html search form.

All criteria will be merged with the sql 'and' operator (if there is an initial where clause, it is wrapped into parenthesis).

Example : suppose we have defined the attribute 'person.children' as " *person(person_id):select * from person where parent_id=?". Then, if we issue the following calls from inside the template :

$bob.children.refine("age>18")
$bob.children.refine("gender='F'")

the resulting query that will be issed is :

select * from person where (parent_id=?) and (age>18) and (gender='F')

Parameters:
criterium - a valid sql condition

clearRefinement

public void clearRefinement()
Clears any refinement made on this attribute.


iterator

public java.util.Iterator iterator()
Called by the #foreach directive.

Returns a RowIterator on all possible instances of this entity, possibly previously refined and ordered.

Specified by:
iterator in interface java.lang.Iterable
Returns:
a RowIterator on instances of this entity, or null if an error occured.

getRows

public java.util.List getRows()
Gets all the rows in a list of maps.

Returns:
a list of all the rows

getScalars

public java.util.List getScalars()
Gets a list of scalars

Returns:
a list of scalars

getMap

public java.util.Map getMap()
Get all the rows in a map firstcol->secondcol. FIXME: better in Attribute than in AttributeReference

Returns:
a list of all the rows

getInstanceMap

public java.util.Map getInstanceMap()
Get all the rows in a map firstcol->instance FIXME: better in Attribute than in AttributeReference

Returns:
a list of all the rows

setOrder

public void setOrder(java.lang.String order)

Specify an 'order by' clause for this attribute reference result.

If an 'order by' clause is already present in the original query, the new one is appended (but successive calls to this method overwrite previous ones)

postfix " DESC " to a column for descending order.

Pass it null or an empty string to clear any ordering.

Parameters:
order - valid sql column names (separated by commas) indicating the desired order


~ooOoo~