org.mmbase.module.core
Class ClusterBuilder

java.lang.Object
  |
  +--org.mmbase.module.core.MMTable
        |
        +--org.mmbase.module.core.MMObjectBuilder
              |
              +--org.mmbase.module.core.VirtualBuilder
                    |
                    +--org.mmbase.module.core.ClusterBuilder

public class ClusterBuilder
extends VirtualBuilder

ClusterBuilder is a builder which creates 'virtual' nodes. This is an alternate class for 'MultiRelations', which will be used by the MMCI. The old class may eventually get deprecated, but is supported to allow the new system to be developed without accidentally breaking older code.
The nodes are build out of a set of fields from different nodes, combined through a complex query, which is in turn based on the relations that exist between nodes.
The builder supplies a method to retrieve these virtual nodes, searchMultiLevelVector(int, java.util.Vector, java.lang.String, java.util.Vector, java.lang.String, java.util.Vector, java.util.Vector). Other public methods in this builder function to handle the requests for data obtained from this particular node. Individual nodes in a 'cluster' node can be retrieved by calling the getNodeValue() method, with the builder name of the needed node as parameter value.

Version:
$Id: ClusterBuilder.java,v 1.4.2.1 2002/03/18 14:24:59 pierre Exp $
Author:
Rico Jansen, Pierre van Rooden

Field Summary
static int SEARCH_ALL
          Search for all relations.
static int SEARCH_BOTH
          Search for all valid relations.
static int SEARCH_DESTINATION
          Search for destinations, When searching relations, return only relations from source to deastination.
static int SEARCH_EITHER
          Search for either destination or source.
static int SEARCH_SOURCE
          Seach for sources.
 
Fields inherited from class org.mmbase.module.core.MMObjectBuilder
broadcastChanges, className, database, debug, description, descriptions, fields, NODE_MAX_SIZE, nodeCache, obj2type, OBJ2TYPE_MAX_SIZE, oType, replaceCache, searchAge, sortedDBLayout, TEMPNODE_DEFAULT_SIZE, TemporaryNodes, virtual
 
Fields inherited from class org.mmbase.module.core.MMTable
mmb, tableName
 
Constructor Summary
ClusterBuilder(MMBase m)
          Creates an instance of the MultiRelations builder.
 
Method Summary
 java.lang.String getBuilderNameFromField(java.lang.String fieldname)
          Determines the builder part of a specified field.
 int getDBState(java.lang.String fieldName)
          Return a field's database state.
 int getDBType(java.lang.String fieldName)
          Return a field's database type.
 java.lang.String getFieldNameFromField(java.lang.String fieldname)
          Determines the fieldname part of a specified field (without the builder name).
 java.lang.String getGUIIndicator(MMObjectNode node)
          What should a GUI display for this node.
 java.lang.String getGUIIndicator(java.lang.String field, MMObjectNode node)
          What should a GUI display for this node/field combo.
 MMObjectNode getNewNode(java.lang.String owner)
          Get a new node, using this builder as its parent.
protected  java.lang.String getRelationString(java.util.Vector alltables)
          Creates a condition string which checks the relations between nodes.
protected  java.lang.String getRelationString(java.util.Vector alltables, int searchdir, java.util.HashMap roles)
          Creates a condition string which checks the relations between nodes.
protected  java.lang.String getSelectString(java.util.Vector alltables, java.util.Vector rfields)
          Creates a select string for the Multi level query.
protected  java.lang.String getSelectString(java.util.Vector alltables, java.util.Vector originaltables, java.util.Vector rfields, boolean includeAllReferences)
          Creates a select string for the Multi level query.
 byte[] getShortedByte(java.lang.String fieldname, int number)
          Get binary data of a database blob field.
 java.lang.String getShortedText(java.lang.String fieldname, int number)
          Get text from a blob field.
protected  java.lang.String getTableString(java.util.Vector alltables)
          This method defines what is 'allowed' in tablenames.
protected  java.lang.String getTableString(java.util.Vector alltables, java.util.HashMap roles)
          This method defines what is 'allowed' in tablenames.
protected  java.lang.String idx2char(int idx)
          Converts an index to a one-character string.
 java.util.Vector searchMultiLevelVector(int snode, java.util.Vector fields, java.lang.String pdistinct, java.util.Vector tables, java.lang.String where, java.util.Vector orderVec, java.util.Vector direction)
          Return all the objects that match the searchkeys.
 java.util.Vector searchMultiLevelVector(java.util.Vector snodes, java.util.Vector fields, java.lang.String pdistinct, java.util.Vector tables, java.lang.String where, java.util.Vector orderVec, java.util.Vector direction)
          Return all the objects that match the searchkeys.
 java.util.Vector searchMultiLevelVector(java.util.Vector snodes, java.util.Vector fields, java.lang.String pdistinct, java.util.Vector tables, java.lang.String where, java.util.Vector orderVec, java.util.Vector direction, int searchdir)
          Return all the objects that match the searchkeys.
 
Methods inherited from class org.mmbase.module.core.VirtualBuilder
create, init, insert
 
Methods inherited from class org.mmbase.module.core.MMObjectBuilder
addField, addLocalObserver, addRemoteObserver, buildSet, checkAddTmpField, commit, convertMMNode2SQL, count, createAlias, created, debug, deleteNodeCache, executeFunction, fieldLocalChanged, getAge, getAliasedNode, getCacheNumbers, getCacheSize, getCacheSize, getClassName, getDBByte, getDBKey, getDBText, getDefaultTeaser, getDefaultUrl, getDescription, getDescriptions, getDutchSName, getEditFields, getField, getFieldNames, getFields, getFullTableName, getFunctionParameters, getHardNode, getHardNode, getHTML, getInitParameter, getInitParameters, getList, getMachineName, getMaintainer, getNewTmpNode, getNextField, getNode, getNode, getNode, getNode, getNodeType, getNumberFromName, getPluralName, getPluralName, getPluralNames, getRelations_main, getSearchAge, getShort, getSingularName, getSingularName, getSingularNames, getSmartPath, getSortedFields, getSortedListFields, getTableName, getTmpNode, getURLEncode, getValue, getVersion, getWAP, getXMLPath, getXMLSetup, hostname_function, init_obj2type, insert, insertDone, isNodeCached, isVirtual, isXMLConfig, nodeLocalChanged, nodeRemoteChanged, preCommit, preEdit, process, putTmpNode, readSearchResults, removeField, removeNode, removeRelations, removeTmpNode, replace, safeCache, safeCommit, safeInsert, search, search, search, searchIn, searchIn, searchIn, searchNumbers, searchVector, searchVector, searchVector, searchVector, searchVectorIn, searchVectorIn, searchVectorIn, searchVectorIn, searchWithWhere, sendFieldChangeSignal, setClassName, setDBLayout_xml, setDBLayout, setDebug, setDefaults, setDescription, setDescriptions, setDutchSName, setInitParameter, setMaintainer, setMMBase, setPluralNames, setSearchAge, setSingularNames, setTableName, setValue, setValue, setVersion, setXmlConfig, setXMLPath, setXMLValues, signalNewObject, testValidData, toXML, waitUntilNodeChanged, wrap
 
Methods inherited from class org.mmbase.module.core.MMTable
size
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SEARCH_BOTH

public static final int SEARCH_BOTH
Search for all valid relations. When searching relations, return both relations from source to deastination and from destination to source, provided directionality allows

SEARCH_DESTINATION

public static final int SEARCH_DESTINATION
Search for destinations, When searching relations, return only relations from source to deastination.

SEARCH_SOURCE

public static final int SEARCH_SOURCE
Seach for sources. When searching a multilevel, return only relations from destination to source, provided directionality allows

SEARCH_ALL

public static final int SEARCH_ALL
Search for all relations. When searching a multilevel, return both relations from source to deastination and from destination to source. Directionality is not checked - ALL relations are used.

SEARCH_EITHER

public static final int SEARCH_EITHER
Search for either destination or source. When searching a multilevel, return either relations from source to destination OR from destination to source. The returned set is decided through the typerel tabel. However, if both directiosn ARE somehow supported, the system onyl returns source to destination relations. This is the default value (for compatibility purposes).
Constructor Detail

ClusterBuilder

public ClusterBuilder(MMBase m)
Creates an instance of the MultiRelations builder. Called from the MMBase class.
Parameters:
m - the MMbase cloud creating the node
Method Detail

getNewNode

public MMObjectNode getNewNode(java.lang.String owner)
Get a new node, using this builder as its parent. The new node is a cluster node. Unlike most other nodes, a cluster node does not have a number, owner, or otype fields.
Overrides:
getNewNode in class VirtualBuilder
Parameters:
owner - The administrator creating the new node (ignored).
Returns:
A newly initialized VirtualNode.

getGUIIndicator

public java.lang.String getGUIIndicator(MMObjectNode node)
What should a GUI display for this node. This version displays the contents of the 'name' field(s) that were retrieved. XXX: should be changed to something better
Overrides:
getGUIIndicator in class VirtualBuilder
Parameters:
node - The node to display
Returns:
the display of the node as a String

getGUIIndicator

public java.lang.String getGUIIndicator(java.lang.String field,
                                        MMObjectNode node)
What should a GUI display for this node/field combo. For a multilevel node, the builder tries to determine the original builder of a field, and invoke the method using that builder. XXX: should retrieve the actual node belonging to the field, instead...
Overrides:
getGUIIndicator in class MMObjectBuilder
Parameters:
node - The node to display
field - the name field of the field to display
Returns:
the display of the node's field as a String, null if not specified

getBuilderNameFromField

public java.lang.String getBuilderNameFromField(java.lang.String fieldname)
Determines the builder part of a specified field.
Parameters:
fieldname - the name of the field
Returns:
the name of the field's builder

getFieldNameFromField

public java.lang.String getFieldNameFromField(java.lang.String fieldname)
Determines the fieldname part of a specified field (without the builder name).
Parameters:
fieldname - the name of the field
Returns:
the name of the field without its builder

getDBType

public int getDBType(java.lang.String fieldName)
Return a field's database type. The returned value is one of the following values declared in FieldDefs: TYPE_STRING, TYPE_INTEGER, TYPE_BYTE, TYPE_FLOAT, TYPE_DOUBLE, TYPE_LONG, or TYPE_UNKNOWN (returned if the original builder of the field cannot be determined)
Overrides:
getDBType in class MMObjectBuilder
Parameters:
the - requested field's name
Returns:
the field's type.

getDBState

public int getDBState(java.lang.String fieldName)
Return a field's database state. The returned value is one of the following values declared in FieldDefs: DBSTATE_VIRTUAL, DBSTATE_PERSISTENT, DBSTATE_SYSTEM, or DBSTATE_UNKNOWN (returned if the original builder of the field cannot be determined)
Overrides:
getDBState in class VirtualBuilder
Parameters:
the - requested field's name
Returns:
the field's type.

searchMultiLevelVector

public java.util.Vector searchMultiLevelVector(int snode,
                                               java.util.Vector fields,
                                               java.lang.String pdistinct,
                                               java.util.Vector tables,
                                               java.lang.String where,
                                               java.util.Vector orderVec,
                                               java.util.Vector direction)
Return all the objects that match the searchkeys.
Parameters:
snode - The number of the node to start the search with. The node has to be present in the first table listed in the tables parameter.
fields - The fieldnames to return. This should include the name of the builder. Fieldnames without a builder name are ignored. Fieldnames are accessible in the nodes returned in the same format (i.e. with manager indication) as they are specified in this parameter. Examples: 'people.lastname'
pdistinct - 'YES' indicates the records returned need to be distinct. Any other value indicates double values can be returned.
tables - The builder chain. A list containing builder names. The search is formed by following the relations between successive builders in the list. It is possible to explicitly supply a relation builder by placing the name of the builder between two builders to search. Example: company,people or typedef,authrel,people.
where - The contraint. this is in essence a SQL where clause, using the NodeManager names from the nodes as tablenames. The syntax is either sql (if preceded by "WHERE') or Examples: "WHERE people.email IS NOT NULL", "(authrel.creat=1) and (people.lastname='admin')"
orderVec - the fieldnames on which you want to sort.
direction - A list of values containing, for each field in the order parameter, a value indicating whether the sort is ascending (UP) or descending (DOWN). If less values are syupplied then there are fields in order, the first value in the list is used for the remaining fields. Default value is 'UP'.
Returns:
a Vector containing all matching nodes

searchMultiLevelVector

public java.util.Vector searchMultiLevelVector(java.util.Vector snodes,
                                               java.util.Vector fields,
                                               java.lang.String pdistinct,
                                               java.util.Vector tables,
                                               java.lang.String where,
                                               java.util.Vector orderVec,
                                               java.util.Vector direction)
Return all the objects that match the searchkeys.
Parameters:
snodes - The numbers of the nodes to start the search with. These have to be present in the first table listed in the tables parameter.
fields - The fieldnames to return. This should include the name of the builder. Fieldnames without a builder name are ignored. Fieldnames are accessible in the nodes returned in the same format (i.e. with manager indication) as they are specified in this parameter. Examples: 'people.lastname'
pdistinct - 'YES' indicates the records returned need to be distinct. Any other value indicates double values can be returned.
tables - The builder chain. A list containing builder names. The search is formed by following the relations between successive builders in the list. It is possible to explicitly supply a relation builder by placing the name of the builder between two builders to search. Example: company,people or typedef,authrel,people.
where - The contraint. this is in essence a SQL where clause, using the NodeManager names from the nodes as tablenames. The syntax is either sql (if preceded by "WHERE') or Examples: "WHERE people.email IS NOT NULL", "(authrel.creat=1) and (people.lastname='admin')"
orderVec - the fieldnames on which you want to sort.
direction - A list of values containing, for each field in the order parameter, a value indicating whether the sort is ascending (UP) or descending (DOWN). If less values are syupplied then there are fields in order, the first value in the list is used for the remaining fields. Default value is 'UP'.
Returns:
a Vector containing all matching nodes

searchMultiLevelVector

public java.util.Vector searchMultiLevelVector(java.util.Vector snodes,
                                               java.util.Vector fields,
                                               java.lang.String pdistinct,
                                               java.util.Vector tables,
                                               java.lang.String where,
                                               java.util.Vector orderVec,
                                               java.util.Vector direction,
                                               int searchdir)
Return all the objects that match the searchkeys.
Parameters:
snodes - The numbers of the nodes to start the search with. These have to be present in the first table listed in the tables parameter.
fields - The fieldnames to return. This should include the name of the builder. Fieldnames without a builder name are ignored. Fieldnames are accessible in the nodes returned in the same format (i.e. with manager indication) as they are specified in this parameter. Examples: 'people.lastname'
pdistinct - 'YES' indicates the records returned need to be distinct. Any other value indicates double values can be returned.
tables - The builder chain. A list containing builder names. The search is formed by following the relations between successive builders in the list. It is possible to explicitly supply a relation builder by placing the name of the builder between two builders to search. Example: company,people or typedef,authrel,people.
where - The contraint. this is in essence a SQL where clause, using the NodeManager names from the nodes as tablenames. The syntax is either sql (if preceded by "WHERE') or Examples: "WHERE people.email IS NOT NULL", "(authrel.creat=1) and (people.lastname='admin')"
orderVec - the fieldnames on which you want to sort.
direction - A list of values containing, for each field in the order parameter, a value indicating whether the sort is ascending (UP) or descending (DOWN). If less values are syupplied then there are fields in order, the first value in the list is used for the remaining fields. Default value is 'UP'.
Returns:
a Vector containing all matching nodes

getSelectString

protected java.lang.String getSelectString(java.util.Vector alltables,
                                           java.util.Vector rfields)
Creates a select string for the Multi level query. This consists of a list of fieldnames, preceded by a tablename.
Parameters:
alltables - the tablenames to use
rfields - the fields that were requested
Returns:
a select String

getSelectString

protected java.lang.String getSelectString(java.util.Vector alltables,
                                           java.util.Vector originaltables,
                                           java.util.Vector rfields,
                                           boolean includeAllReferences)
Creates a select string for the Multi level query. This consists of a list of fieldnames, preceded by a tablename.
Parameters:
alltables - the tablenames to use
originaltables - the original tablenames that were specified
rfields - the fields that were requested
includeAllReferences - if true, for each trable specified in originaltables, the number field will be added to the returned select string. If false, no additional fields will be added (this should change : fields should be added, but only for those tables for which fields have been requested).
Returns:
a select String

getTableString

protected java.lang.String getTableString(java.util.Vector alltables)
This method defines what is 'allowed' in tablenames. Multilevel uses this to find out what is a tablename and what not

getTableString

protected java.lang.String getTableString(java.util.Vector alltables,
                                          java.util.HashMap roles)
This method defines what is 'allowed' in tablenames. Multilevel uses this to find out what is a tablename and what not

getRelationString

protected java.lang.String getRelationString(java.util.Vector alltables)
Creates a condition string which checks the relations between nodes. The string can then be added to the query's where clause.
Parameters:
alltables - the tablenames to use
Returns:
a condition as a String

getRelationString

protected java.lang.String getRelationString(java.util.Vector alltables,
                                             int searchdir,
                                             java.util.HashMap roles)
Creates a condition string which checks the relations between nodes. The string can then be added to the query's where clause.
Parameters:
alltables - the tablenames to use
searchdir - the directionality option to use
Returns:
a condition as a String

idx2char

protected java.lang.String idx2char(int idx)
Converts an index to a one-character string. I.e. o becomes 'a', 1 becomes 'b', etc. This is used to map the tables in a List to alternate names (using their index in the list).
Parameters:
idx - the index
Returns:
the one-letter name as a String

getShortedText

public java.lang.String getShortedText(java.lang.String fieldname,
                                       int number)
Get text from a blob field. the text is cut if it is to long.
Overrides:
getShortedText in class VirtualBuilder
Parameters:
fieldname - name of the field
number - number of the object in the table
Returns:
a String containing the contents of a field as text

getShortedByte

public byte[] getShortedByte(java.lang.String fieldname,
                             int number)
Get binary data of a database blob field. the data is cut if it is to long.
Overrides:
getShortedByte in class VirtualBuilder
Parameters:
fieldname - name of the field
number - number of the object in the table
Returns:
an array of byte containing the contents of a field as text


MMBase 2002