org.mmbase.module.core
Class ClusterBuilder

java.lang.Object
  extended byorg.mmbase.module.core.MMTable
      extended byorg.mmbase.module.core.MMObjectBuilder
          extended byorg.mmbase.module.core.VirtualBuilder
              extended byorg.mmbase.module.core.ClusterBuilder

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.58.2.2 2004/08/10 15:02:57 keesj Exp $
Author:
Rico Jansen, Pierre van Rooden, Rob van Maris
See Also:
ClusterNode

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, database, DEFAULT_ALINEA, DEFAULT_EOL, description, descriptions, fields, GUI_PARAMETERS, listCache, nodeCache, OBJ2TYPE_MAX_SIZE, oType, REPLACE_CACHE, searchAge, sortedDBLayout, TEMPNODE_DEFAULT_SIZE, TemporaryNodes, virtual
 
Fields inherited from class org.mmbase.module.core.MMTable
mmb, tableName
 
Constructor Summary
ClusterBuilder(MMBase m)
          Creates ClusterBuilder instance.
 
Method Summary
 java.lang.String getBuilderNameFromField(java.lang.String fieldName)
          Determines the builder part of a specified field.
 java.util.List getClusterNodes(SearchQuery query)
          Executes query, returns results as clusternodes or MMObjectNodes if the query is a Node-query.
 FieldDefs getField(java.lang.String fieldName)
          Return a field.
static 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.
 BasicSearchQuery getMultiLevelSearchQuery(java.util.List snodes, java.util.List fields, java.lang.String pdistinct, java.util.List tables, java.lang.String where, java.util.List sortFields, java.util.List directions, int searchdir)
          Creates search query that selects all the objects that match the searchkeys.
 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.
static int getSearchDir(java.lang.String search)
          Translates a string to a search direction constant.
static java.lang.String getSearchDirString(int search)
          Translates a search direction constant to a string.
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)
          Same as searchMultiLevelVector(snodes, fields, pdistinct, tables, where, orderVec, direction, RelationStep.DIRECTIONS_EITHER), where snodes contains just the number specified by snode.
 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)
          Same as searchMultiLevelVector(snodes, fields, pdistinct, tables, where, orderVec, direction, RelationStep.DIRECTIONS_EITHER).
 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, getDBState, getGUIInicator, init, insert, processSearchResults
 
Methods inherited from class org.mmbase.module.core.MMObjectBuilder
addField, addLocalObserver, addRemoteObserver, buildSet, checkAddTmpField, commit, convertMMNode2SQL, count, count, createAlias, delete, deleteNodeCache, drop, equals, equals, executeFunction, executeFunction, fieldLocalChanged, getAge, getAliasedNode, getAncestors, getCacheNumbers, getCacheSize, getCacheSize, getClassName, getConfigFile, getDBByte, getDBKey, getDBText, getDBType, getDefaultTeaser, getDefaultUrl, getDescendants, getDescription, getDescription, getDescriptions, getEditFields, getFieldNames, getFields, getFields, getFunctionParameters, getHardNode, getHardNode, getHTML, getInitParameter, getInitParameters, getList, getLocaleGUIIndicator, getLocaleGUIIndicator, getMachineName, getMaintainer, getMMBase, getNewTmpNode, getNextField, getNextField, getNode, getNode, getNode, getNode, getNodes, getNodes, getNodeType, getNumberFromName, getObjectType, getObjectValue, getParameterDefinition, getParentBuilder, getPluralName, getPluralName, getPluralNames, getQuery, getQuery, getQuery, getRawNodes, getRelations_main, getSearchAge, getShort, getSingularName, getSingularName, getSingularNames, getSmartPath, getSortedFields, getSortedListFields, getTmpNode, getURLEncode, getValue, getVersion, getWAP, getXMLPath, hashCode, hostname_function, insert, insertDone, isExtensionOf, isNodeCached, isVirtual, nodeLocalChanged, nodeRemoteChanged, preCommit, preEdit, process, putTmpNode, readSearchResults, removeField, removeNode, removeRelations, removeSyncNodes, removeTmpNode, replace, safeCache, safeCommit, safeInsert, search, search, search, searchIn, searchIn, searchIn, searchList, searchList, searchNumbers, searchVector, searchVector, searchVector, searchVector, searchVectorIn, searchVectorIn, searchVectorIn, searchVectorIn, searchWithWhere, sendFieldChangeSignal, setDBLayout_xml, setDefaults, setDescription, setDescriptions, setInitParameter, setMaintainer, setMMBase, setParentBuilder, setPluralNames, setSearchAge, setSingularNames, setTableName, setUniqueValue, setUniqueValue, setValue, setValue, setVersion, setXMLPath, setXMLValues, signalNewObject, testValidData, toString, toString, toXML, updateFields, waitUntilNodeChanged, wrap
 
Methods inherited from class org.mmbase.module.core.MMTable
created, getFullTableName, getTableName, size
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, 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(java.lang.String search)
Translates a string to a search direction constant.

Since:
MMBase-1.6

getSearchDirString

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

Since:
MMBase-1.6

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 MMObjectBuilder
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.

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.

Returns:
the name of the field's builder

getFieldNameFromField

public static 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

getField

public FieldDefs getField(java.lang.String fieldName)
Return a field.

Overrides:
getField in class MMObjectBuilder
Returns:
the field

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)
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(Vector,Vector,String,Vector,String,Vector,Vector,int)

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)
Same as searchMultiLevelVector(snodes, fields, pdistinct, tables, where, orderVec, direction, RelationStep.DIRECTIONS_EITHER).

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

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. 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"
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

getClusterNodes

public java.util.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)

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. The method returns null if no validf condition can be made (i.e. the result would ALWAYS be an empty resultset)

Parameters:
alltables - the tablenames to use
searchdir - the directionality option to use
Returns:
a condition as a String, or null id no valid condiiton can be made

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 XXX: So, why does this not return simply a 'char'?

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

getMultiLevelSearchQuery

public BasicSearchQuery getMultiLevelSearchQuery(java.util.List snodes,
                                                 java.util.List fields,
                                                 java.lang.String pdistinct,
                                                 java.util.List tables,
                                                 java.lang.String where,
                                                 java.util.List sortFields,
                                                 java.util.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'.
Returns:
the resulting search query.
Since:
MMBase-1.7


MMBase build 1.7.4.20050922