velosurf.context
Class AttributeReference

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractList
          extended by velosurf.context.AttributeReference
All Implemented Interfaces:
java.lang.Iterable, java.util.Collection, java.util.List

public class AttributeReference
extends java.util.AbstractList

Context wrapper for attributes

Author:
Claude Brisson

Field Summary
protected  Attribute mAttribute
          The wrapped attribute.
protected  DataAccessor mDataAccessor
          The data accessor this attribute reference applies to.
protected  java.lang.String mOrder
          Specified 'order by' clause specified for this attribute reference.
protected  java.util.List mRefineCriteria
          Specified refining criteria defined on this attribute reference.
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
AttributeReference(DataAccessor inDataAccessor, Attribute inAttribute)
          Constructor for attributes
 
Method Summary
 void clearRefinement()
          Clears any refinement made on this attribute
 java.lang.Object get(int i)
          Dummy method.
 java.util.List getRows()
          gets all the rows in a list of maps
 java.util.Iterator iterator()
          Called by the #foreach directive.
 void refine(java.lang.String inCriterium)
          Refines this attribute's reference result : the provided criterium will be added to the 'where' clause (or a 'where' clause will be added).
 void setOrder(java.lang.String inOrder)
          Specify an 'order by' clause for this attribute reference result.
 int size()
          Not yet implemented.
 
Methods inherited from class java.util.AbstractList
add, add, addAll, clear, equals, hashCode, indexOf, lastIndexOf, listIterator, listIterator, remove, removeRange, set, subList
 
Methods inherited from class java.util.AbstractCollection
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.List
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray
 

Field Detail

mRefineCriteria

protected java.util.List mRefineCriteria
Specified refining criteria defined on this attribute reference.


mOrder

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


mDataAccessor

protected DataAccessor mDataAccessor
The data accessor this attribute reference applies to.


mAttribute

protected Attribute mAttribute
The wrapped attribute.

Constructor Detail

AttributeReference

public AttributeReference(DataAccessor inDataAccessor,
                          Attribute inAttribute)
Constructor for attributes

Parameters:
inDataAccessor - the data accessor this attribute reference applies to
inAttribute - the wrapped attribute
Method Detail

refine

public void refine(java.lang.String inCriterium)
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:
inCriterium - 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
Specified by:
iterator in interface java.util.Collection
Specified by:
iterator in interface java.util.List
Overrides:
iterator in class java.util.AbstractList
Returns:
a RowIterator on instances of this entity, or null if an error occured.

getRows

public java.util.List getRows()
                       throws java.sql.SQLException
gets all the rows in a list of maps

Returns:
a list of all the rows
Throws:
java.sql.SQLException

setOrder

public void setOrder(java.lang.String inOrder)
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)

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

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

get

public java.lang.Object get(int i)
Dummy method. Since this class has to appear as a Collection for Velocity, it extends the AbstractList class but only the iterator() method has a real meaning.

Specified by:
get in interface java.util.List
Specified by:
get in class java.util.AbstractList
Parameters:
i - ignored
Returns:
null

size

public int size()
Not yet implemented. Will return the number of rows.

Specified by:
size in interface java.util.Collection
Specified by:
size in interface java.util.List
Specified by:
size in class java.util.AbstractCollection
Returns:
0


~ooOoo~