org.mmbase.module.core
Class ClusterNode

java.lang.Object
  |
  +--org.mmbase.module.core.MMObjectNode
        |
        +--org.mmbase.module.core.VirtualNode
              |
              +--org.mmbase.module.core.ClusterNode

public class ClusterNode
extends VirtualNode

ClusterNode is a representation of a 'cluster' of objectnodes. It represents a set of related nodes, retrieved using a multilevel query. This class overrides a number of methods, allowing direct access to data in the nodes which form the 'virtual' node.
In future releases, data will NOT be stored directkly in this node anymore. Instead, it will be stored in the underlying MMObjectNodes. For reasons of optiomalization, however, we cannot do this right now. MMObjectNode will need a status field that allows us to recognize whether it is fully loaded, partially loaded, or being edited. This can then be checked in 'retrievevalue'. In addition, to prevent caching conflicts, nodes will need to maintain their references. This allows for a secure caching mechanism.
Among other things, this allows one to change values in a multilevel node, or to access functionality that would otherwise be restricted to 'real' nodes.

Version:
26 Apr 2001
Author:
Pierre van Rooden

Field Summary
 boolean initializing
          Determines whether the node is being loaded.
protected  java.util.Hashtable nodes
          Holds the name - value pairs of related nodes in this virtual node.
 
Fields inherited from class org.mmbase.module.core.MMObjectNode
alias, changed, parent, prefix, properties, values, virtual
 
Constructor Summary
ClusterNode(MMObjectBuilder parent)
          Main contructor.
ClusterNode(MMObjectBuilder parent, int nrofnodes)
          Main contructor.
 
Method Summary
 boolean commit()
          commit : commits the node to the database or other storage system this can only be done on a existing (inserted) node.
protected  java.lang.String getBuilderName(java.lang.String fieldname)
          Determines the builder name of a specified fieldname, i.e.
 byte[] getByteValue(java.lang.String fieldname)
          Get a binary value of a certain field.
 MMObjectNode getRealNode(java.lang.String buildername)
          Obtain the 'real' nodes, associated with a specified objectbuilder.
 java.lang.String getStringValue(java.lang.String fieldname)
          Get a value of a certain field.
 java.lang.Object getValue(java.lang.String fieldname)
          Get a value of a certain field.
 boolean isChanged()
          Tests whether one of the values of this node was changed since the last commit/insert.
 boolean setValue(java.lang.String fieldname, java.lang.Object fieldvalue)
          Sets a key/value pair in the main values of this node.
protected  void storeValue(java.lang.String fieldname, java.lang.Object fieldvalue)
          Stores a value in the values hashtable.
 void testValidData()
          Tests whether the data in a node is valid (throws an exception if this is not the case).
 
Methods inherited from class org.mmbase.module.core.VirtualNode
getAge, getRelationCount, getRelationCount, getRelations, hasRelations, insert
 
Methods inherited from class org.mmbase.module.core.MMObjectNode
clearChanged, delPropertiesCache, delRelationsCache, getAlias, getAllRelations, getBooleanValue, getChanged, getDBState, getDBType, getDoubleValue, getDutchSName, getFloatValue, getGUIIndicator, getIntegerValue, getIntValue, getLongValue, getName, getNodeValue, getNumber, getOType, getProperties, getProperty, getRelatedNodes, getRelatedNodes, getRelationCacheHits, getRelationCacheMiss, getRelations, getRelations, getTableName, getValueAsString, getValues, insertDone, isVirtual, preEdit, putProperty, removeRelations, retrieveValue, sendFieldChangeSignal, setAlias, setParent, setValue, setValue, setValue, setValue, toString, toXML
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

nodes

protected java.util.Hashtable nodes
Holds the name - value pairs of related nodes in this virtual node.

initializing

public boolean initializing
Determines whether the node is being loaded.
Constructor Detail

ClusterNode

public ClusterNode(MMObjectBuilder parent)
Main contructor.
Parameters:
parent - the node's parent, generally an instance of the ClusterBuilder builder.

ClusterNode

public ClusterNode(MMObjectBuilder parent,
                   int nrofnodes)
Main contructor.
Parameters:
parent - the node's parent, generally an instance of the ClusterBuilder builder.
rnofnodes - Nr of referenced nodes.
Method Detail

testValidData

public void testValidData()
                   throws InvalidDataException
Tests whether the data in a node is valid (throws an exception if this is not the case). The call is performed on all loaded 'real' nodes. If a 'real' node has not previously been forcably loaded, it is assumed to be correct.
Overrides:
testValidData in class MMObjectNode
Throws:
InvalidDataException - If the data was unrecoverably invalid (the references did not point to existing objects)

commit

public boolean commit()
commit : commits the node to the database or other storage system this can only be done on a existing (inserted) node. it will use the changed Vector as its base of what to commit/changed
Overrides:
commit in class VirtualNode
Returns:
true if the commit was succesfull, false is it failed

getRealNode

public MMObjectNode getRealNode(java.lang.String buildername)
Obtain the 'real' nodes, associated with a specified objectbuilder.
Parameters:
buildername - the name of the builder of the requested node, as known within the virtual node
Returns:
the node, or null if it does not exist or is unknown

storeValue

protected void storeValue(java.lang.String fieldname,
                          java.lang.Object fieldvalue)
Stores a value in the values hashtable. If the value is not stored in the virtualnode, the 'real' node is used instead.
Overrides:
storeValue in class MMObjectNode
Parameters:
fieldname - the name of the field to change
fieldValue - the value to assign

setValue

public boolean setValue(java.lang.String fieldname,
                        java.lang.Object fieldvalue)
Sets a key/value pair in the main values of this node. Note that if this node is a node in cache, the changes are immediately visible to everyone, even if the changes are not committed. The fieldname is added to the (public) 'changed' vector to track changes.
Overrides:
setValue in class MMObjectNode
Parameters:
fieldname - the name of the field to change
fieldValue - the value to assign
Returns:
always true

getBuilderName

protected java.lang.String getBuilderName(java.lang.String fieldname)
Determines the builder name of a specified fieldname, i.e. "news" in "news.title",
Parameters:
fieldname - the name of the field
Returns:
the buidler name of the field

getValue

public java.lang.Object getValue(java.lang.String fieldname)
Get a value of a certain field.
Overrides:
getValue in class MMObjectNode
Parameters:
fieldname - the name of the field who's data to return
Returns:
the field's value as an Object

getStringValue

public java.lang.String getStringValue(java.lang.String fieldname)
Get a value of a certain field. The value is returned as a String. Non-string values are automatically converted to String.
Overrides:
getStringValue in class MMObjectNode
Parameters:
fieldname - the name of the field who's data to return
Returns:
the field's value as a String

getByteValue

public byte[] getByteValue(java.lang.String fieldname)
Get a binary value of a certain field.
Overrides:
getByteValue in class MMObjectNode
Parameters:
fieldname - the name of the field who's data to return
Returns:
the field's value as an byte [] (binary/blob field)

isChanged

public boolean isChanged()
Tests whether one of the values of this node was changed since the last commit/insert.
Overrides:
isChanged in class MMObjectNode
Returns:
true if changes have been made, false otherwise


MMBase 2001