velosurf.context
Class Instance

java.lang.Object
  extended byjava.util.AbstractMap
      extended byjava.util.HashMap
          extended byvelosurf.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

Nested Class Summary
 
Nested classes inherited from class java.util.HashMap
 
Nested classes inherited from class java.util.AbstractMap
 
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
 
Fields inherited from class java.util.AbstractMap
 
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.
 Entity getEntity()
          Get 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.
 java.lang.Object put(java.lang.Object key, java.lang.Object value)
          Generic setter
 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
clear, clone, containsKey, containsValue, entrySet, isEmpty, keySet, putAll, remove, size, values
 
Methods inherited from class java.util.AbstractMap
equals, hashCode, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, 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 Entity getEntity()
Get this Instance's Entity.

Returns:
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
Parameters:
inKey - key of the property to be returned
Returns:
a String, an Instance, an AttributeReference or null if an error occurs

put

public java.lang.Object put(java.lang.Object key,
                            java.lang.Object value)
Generic setter

Specified by:
put in interface java.util.Map
Parameters:
key - key of the property to be set
value - corresponding value
Returns:
previous value, or null

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