org.mmbase.module.core
Class ClusterNode

Package class diagram package ClusterNode
java.lang.Object
  extended by org.mmbase.module.core.MMObjectNode
      extended by org.mmbase.module.core.VirtualNode
          extended by org.mmbase.module.core.ClusterNode
All Implemented Interfaces:
Serializable, Cloneable, PublicCloneable<MMObjectNode>, SizeMeasurable

public class ClusterNode
extends VirtualNode

ClusterNode combines fields of different nodes in a single "virtual" node. This corresponds to the way that an SQL "join" select statement combines fields of different tables in result rows.

The individual fields are retrieved from a set of related nodes using a multilevel query, i.e. a query joining tables using the relations between the tables.

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:
$Id: ClusterNode.java 45315 2011-02-18 20:23:11Z michiel $
Author:
Pierre van Rooden
See Also:
ClusterBuilder, Serialized Form

Field Summary
 
Fields inherited from class org.mmbase.module.core.MMObjectNode
aliases, initializing, isNew, oldBuilder, parent, sequence, VALUE_SHORTED, values
 
Constructor Summary
ClusterNode(ClusterBuilder parent)
          Main contructor.
ClusterNode(ClusterBuilder parent, int nrofnodes)
          Main contructor.
 
Method Summary
 boolean commit()
          commit : commits the node to the database or other storage system.
 MMObjectBuilder getBuilder()
          Returns the actual builder of the node.
protected  String getBuilderName(String fieldName)
          Determines the builder name of a specified fieldname, i.e.
 byte[] getByteValue(String fieldName)
          Get a binary value of a certain field.
 MMObjectNode getRealNode(String builderName)
          Obtain the 'real' nodes, associated with a specified objectbuilder.
 Enumeration<MMObjectNode> getRelations()
          Return the relations of this node.
 long getSize(String fieldName)
          Returns the size (in byte) of the given field.
 String getStringValue(String fieldName)
          Get a value of a certain field.
 Object getValue(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(String fieldName, Object fieldValue)
          Sets a key/value pair in the main values of this node.
 void storeValue(String fieldName, 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
checkFieldExistance, getAge, getOType, getRelationCount, getRelationCount, hasRelations, insert, isVirtual
 
Methods inherited from class org.mmbase.module.core.MMObjectNode
cancel, checkSerializable, clearChanged, clone, commit, compareTo, createParameters, defaultEquals, defaultToString, delPropertiesCache, delRelationsCache, delRelationsCache, equals, finish, getAllRelations, getBooleanValue, getByteSize, getByteSize, getChanged, getContext, getDateValue, getDBState, getDBType, getDoubleValue, getFloatValue, getFunction, getFunctions, getFunctionValue, getGUIIndicator, getInputStreamValue, getIntegerValue, getIntValue, getListValue, getLongValue, getName, getNodeValue, getNumber, getOldBuilder, getOldValues, getPossibleContexts, getProperties, getProperty, getRelatedNodes, getRelatedNodes, getRelatedNodes, getRelatedNodes, getRelationNodes, getRelations, getRelations, getValues, getXMLValue, hashCode, insert, isNew, isNull, putProperty, remove, removeRelations, retrieveValue, sendFieldChangeSignal, setAlias, setBuilder, setContext, setSize, start, toString, toXML, useAliases
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ClusterNode

public ClusterNode(ClusterBuilder parent)
Main contructor.

Parameters:
parent - the node's parent

ClusterNode

public ClusterNode(ClusterBuilder parent,
                   int nrofnodes)
Main contructor.

Parameters:
parent - the node's parent
nrofnodes - 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(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

public void storeValue(String fieldName,
                       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(String fieldName,
                        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 String getBuilderName(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

getBuilder

public MMObjectBuilder getBuilder()
Description copied from class: MMObjectNode
Returns the actual builder of the node. Note that it is possible that, due to optimization, a node is currently associated with another (parent) builder, i.e. a posrel node may be associated with a insrel builder. This method returns the actual builder. The node may miss vital information (not retrieved from the database) to act as a node of such a builder - if you need actual status you need to reload it.

Overrides:
getBuilder in class MMObjectNode
Returns:
the builder of this node

getValue

public Object getValue(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

getSize

public long getSize(String fieldName)
Description copied from class: MMObjectNode
Returns the size (in byte) of the given field. This is mainly targeted at fields of the type byte array. For other fields this method will return something reasonable, but it is as yet not well defined what...

Overrides:
getSize in class MMObjectNode

getStringValue

public String getStringValue(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(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

getRelations

public Enumeration<MMObjectNode> getRelations()
Return the relations of this node. This is not allowed on a cluster node

Overrides:
getRelations in class VirtualNode
Returns:
empty Enumeration
Throws:
RuntimeException


MMBase2 Core 2.0-SNAPSHOT - 2013-05-29T22:08