com.boylesoftware.cb2
Class DynamicDataModel

java.lang.Object
  extended bycom.boylesoftware.cb2.DataModel
      extended bycom.boylesoftware.cb2.DynamicDataModel
All Implemented Interfaces:
java.util.Map, java.io.Serializable

public final class DynamicDataModel
extends DataModel
implements java.util.Map

Special implementation of Data Model, which is not associated with any specific result set, but is able to contain any data in a form of name-value mappings. A query can be associated with DynamicDataModel and then used with a DAO fetch call. The DAO then will return instances of DynamicDataModel containing data for all columns in the result set. The keys in the data model's map will be column labels aquired via getColumnLabel call on the JDBC's ResultSetMetaData object, and the values - objects returned by getObject method on the ResultSet.

Note, that although it is very tempting to use this class in many cases, it is significantly less efficient than using normal DMs, so it should be done only in very special cases.

This class is not synchronized.

Version:
$Id: DynamicDataModel.java,v 1.3 2004/05/19 14:24:05 levahim Exp $
Author:
Lev Himmelfarb
See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class java.util.Map
java.util.Map.Entry
 
Method Summary
 void clear()
           
 boolean containsKey(java.lang.Object key)
           
 boolean containsValue(java.lang.Object value)
           
 java.lang.String[] diff(DataModel dm)
          Finds fields that have different values in this DM and the specified one, which must be a DynamicDataModel too.
 java.util.Set entrySet()
           
 java.lang.Object get(java.lang.Object key)
           
 java.lang.Object getField(java.lang.String name)
          Gets a field's value by its name.
 boolean isEmpty()
           
 java.util.Set keySet()
           
 java.lang.Object put(java.lang.Object key, java.lang.Object value)
           
 void putAll(java.util.Map t)
           
 java.lang.Object remove(java.lang.Object key)
           
 void setField(java.lang.String name, java.lang.Object value)
          Sets a field's value by the field's name.
 int size()
           
 java.lang.String toString()
          Gives string representation of the data model including values of all its fields
 java.util.Collection values()
           
 
Methods inherited from class com.boylesoftware.cb2.DataModel
equals, hashCode
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
equals, hashCode
 

Method Detail

toString

public java.lang.String toString()
Gives string representation of the data model including values of all its fields

Overrides:
toString in class DataModel
Returns:
string representation of the data model.

diff

public java.lang.String[] diff(DataModel dm)
Finds fields that have different values in this DM and the specified one, which must be a DynamicDataModel too.

Overrides:
diff in class DataModel
Parameters:
dm - another dynamic DM.
Returns:
array of names of fields that have different values in this and the specified DM. Returns an empty array if the DMs are equal.
Throws:
java.lang.IllegalArgumentException - if type of the specified DM is not DynamicDataModel.

getField

public java.lang.Object getField(java.lang.String name)
                          throws java.lang.NoSuchFieldException
Gets a field's value by its name. In the case of a DynamicDataModel this does almost the same as the get method from the java.util.Map interface implemented by this class. The difference is that this method throws a NoSuchFieldException if the requested field does not exist, while the get method simply returns null.

Overrides:
getField in class DataModel
Parameters:
name - name of a DM field.
Returns:
the field's value.
Throws:
java.lang.NoSuchFieldException - if the requested field is not present in the DM.

setField

public void setField(java.lang.String name,
                     java.lang.Object value)
Sets a field's value by the field's name. In the case of a DynamicDataModel this is a complete analogue of put method from the java.util.Map interface implemented by this class.

Overrides:
setField in class DataModel
Parameters:
name - name of a DM field.
value - new value.

size

public int size()
Specified by:
size in interface java.util.Map

clear

public void clear()
Specified by:
clear in interface java.util.Map

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface java.util.Map

containsKey

public boolean containsKey(java.lang.Object key)
Specified by:
containsKey in interface java.util.Map

containsValue

public boolean containsValue(java.lang.Object value)
Specified by:
containsValue in interface java.util.Map

values

public java.util.Collection values()
Specified by:
values in interface java.util.Map

putAll

public void putAll(java.util.Map t)
Specified by:
putAll in interface java.util.Map

entrySet

public java.util.Set entrySet()
Specified by:
entrySet in interface java.util.Map

keySet

public java.util.Set keySet()
Specified by:
keySet in interface java.util.Map

get

public java.lang.Object get(java.lang.Object key)
Specified by:
get in interface java.util.Map

remove

public java.lang.Object remove(java.lang.Object key)
Specified by:
remove in interface java.util.Map

put

public java.lang.Object put(java.lang.Object key,
                            java.lang.Object value)
Specified by:
put in interface java.util.Map


Copyright © 2002,2003,2004 - Boyle Software, Inc.