org.mmbase.module.core
Class ClusterBuilder

java.lang.Object
  extended byorg.mmbase.util.functions.FunctionProvider
      extended byorg.mmbase.module.core.MMTable
          extended byorg.mmbase.module.core.MMObjectBuilder
              extended byorg.mmbase.module.core.VirtualBuilder
                  extended byorg.mmbase.module.core.ClusterBuilder
All Implemented Interfaces:
EventListener, NodeEventListener, RelationEventListener

public class ClusterBuilder
extends VirtualBuilder

The builder for clusternodes.

Provides these methods to retrieve clusternodes:

Individual nodes in a 'cluster' node can be retrieved by calling the node's getNodeValue() method, using the builder name (or step alias) as argument.

Version:
$Id: ClusterBuilder.java,v 1.85 2006/01/06 16:34:16 michiel Exp $
Author:
Rico Jansen, Pierre van Rooden, Rob van Maris
See Also:
ClusterNode
To Do:
XXXX. This 'builder' is actually singleton (only one instance is created). It does therefore not support getFields, so this is more or less hacked in bridge. Perhaps in 'core' a similar approach as now in birdge must be taken, so no ClusterBuilder, but only Virtual builders, one for every query result.

Field Summary
static int SEARCH_ALL
          Deprecated. use RelationStep.DIRECTIONS_ALL
static int SEARCH_BOTH
          Deprecated. use RelationStep.DIRECTIONS_BOTH In future versions of MMBase (1.8 and up) this will be the default value
static int SEARCH_DESTINATION
          Deprecated. use RelationStep.DIRECTIONS_DESTINATION
static int SEARCH_EITHER
          Deprecated. use RelationStep.DIRECTIONS_EITHER. In future versions of MMBase (1.8 and up) the default value will be RelationStep.DIRECTIONS_BOTH
static int SEARCH_SOURCE
          Deprecated. use RelationStep.DIRECTIONS_SOURCE
 
Fields inherited from class org.mmbase.module.core.MMObjectBuilder
AGE_PARAMETERS, broadCastChanges, DEFAULT_ALINEA, DEFAULT_EOL, description, descriptions, EVENT_TYPE_LOCAL, EVENT_TYPE_REMOTE, FIELD_NUMBER, FIELD_OBJECT_TYPE, FIELD_OWNER, fields, genericBlobCache, getFunctions, GUI_PARAMETERS, guiFunction, infoFunction, internalVersion, nodeCache, oType, searchAge, SYSTEM_OWNER, TEMPNODE_DEFAULT_SIZE, temporaryNodes, TMP_FIELD_NUMBER, virtual, WRAP_PARAMETERS, wrapFunction
 
Fields inherited from class org.mmbase.module.core.MMTable
maxNodesFromQuery, mmb, storageConnector, tableName
 
Fields inherited from class org.mmbase.util.functions.FunctionProvider
functions
 
Constructor Summary
ClusterBuilder(MMBase m)
          Creates ClusterBuilder instance.
 
Method Summary
 String getBuilderNameFromField(String fieldName)
          Determines the builder part of a specified field.
 List getClusterNodes(SearchQuery query)
          Executes query, returns results as clusternodes or MMObjectNodes if the query is a Node-query.
 FieldDefs getField(String fieldName)
          Return a field.
static String getFieldNameFromField(String fieldname)
          Determines the fieldname part of a specified field (without the builder name).
 Collection getFields()
          Return a copy of the list of field definitions of this table.
 List getFields(int order)
          Gets the field definitions for the editor, sorted according to the specified order, and excluding the fields that have not been assigned a valid position (valid is >= 0).
 Map getFields(MMObjectNode node)
          Get text from a blob field from a database.
 String getGUIIndicator(MMObjectNode node)
          What should a GUI display for this node.
protected  String getGUIIndicator(MMObjectNode node, Parameters pars)
          What should a GUI display for this node/field combo.
 BasicSearchQuery getMultiLevelSearchQuery(List snodes, List fields, String pdistinct, List tables, String where, List sortFields, List directions, int searchDir)
          Deprecated. use getMultiLevelSearchQuery(List snodes, List fields, String pdistinct, List tables, String where, List orderVec, List directions, int searchDir)
 BasicSearchQuery getMultiLevelSearchQuery(List snodes, List fields, String pdistinct, List tables, String where, List sortFields, List directions, List searchDirs)
          Creates search query that selects all the objects that match the searchkeys.
 MMObjectNode getNewNode(String owner)
          Get a new node, using this builder as its parent.
static int getSearchDir(String search)
          Translates a string to a search direction constant.
