|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.util.AbstractMap<K,V> java.util.TreeMap<java.lang.String,java.lang.Object> velosurf.context.Instance
public class Instance
An Instance provides field values by their name.
Nested Class Summary |
---|
Nested classes/interfaces inherited from class java.util.AbstractMap |
---|
java.util.AbstractMap.SimpleEntry<K,V>, java.util.AbstractMap.SimpleImmutableEntry<K,V> |
Field Summary | |
---|---|
protected Database |
db
The main database connection. |
protected java.util.List<java.lang.Boolean> |
dirtyFlags
Keep a dirty flag per column |
protected Entity |
entity
This Instance's Entity. |
private boolean |
localized
Is there a column to localize? |
Constructor Summary | |
---|---|
Instance()
Build an empty instance for the given entity. |
|
Instance(Entity entity)
Build an empty instance for the given entity. |
|
Instance(java.util.Map<java.lang.String,java.lang.Object> values)
Builds a generic instance using values . |
|
Instance(java.util.Map<java.lang.String,java.lang.Object> values,
Database db)
Builds a generic instance using values . |
Method Summary | |
---|---|
boolean |
containsKey(java.lang.Object key)
Check for a key |
boolean |
delete()
Delete the row associated with this Instance. |
boolean |
equals(java.lang.Object o)
Test equality of two instances. |
java.lang.Object |
get(java.lang.Object k)
Generic getter, used to access this instance properties by their name. |
EntityReference |
getEntity()
Get this Instance's Entity. |
java.lang.Object |
getExternal(java.lang.Object key)
External getter. |
java.lang.Object |
getInternal(java.lang.Object key)
Internal getter. |
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. |
java.lang.Object |
getWithParams(java.lang.String key,
java.util.Map params)
Default method handler, called by Velocity when it did not find the specified method. |
private void |
handleSQLException(java.sql.SQLException sqle)
Handle an sql exception. |
void |
initialize(Entity entity)
Initialization. |
boolean |
insert()
Insert a new row corresponding to this Instance. |
java.lang.Object |
put(java.lang.String key,
java.lang.Object value)
Generic setter. |
java.lang.Object |
remove(java.lang.Object key)
Removes an association |
protected java.lang.String |
resolveName(java.lang.String name)
|
void |
setClean()
|
void |
setColumnValues(java.util.Map<java.lang.String,java.lang.Object> values)
Global setter that will only set values the correspond to actual columns (otherwise, use putAll(Map values)). |
java.lang.String |
toString()
Inherit toString to avoid listing cached AttributeReference |
boolean |
update()
Update the row associated with this Instance from passed values. |
boolean |
update(java.util.Map<java.lang.String,java.lang.Object> values)
Update the row associated with this Instance from actual values. |
boolean |
upsert()
Insert or update, depending on whether or not a value for the id key is present and does exist |
boolean |
upsert(java.util.Map<java.lang.String,java.lang.Object> values)
Insert or update, depending on whether or not a value for the id key is present and does exist |
boolean |
validate()
Validate this instance against declared contraints. |
Methods inherited from class java.util.TreeMap |
---|
ceilingEntry, ceilingKey, clear, clone, comparator, containsValue, descendingKeySet, descendingMap, entrySet, firstEntry, firstKey, floorEntry, floorKey, headMap, headMap, higherEntry, higherKey, keySet, lastEntry, lastKey, lowerEntry, lowerKey, navigableKeySet, pollFirstEntry, pollLastEntry, putAll, size, subMap, subMap, tailMap, tailMap, values |
Methods inherited from class java.util.AbstractMap |
---|
hashCode, isEmpty |
Methods inherited from class java.lang.Object |
---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
Methods inherited from interface java.util.Map |
---|
hashCode, isEmpty |
Field Detail |
---|
protected Entity entity
private boolean localized
protected Database db
protected java.util.List<java.lang.Boolean> dirtyFlags
Constructor Detail |
---|
public Instance()
public Instance(Entity entity)
entity
- Entity this instance is a realisation ofpublic Instance(java.util.Map<java.lang.String,java.lang.Object> values)
values
.
values
- public Instance(java.util.Map<java.lang.String,java.lang.Object> values, Database db)
values
.
values
- db
- Method Detail |
---|
public void initialize(Entity entity)
entity
- public EntityReference getEntity()
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.
Example:
#foreach ($field in $product.primaryKey)
<input type=hidden name='$field.name' value='$field.value'>
#end
Please note that this method won't be of any help if you are using column aliases.
public java.lang.Object get(java.lang.Object k)
Generic getter, used to access this instance properties by their name.
Asked property is first searched in the Map, then among Attributes defined for the entity.
get
in interface java.util.Map<java.lang.String,java.lang.Object>
get
in class java.util.TreeMap<java.lang.String,java.lang.Object>
k
- key of the property to be returned
public java.lang.Object getWithParams(java.lang.String key, java.util.Map params)
getWithParams
in interface HasParametrizedGetter
key
- asked keyparams
- passed parametersHasParametrizedGetter
public java.lang.Object put(java.lang.String key, java.lang.Object value)
put
in interface java.util.Map<java.lang.String,java.lang.Object>
put
in class java.util.TreeMap<java.lang.String,java.lang.Object>
key
- key of the property to be setvalue
- corresponding value
public void setClean()
public void setColumnValues(java.util.Map<java.lang.String,java.lang.Object> values)
values
- corresponding valuespublic java.lang.Object getInternal(java.lang.Object key)
key
- key of the property to be returned
public java.lang.Object getExternal(java.lang.Object key)
key
- key of the property to be returned
public boolean equals(java.lang.Object o)
equals
in interface java.util.Map<java.lang.String,java.lang.Object>
equals
in class java.util.AbstractMap<java.lang.String,java.lang.Object>
o
- other instance
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.
true
if successfull, false
if an error
occurs (in which case $db.error can be checked).public boolean update(java.util.Map<java.lang.String,java.lang.Object> values)
Update the row associated with this Instance from actual values.
Velosurf will ensure all key columns are specified, to avoid an accidental massive update.
values
- values to be used for the update
true
if successfull, false
if an error
occurs (in which case $db.error can be checked).public boolean delete()
Delete the row associated with this Instance.
Velosurf will ensure all key columns are specified, to avoid an accidental massive update.
true
if successfull, false
if an error
occurs (in which case $db.error can be checked).public boolean insert()
true
if successfull, false
if an error
occurs (in which case $db.error can be checked).public boolean validate()
private void handleSQLException(java.sql.SQLException sqle)
protected java.lang.String resolveName(java.lang.String name)
public boolean containsKey(java.lang.Object key)
containsKey
in interface java.util.Map<java.lang.String,java.lang.Object>
containsKey
in class java.util.TreeMap<java.lang.String,java.lang.Object>
public java.lang.Object remove(java.lang.Object key)
remove
in interface java.util.Map<java.lang.String,java.lang.Object>
remove
in class java.util.TreeMap<java.lang.String,java.lang.Object>
public java.lang.String toString()
toString
in class java.util.AbstractMap<java.lang.String,java.lang.Object>
public boolean upsert()
public boolean upsert(java.util.Map<java.lang.String,java.lang.Object> values)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |