velosurf.context
Class EntityReference

java.lang.Object
  |
  +--java.util.AbstractCollection
        |
        +--java.util.AbstractList
              |
              +--velosurf.context.EntityReference
All Implemented Interfaces:
java.util.Collection, java.util.List

public class EntityReference
extends java.util.AbstractList

Context wrapper for an entity.

Author:
Claude Brisson

Field Summary
protected  Entity mEntity
          the wrapped entity
protected  java.util.Map mExternalParams
          The map of external query parameters used by children attributes
protected  java.lang.String mOrder
          specified order
protected  java.util.List mRefineCriteria
          specified refining criteria
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
EntityReference(Entity inEntity)
          Builds a new EntityReference.
 
Method Summary
 void clearRefinement()
          Clears any refinement made on this entity
 boolean delete(java.util.Map inValues)
          Detele a row from this entity's table.
 Instance fetch(java.util.List inValues)
          Fetch an Instance of this entity, specifying the values of its key columns in their natural order.
 Instance fetch(java.util.Map inValues)
          Fetch an Instance of this entity, specifying the values of its key columns in the map.
 Instance fetch(java.lang.Number inKeyValue)
          Fetch an Instance of this entity, specifying the value of its unique key column as an integer
 Instance fetch(java.lang.String inKeyValue)
          Fetch an Instance of this entity, specifying the value of its unique key column as a string
 java.lang.Object get(int i)
          Dummy method.
 long getLastInsertID()
           
 boolean insert(java.util.Map inValues)
          Insert a new row in this entity's table.
 java.util.Iterator iterator()
          Called by the #foreach directive.
 Instance newInstance()
          Create a new instance for this entity
 void refine(java.lang.String inCriterium)
          Refines this entity reference querying 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()
          Dummy method.
 boolean update(java.util.Map inValues)
          Update a row in this entity's table.
 
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, registerNatives, wait, wait, wait
 
Methods inherited from interface java.util.List
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray
 

Field Detail

mEntity

protected Entity mEntity
the wrapped entity

mOrder

protected java.lang.String mOrder
specified order

mRefineCriteria

protected java.util.List mRefineCriteria
specified refining criteria

mExternalParams

protected java.util.Map mExternalParams
The map of external query parameters used by children attributes
Constructor Detail

EntityReference

public EntityReference(Entity inEntity)
Builds a new EntityReference.
Parameters:
inEntity - the wrapped entity
Method Detail

insert

public boolean insert(java.util.Map inValues)
Insert a new row in this entity's table.
Parameters:
inValues - col -> value map
Returns:
true if successfull, false if an error occurs (in which case $db.lastError can be checked).

getLastInsertID

public long getLastInsertID()

update

public boolean update(java.util.Map inValues)
Update a row in this entity's table.

Velosurf will ensure all key columns are specified, to avoid an accidental massive update.

Parameters:
inValues - col -> value map
Returns:
true if successfull, false if an error occurs (in which case $db.lastError can be checked).

delete

public boolean delete(java.util.Map inValues)
Detele a row from this entity's table.

Velosurf will ensure all key columns are specified, to avoid an accidental massive update.

Parameters:
inValues - col -> value map
Returns:
true if successfull, false if an error occurs (in which case $db.lastError can be checked).

fetch

public Instance fetch(java.util.List inValues)
Fetch an Instance of this entity, specifying the values of its key columns in their natural order.
Parameters:
inValues - values of the key columns
Returns:
an Instance, or null if an error occured (in which case $db.lastError can be checked)

fetch

public Instance fetch(java.util.Map inValues)
Fetch an Instance of this entity, specifying the values of its key columns in the map.
Parameters:
inValues - key=>value map
Returns:
an Instance, or null if an error occured (in which case $db.lastError can be checked)

fetch

public Instance fetch(java.lang.String inKeyValue)
Fetch an Instance of this entity, specifying the value of its unique key column as a string
Parameters:
inKeyValue - value of the key column
Returns:
an Instance, or null if an error occured (in which case $db.lastError can be checked)

fetch

public Instance fetch(java.lang.Number inKeyValue)
Fetch an Instance of this entity, specifying the value of its unique key column as an integer
Parameters:
inKeyValue - value of the key column b * @return an Instance, or null if an error occured (in which case $db.lastError can be checked)

iterator

public java.util.Iterator iterator()
Called by the #foreach directive.
Overrides:
iterator in class java.util.AbstractList
Returns:
a RowIterator on all instances of this entity, possibly previously refined or ordered.

refine

public void refine(java.lang.String inCriterium)
Refines this entity reference querying 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 : if we issue the following calls from inside the template :

$person.refine("age>30")

$person.refine("salary>3000")

the resulting query that will be issed is :

select * from person where (age>30) and (salary>3000)

Parameters:
inCriterium - a valid sql condition

clearRefinement

public void clearRefinement()
Clears any refinement made on this entity


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

newInstance

public Instance newInstance()
Create a new instance for this entity
Returns:
null

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.
Overrides:
get in class java.util.AbstractList
Parameters:
i - ignored
Returns:
null

size

public int size()
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.
Overrides:
size in class java.util.AbstractCollection
Returns:
0


ooOoo