static String getSearchDirString(int search)
          Translates a search direction constant to a string.
 byte[] getShortedByte(String fieldname, int number)
          Get binary data of a database blob field.
 String getShortedText(String fieldname, int number)
          Get text from a blob field.
 Vector searchMultiLevelVector(int snode, Vector fields, String pdistinct, Vector tables, String where, Vector orderVec, Vector direction)
          Same as searchMultiLevelVector(snodes, fields, pdistinct, tables, where, orderVec, direction, RelationStep.DIRECTIONS_EITHER), where snodes contains just the number specified by snode.
 Vector searchMultiLevelVector(List snodes, List fields, String pdistinct, List tables, String where, List sortFields, List directions, int searchDir)
          Deprecated. use searchMultiLevelVector(List snodes, List fields, String pdistinct, List tables, String where, List orderVec, List directions, List searchDirs)
 Vector searchMultiLevelVector(List snodes, List fields, String pdistinct, List tables, String where, List sortFields, List directions, List searchDirs)
          Return all the objects that match the searchkeys.
 Vector searchMultiLevelVector(Vector snodes, Vector fields, String pdistinct, Vector tables, String where, Vector orderVec, Vector direction)
          Same as searchMultiLevelVector(snodes, fields, pdistinct, tables, where, orderVec, direction, RelationStep.DIRECTIONS_EITHER).
 
Methods inherited from class org.mmbase.module.core.VirtualBuilder
create, getDBState, getShortedByte, getShortedText, init, insert
 
Methods inherited from class org.mmbase.module.core.MMObjectBuilder
addEventListener, addField, addLocalObserver, addRemoteObserver, broadcastChanges, checkAddTmpField, clearBlobCache, commit, createAlias, createAlias, delete, equals, equals, executeFunction, executeFunction, fieldLocalChanged, getAncestors, getBlobCache, getClassName, getConfigFile, getConfigResource, getDataTypeCollector, getDBKey, getDBType, getDefaultTeaser, getDefaultUrl, getDescendants, getDescription, getDescription, getDescriptions, getEditFields, getEmptyNode, getFieldNames, getFunction, getFunctionParameters, getFunctions, getGUIIndicator, getHardNode, getHardNode, getHTML, getInitParameter, getInitParameters, getInternalVersion, getList, getLocaleGUIIndicator, getLocaleGUIIndicator, getMachineName, getMaintainer, getNewTmpNode, getNextField, getNextField, getNode, getNode, getNode, getNodeFromCache, getNodeGUIIndicator, getNumber, getObjectType, getObjectValue, getParentBuilder, getPluralName, getPluralName, getPluralNames, getRelations_main, getSearchAge, getShort, getSingularName, getSingularName, getSingularNames, getSmartPath, getSortedFields, getSortedListFields, getTmpNode, getURLEncode, getValue, getVersion, getWAP, getXMLPath, hasField, hashCode, hashCode, hostname_function, insert, isExtensionOf, isNodeCached, isVirtual, newFunctionInstance, nodeLocalChanged, nodeRemoteChanged, notify, notify, preCommit, process, putTmpNode, removeEventListener, removeField, removeLocalObserver, removeNode, removeRelations, removeRemoteObserver, removeSyncNodes, removeTmpNode, replace, safeCache, sendFieldChangeSignal, setDefaults, setDescription, setDescriptions, setFields, setInitParameter, setMaintainer, setParentBuilder, setPluralNames, setSearchAge, setSingularNames, setUniqueValue, setUniqueValue, setValue, setValue, setVersion, setXMLPath, testValidData, toString, toString, update, updateFields, wrap
 
Methods inherited from class org.mmbase.module.core.MMTable
count, count, created, getFullTableName, getMMBase, getNode, getNodes, getNodes, getNodes, getNodeType, getStorageConnector, getTableName, search, searchVector, setMMBase, setTableName, size
 
Methods inherited from class org.mmbase.util.functions.FunctionProvider
addFunction, createParameters, getFunction, getFunctions, getFunctionValue
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

SEARCH_BOTH

public static final int SEARCH_BOTH
Deprecated. use RelationStep.DIRECTIONS_BOTH In future versions of MMBase (1.8 and up) this will be the default value

Search for all valid relations. When searching relations, return both relations from source to deastination and from destination to source, provided there is an allowed relation in that directon.

See Also:
Constant Field Values

SEARCH_DESTINATION

public static final int SEARCH_DESTINATION
Deprecated. use RelationStep.DIRECTIONS_DESTINATION

Search for destinations, When searching relations, return only relations from source to deastination.

See Also:
Constant Field Values

SEARCH_SOURCE

public static final int SEARCH_SOURCE
Deprecated. use RelationStep.DIRECTIONS_SOURCE

Seach for sources. When searching a multilevel, return only relations from destination to source, provided directionality allows

See Also:
Constant Field Values

SEARCH_ALL

public static final int SEARCH_ALL
Deprecated. use RelationStep.DIRECTIONS_ALL

Search for all relations. When searching a multilevel, return both relations from source to deastination and from destination to source. Allowed relations are not checked - ALL relations are used. This makes more inefficient queries, but it is not really wrong.

See Also:
Constant Field Values

SEARCH_EITHER

public static final int SEARCH_EITHER
Deprecated. use RelationStep.DIRECTIONS_EITHER. In future versions of MMBase (1.8 and up) the default value will be RelationStep.DIRECTIONS_BOTH

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 directions ARE somehow supported, the system only returns source to destination relations. This is the default value (for compatibility purposes).

See Also:
Constant Field Values
Constructor Detail

ClusterBuilder

public ClusterBuilder(MMBase m)
Creates ClusterBuilder instance. Must be called from the MMBase class.

Parameters:
m - the MMbase cloud creating the node
Warning: Scope will be changed to:
package
Method Detail

getSearchDir

public static int getSearchDir(String search)
Translates a string to a search direction constant.

Since:
MMBase-1.6

getSearchDirString

public static String getSearchDirString(int search)
Translates a search direction constant to a string.

Since:
MMBase-1.6

getNewNode

public MMObjectNode getNewNode(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 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

protected String getGUIIndicator(MMObjectNode node,
                                 Parameters pars)
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.

Overrides:
getGUIIndicator in class MMObjectBuilder
Parameters:
node - The node to display
pars - Parameters, see MMObjectBuilder.GUI_PARAMETERS
Returns:
the display of the node's field as a String, null if not specified

getBuilderNameFromField

public String getBuilderNameFromField(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 static String getFieldNameFromField(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

getField

public FieldDefs getField(String fieldName)
Return a field.

Overrides:
getField in class MMObjectBuilder
Parameters:
fieldName - the requested field's name
Returns:
the field

getFields

public List getFields(int order)
Description copied from class: MMObjectBuilder
Gets the field definitions for the editor, sorted according to the specified order, and excluding the fields that have not been assigned a valid position (valid is >= 0). This method makes an explicit sort (it does not use a cached list).

Overrides:
getFields in class MMObjectBuilder
Parameters:
order - One of the sortorders defined in CoreField
Returns:
The ordered list of field definitions.

getFields

public Collection getFields()
Description copied from class: MMObjectBuilder
Return a copy of the list of field definitions of this table.

Overrides:
getFields in class MMObjectBuilder
Returns:
An unmodifiable Collection with the tables fields

getFields

public Map getFields(MMObjectNode node)
Description copied from class: VirtualBuilder
Get text from a blob field from a database.

Overrides:
getFields in class VirtualBuilder
Since:
MMBase-1.8

searchMultiLevelVector

public Vector searchMultiLevelVector(int snode,
                                     Vector fields,
                                     String pdistinct,
                                     Vector tables,
                                     String where,
                                     Vector orderVec,
                                     Vector direction)
Same as searchMultiLevelVector(snodes, fields, pdistinct, tables, where, orderVec, direction, RelationStep.DIRECTIONS_EITHER), where snodes contains just the number specified by snode.

See Also:
searchMultiLevelVector(List, List, String, List, String, List, List, List)

searchMultiLevelVector

public Vector searchMultiLevelVector(Vector snodes,
                                     Vector fields,
                                     String pdistinct,
                                     Vector tables,
                                     String where,
                                     Vector orderVec,
                                     Vector direction)
Same as searchMultiLevelVector(snodes, fields, pdistinct, tables, where, orderVec, direction, RelationStep.DIRECTIONS_EITHER).

See Also:
searchMultiLevelVector(List,List,String,List,String,List,List,int)

searchMultiLevelVector

public Vector searchMultiLevelVector(List snodes,
                                     List fields,
                                     String pdistinct,
                                     List tables,
                                     String where,
                                     List sortFields,
                                     List directions,
                                     int searchDir)
Deprecated. use searchMultiLevelVector(List snodes, List fields, String pdistinct, List tables, String where, List orderVec, List directions, List searchDirs)

Return all the objects that match the searchkeys. The constraint must be in one of the formats specified by QueryConvertor#setConstraint().

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 prefix 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 constraint, must be in one of the formats specified by QueryConvertor#setConstraint(). E.g. "WHERE news.title LIKE '%MMBase%' AND news.title > 100"
sortFields - the fieldnames on which you want to sort.
directions - 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'.
searchDir - Specifies in which direction relations are to be followed, this must be one of the values defined by this class.
Returns:
a Vector containing all matching nodes

searchMultiLevelVector

public Vector searchMultiLevelVector(List snodes,
                                     List fields,
                                     String pdistinct,
                                     List tables,
                                     String where,
                                     List sortFields,
                                     List directions,
                                     List searchDirs)
Return all the objects that match the searchkeys. The constraint must be in one of the formats specified by QueryConvertor#setConstraint().

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 prefix 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 constraint, must be in one of the formats specified by QueryConvertor#setConstraint(). E.g. "WHERE news.title LIKE '%MMBase%' AND news.title > 100"
sortFields - the fieldnames on which you want to sort.
directions - 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'.
searchDirs - Specifies in which direction relations are to be followed. You can specify a direction for each relation in the path. If you specify less directions than there are relations, the last specified direction is used for the remaining relations. If you specify an empty list the default direction is BOTH.
Returns:
a Vector containing all matching nodes

getClusterNodes

public List getClusterNodes(SearchQuery query)
                     throws SearchQueryException
Executes query, returns results as clusternodes or MMObjectNodes if the query is a Node-query.

Parameters:
query - The query.
Returns:
The clusternodes.
Throws:
SearchQueryException - When an exception occurred while retrieving the results.
Since:
MMBase-1.7
See Also:
SearchQueryHandler.getNodes(org.mmbase.storage.search.SearchQuery, org.mmbase.module.core.MMObjectBuilder)

getShortedText

public String getShortedText(String fieldname,
                             int number)
Get text from a blob field. The text is cut if it is to long.

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(String fieldname,
                             int number)
Get binary data of a database blob field. The data is cut if it is to long.

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

getMultiLevelSearchQuery

public BasicSearchQuery getMultiLevelSearchQuery(List snodes,
                                                 List fields,
                                                 String pdistinct,
                                                 List tables,
                                                 String where,
                                                 List sortFields,
                                                 List directions,
                                                 int searchDir)
Deprecated. use getMultiLevelSearchQuery(List snodes, List fields, String pdistinct, List tables, String where, List orderVec, List directions, int searchDir)

Creates search query that selects all the objects that match the searchkeys. The constraint must be in one of the formats specified by QueryConvertor#setConstraint().

Parameters:
snodes - null or a list of numbers of nodes to start the search with. These have to be present in the first table listed in the tables parameter.
fields - List of fieldnames to return. These should be formatted as stepalias.field, e.g. 'people.lastname'
pdistinct - 'YES' if the records returned need to be distinct (ignoring case). 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 constraint, must be in one of the formats specified by QueryConvertor#setConstraint(). E.g. "WHERE news.title LIKE '%MMBase%' AND news.title > 100"
sortFields - null or a list of fieldnames on which you want to sort.
directions - null or a list of values containing, for each field in the sortFields parameter, a value indicating whether the sort is ascending (UP) or descending (DOWN). If less values are supplied then there are fields in order, the first value in the list is used for the remaining fields. Default value is 'UP'.
searchDir - Specifies in which direction relations are to be followed, this must be one of the values defined by this class.
Returns:
the resulting search query.
Since:
MMBase-1.7

getMultiLevelSearchQuery

public BasicSearchQuery getMultiLevelSearchQuery(List snodes,
                                                 List fields,
                                                 String pdistinct,
                                                 List tables,
                                                 String where,
                                                 List sortFields,
                                                 List directions,
                                                 List searchDirs)
Creates search query that selects all the objects that match the searchkeys. The constraint must be in one of the formats specified by QueryConvertor#setConstraint().

Parameters:
snodes - null or a list of numbers of nodes to start the search with. These have to be present in the first table listed in the tables parameter.
fields - List of fieldnames to return. These should be formatted as stepalias.field, e.g. 'people.lastname'
pdistinct - 'YES' if the records returned need to be distinct (ignoring case). 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 constraint, must be in one of the formats specified by QueryConvertor#setConstraint(). E.g. "WHERE news.title LIKE '%MMBase%' AND news.title > 100"
sortFields - null or a list of fieldnames on which you want to sort.
directions - null or a list of values containing, for each field in the sortFields parameter, a value indicating whether the sort is ascending (UP) or descending (DOWN). If less values are supplied then there are fields in order, the first value in the list is used for the remaining fields. Default value is 'UP'.
searchDirs - Specifies in which direction relations are to be followed, this must be one of the values defined by this class.
Returns:
the resulting search query.
Since:
MMBase-1.7


MMBase build 1.8.1.20060716