velosurf.context
Class Instance

java.lang.Object
  |
  +--java.util.AbstractMap
        |
        +--java.util.HashMap
              |
              +--velosurf.context.Instance
All Implemented Interfaces:
java.lang.Cloneable, DataAccessor, java.util.Map, java.io.Serializable

public class Instance
extends java.util.HashMap
implements DataAccessor

An Instance provides field values by their name, choosing in a transparent way between the associated RowIterator or the Map its implement.

Author:
Claude Brisson
See Also:
Serialized Form

Inner classes inherited from class java.util.Map
java.util.Map.Entry
 
Field Summary
protected  DBConnection mDB
          the main database connection
protected  Entity mEntity
          this Instance's Entity
protected  RowIterator mRowIterator
          the associated RowIterator
 
Fields inherited from class java.util.HashMap
count, emptyHashIterator, ENTRIES, entrySet, KEYS, keySet, loadFactor, modCount, serialVersionUID, table, threshold, values, VALUES
 
Constructor Summary
Instance(Entity inEntity)
          Build an empty instance for the given entity
 
Method Summary
 boolean delete()
          Delete the row associated with this Instance.
 java.lang.Object get(java.lang.Object inKey)
          Generic getter, used to access this instance properties by their name.
 java.lang.String getEntity()
          Get the name of this Instance's Entity.
 java.lang.Object getInternal(java.lang.Object inKey)
          Internal getter : access only Map interface
 java.util.List getKeys()
          Deprecated. As of Velosurf version 0.9, replaced by getPrimaryKey Returns an ArrayList of two-entries maps ('name' & 'value'), meant to be use in a #foreach loop to build form fields, like :

#foreach ($field in $product.keys)

  <input type=hidden name='$field.name' value='$field.value'> #end

 java.util.List getPrimaryKey()
          Returns an ArrayList of two-entries maps ('name' & 'value'), meant to be use in a #foreach loop to build form fields, like :
protected  java.lang.String getTable()
          Get the name of the table mapped by this Instance's Entity.
 void initialize()
          Meant to be overloaded
 boolean insert()
          Insert a new row corresponding to this Instance.
 void setRowIterator(RowIterator inRowIterator)
          Set the RowIterator this Instance is bound to, when used in a #foreach directive.
 boolean update()
          Update the row associated with this Instance from passed values
 boolean update(java.util.Map inValues)
          Update the row associated with this Instance from actual values
 
Methods inherited from class java.util.HashMap
, capacity, clear, clone, containsKey, containsValue, entrySet, getHashIterator, isEmpty, keySet, loadFactor, put, putAll, readObject, rehash, remove, size, values, writeObject
 
Methods inherited from class java.util.AbstractMap
equals, hashCode, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, registerNatives, wait, wait, wait
 
Methods inherited from interface java.util.Map
equals, hashCode
 

Field Detail

mRowIterator

protected RowIterator mRowIterator
the associated RowIterator

mEntity

protected Entity mEntity
this Instance's Entity

mDB

protected DBConnection mDB
the main database connection
Constructor Detail

Instance

public Instance(Entity inEntity)
Build an empty instance for the given entity
Parameters:
inEntity - Entity this instance is a realisation of
Method Detail

initialize

public void initialize()
Meant to be overloaded

setRowIterator

public void setRowIterator(RowIterator inRowIterator)
Set the RowIterator this Instance is bound to, when used in a #foreach directive. Called by the framework.
Parameters:
inRowIterator - the RowIterator this Instance is bound to.

getEntity

public java.lang.String getEntity()
Get the name of this Instance's Entity.
Returns:
The name of this Instance's Entity.

getTable

protected java.lang.String getTable()
Get the name of the table mapped by this Instance's Entity.
Returns:
The name of the table mapped by this Instance's Entity.

getKeys

public java.util.List getKeys()
Deprecated. As of Velosurf version 0.9, replaced by getPrimaryKey Returns an ArrayList of two-entries maps ('name' & 'value'), meant to be use in a #foreach loop to build form fields, like :

#foreach ($field in $product.keys)

  <input type=hidden name='$field.name' value='$field.value'> #end

Returns:
an ArrayList of two-entries maps ('name' & 'value')

getPrimaryKey

public java.util.List getPrimaryKey()
Returns an ArrayList of two-entries maps ('name' & 'value'), meant to be use in a #foreach loop to build form fields, like :

#foreach ($field in $product.primaryKey)

  <input type=hidden name='$field.name' value='$field.value'> #end

Returns:
an ArrayList of two-entries maps ('name' & 'value')

get

public java.lang.Object get(java.lang.Object inKey)
Generic getter, used to access this instance properties by their name.

Asked property is first searched in the Map, then as a column of the bound RowIterator (if present), and at least among Attributes defined for the entity.

Specified by:
get in interface DataAccessor
Overrides:
get in class java.util.HashMap
Parameters:
inKey - key of the property to be returned
Returns:
a String, an Instance, an AttributeReference or null if an error occurs

getInternal

public java.lang.Object getInternal(java.lang.Object inKey)
Internal getter : access only Map interface
Parameters:
inKey - key of the property to be returned
Returns:
a String, an Instance, an AttributeReference or null if an error occurs

update

public boolean update()
Update the row associated with this Instance from passed values

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

Returns:
true if successfull, false if an error occurs (in which case $db.lastError can be checked).

update

public boolean update(java.util.Map inValues)
Update the row associated with this Instance from actual values

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

Parameters:
inValues - values to be used for the update
Returns:
true if successfull, false if an error occurs (in which case $db.lastError can be checked).

delete

public boolean delete()
Delete the row associated with this Instance.

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

Returns:
true if successfull, false if an error occurs (in which case $db.lastError can be checked).

insert

public boolean insert()
Insert a new row corresponding to this Instance.
Returns:
true if successfull, false if an error occurs (in which case $db.lastError can be checked).


ooOoo