|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.avaje.ebean.MapBean
public class MapBean
Map based EntityBean implementation. Used to dynamically create beans based on a table or nativeSql.
Note that MapBeans based on a table can be persisted via save(), insert() and delete(). MapBeans based on a nativeSql query are not persistable until the table to persist to has been set.
There are conveniance methods such as getInteger(), getBigDecimal() etc. The reason for these methods is that the values put into this map often come straight from the JDBC resultSet. Depending on the JDBC driver it may put a different type into a given property. For example an Integer, BigDecimal, Double could all be put into a property depending on the JDBC driver used. These conveniance methods automatically convert the value as required returning the type you expect.
// A "Relational mode" query...
// Get row from oe_order table where primary key = 10
FindByUid find = new FindByUid();
find.setTableName("oe_order");
find.setUid("10");
MapBean mapBean = (MapBean)Ebean.find(find);
// get some field data from order 10
Integer orderId = mapBean.getInteger("id");
Integer custId = mapBean.getInteger("cust_id");
...
// update the order status and save
mapBean.setString("status_code","SHIPPED");
Ebean.save(mapBean);
Nested Class Summary |
---|
Nested classes/interfaces inherited from interface java.util.Map |
---|
java.util.Map.Entry<K,V> |
Constructor Summary | |
---|---|
MapBean() Create a new MapBean based on a LinkedHashMap with default initialCapacity (of 16). |
|
MapBean(int initialCapacity, float loadFactor) Create with an initialCapacity and loadFactor. |
|
MapBean(java.util.Map map) Create with a specific Map implementation. |
Method Summary | |
---|---|
void |
clear() Clear the map. |
java.lang.Object |
clone() Return a clone of this MapBean. |
boolean |
containsKey(java.lang.Object key) Returns true if the map contains the property. |
boolean |
containsValue(java.lang.Object value) Returns true if the map contains the value. |
java.util.Set |
entrySet() Returns the entrySet of the map. |
boolean |
equals(java.lang.Object o) Equal is based on the id property. |
java.lang.Object |
get(java.lang.Object name) Return a property value by its name. |
java.math.BigDecimal |
getBigDecimal(java.lang.Object name) Return a property value as a BigDecimal. |
java.sql.Date |
getDate(java.lang.Object name) Return the property as a sql date. |
java.lang.Double |
getDouble(java.lang.Object name) Return the property value as a Double. |
EntityBeanIntercept |
getEbeanIntercept() Return the EntityBeanIntercept that controls the method interception and old values creation. |
java.lang.Object |
getId() Return the Id value based on the ID property name. |
java.lang.String |
getIdPropertyName() Return the ID property name. |
java.lang.Integer |
getInteger(java.lang.Object name) Return a property as an Integer. |
java.lang.Long |
getLong(java.lang.Object name) Return a property value as a Long. |
java.lang.String |
getString(java.lang.Object name) Return a property as a String. |
java.lang.String |
getTableName() Return the table name for this bean. |
java.sql.Timestamp |
getTimestamp(java.lang.Object name) &nF="../../../com/avaje/ebean/MapBean.html#put(java.lang.Object, java.lang.Object)">put(java.lang.Object name, java.lang.Object value) Set a value to a property. |
void |
putAll(java.util.Map t) Put all the values from t into this map. |
java.lang.Object |
remove(java.lang.Object name) Remove a property from the map. |
void |
resetOldValues() Resets the oldValues back to null and ebeanIntercept 'loaded' to false. |
java.lang.Object |
set(java.lang.Object name, java.lang.Object value) Exactly the same as the put method. |
void |
setEbeanIntercept(EntityBeanIntercept ebi) Not allowed for MapBeans. |
void |
setIdPropertyName(java.lang.String idPropertyName) Set the ID property name. |
void |
setTableName(java.lang.String tableName) Set the table name. |
void |
setTypeConverter(com.avaje.ebean.util.TypeConverter typeConverter) Set the utility object use to provide type conversion. |
int |
size() Return the size of the map. |
java.lang.String |
toString() String description of the underlying map. |
java.util.Collection |
values() Return the values from this map. |
Methods inherited from class java.lang.Object |
---|
getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public MapBean(java.util.Map map)
The default Map implementation is LinkedHashMap.
public MapBean()
public MapBean(int initialCapacity, float loadFactor)
The defaults of these are 16 and 0.75.
Note that the Map will rehash the contents when the number of keys in this map reaches its threshold (initialCapacity * loadFactor).
Method Detail |
---|
public void setTypeConverter(com.avaje.ebean.util.TypeConverter typeConverter)
This is used for getInteger, getBigDecimal etc.
public void setEbeanIntercept(EntityBeanIntercept ebi)
setEbeanIntercept
in interface EntityBean
public EntityBeanIntercept getEbeanIntercept()
getEbeanIntercept
in interface EntityBean
public void resetOldValues()
Use this to force an insert or if you want to set additional data to the bean without creating the old values.
Note that you will need to call ebeanSetLoaded(true) after this for old values to be created.
public java.lang.String getTableName()
public void setTableName(java.lang.String tableName)
public void setIdPropertyName(java.lang.String idPropertyName)
This property name is used by equals to try to do equality based on the value of the unique id.
This is not set for tables with concatinated primary keys.
public java.lang.String getIdPropertyName()
public java.lang.Object getId()
public boolean equals(java.lang.Object o)
If the id is null then this uses an object and equality becomes == (same instance).
equals
in interface java.util.Map
equals
in class java.lang.Object
public int hashCode()
hashCode
in interface java.util.Map
hashCode
in class java.lang.Object
public java.lang.Object clone()
clone
in class java.lang.Object
public java.util.Iterator keys()
Internally this uses LinkedHashMap and so the order of the property names should be predicatable and ordered by the use of LinkedHashMap.
public java.lang.Object remove(java.lang.Object name)
remove
in interface java.util.Map
public java.lang.Object get(java.lang.Object name)
get
in interface java.util.Map
public java.lang.Object put(java.lang.Object name, java.lang.Object value)
put
in interface java.util.Map
public java.lang.Object set(java.lang.Object name, java.lang.Object value)
I added this method because it seems more bean like to have get and set methods.
public java.lang.Integer getInteger(java.lang.Object name)
public java.math.BigDecimal getBigDecimal(java.lang.Object name)
public java.lang.Long getLong(java.lang.Object name)
public java.lang.Double getDouble(java.lang.Object name)
public java.lang.String getString(java.lang.Object name)
public java.util.Date getUtilDate(java.lang.Object name)
public java.sql.Date getDate(java.lang.Object name)
public java.sql.Timestamp getTimestamp(java.lang.Object name)
public java.lang.String toString()
toString
in class java.lang.Object
public void clear()
clear
in interface java.util.Map
public boolean containsKey(java.lang.Object key)
containsKey
in interface java.util.Map
public boolean containsValue(java.lang.Object value)
containsValue
in interface java.util.Map
public java.util.Set keySet()
keySet
in interface java.util.Map
public void putAll(java.util.Map t)
putAll
in interface java.util.Map
public int size()
size
in interface java.util.Map
public java.util.Collection values()
values
in interface java.util.Map
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |