org.mmbase.module.corebuilders
Class InsRel

java.lang.Object
  |
  +--org.mmbase.module.core.MMTable
        |
        +--org.mmbase.module.core.MMObjectBuilder
              |
              +--org.mmbase.module.corebuilders.InsRel
Direct Known Subclasses:
AnnotRel, AuthRel, DecayRel, FunctionRel, NrRel, PosRel, RoleRel

public class InsRel
extends MMObjectBuilder

InsRel, the main relation object, holds relations, and methods to handle them. An insrel defines a relation between two objects.

This class can be extended to create insrels that can also hold extra values and custom methods (named relations for example).

Version:
3 jan 2001
Author:
Daniel Ockeloen, Pierre van Rooden

Field Summary
 java.lang.String classname
           
 int relnumber
          Hold the relnumber to use when creating a node of this builder.
static boolean usesdir
           
 
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
InsRel()
          empty constructor needed for autoload
 
Method Summary
 void deleteRelationCache()
          Deletes the Relation cache.
 void deleteRelationCache(int src)
          Delete a specified relation from the relationCache
 java.util.Vector getAllRelationsVector(int src)
          Get all relation(s) for a MMObjectNode This function returns all relations in which the node is either a source or the destination (even if the direction is unidirectional).
 int getGuessedNumber(java.lang.String name)
          Search the relation definition table for the identifying number of a relation, by name.
 java.lang.String getGUIIndicator(java.lang.String field, MMObjectNode node)
          Get the display string for a given field of this node.
 java.util.Enumeration getRelated(int src, int otype)
          Get MMObjectNodes of a specified type related to a specified MMObjectNode
 java.util.Enumeration getRelated(int src, int otype, int rnumber)
          Get MMObjectNodes of a specified type related to a specified MMObjectNode
 java.util.Enumeration getRelated(int src, java.lang.String wtype)
          get MMObjectNodes related to a specified MMObjectNode
 java.util.Enumeration getRelated(int src, java.lang.String wtype, java.lang.String role)
          get MMObjectNodes related to a specified MMObjectNode
 java.util.Enumeration getRelated(java.lang.String sourceNode, java.lang.String wtype)
          get MMObjectNodes related to a specified MMObjectNode
 java.util.Enumeration getRelated(java.lang.String sourceNode, java.lang.String wtype, java.lang.String role)
          get MMObjectNodes related to a specified MMObjectNode
 java.util.Vector getRelatedVector(int src, int otype)
          Get MMObjectNodes related to a specified MMObjectNode
 java.util.Vector getRelatedVector(int src, int otype, int rnumber)
          Get MMObjectNodes related to a specified MMObjectNode
 MMObjectNode getRelation(int snumber, int dnumber, int rnumber)
          Test whether a relation exists and returns the corresponding node.
 java.util.Enumeration getRelations(int src)
          Get relation(s) for a MMObjectNode
 java.util.Enumeration getRelations(int src, int rnumber)
          Get relation(s) for a MMObjectNode, using a specified role (reldef) as a filter
 java.util.Enumeration getRelations(int src, int otype, int rnumber)
          Get relations for a specified MMObjectNode
 java.util.Vector getRelationsVector(int src)
          Get relation(s) for a MMObjectNode This function returns all relations in which the node is either a source, or where the node is the destination, but the direction is bidirectional.
 java.util.Vector getRelationsVector(int src, int rnumber)
          Get relation(s) for a MMObjectNode, using a specified role (reldef) as a filter This function returns all relations based on this role in which the node is either a source, or where the node is the destination, but the direction is bidirectional.
 boolean hasRelations(int src)
          Checks whether any relations exist for a MMObjectNode.
 boolean init()
          Initializes the builder.
 int insert(java.lang.String owner, int snumber, int dnumber, int rnumber)
          Deprecated. Use insert(String, MMObjectNode) instead.
 int insert(java.lang.String owner, MMObjectNode node)
          Insert a new Instance Relation.
 boolean reldefCorrect(int n1, int n2, int r)
          Deprecated. Use TypeRel.reldefCorrect(int, int, int) instead
 void removeNode(MMObjectNode node)
          Remove a node from the cloud.
 void setDefaults(MMObjectNode node)
          Set defaults for a node.
 
Methods inherited from class org.mmbase.module.core.MMObjectBuilder
addField, addLocalObserver, addRemoteObserver, buildSet, checkAddTmpField, commit, convertMMNode2SQL, count, create, createAlias, created, debug, deleteNodeCache, executeFunction, fieldLocalChanged, getAge, getAliasedNode, getCacheNumbers, getCacheSize, getCacheSize, getClassName, getDBByte, getDBKey, getDBState, getDBText, getDBType, getDefaultTeaser, getDefaultUrl, getDescription, getDescriptions, getDutchSName, getEditFields, getField, getFieldNames, getFields, getFullTableName, getFunctionParameters, getGUIIndicator, getHardNode, getHardNode, getHTML, getInitParameter, getInitParameters, getList, getMachineName, getMaintainer, getNewNode, getNewTmpNode, getNextField, getNode, getNode, getNode, getNode, getNodeType, getNumberFromName, getPluralName, getPluralName, getPluralNames, getRelations_main, getSearchAge, getShort, getShortedByte, getShortedText, 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, 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, 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

usesdir

public static boolean usesdir

classname

public java.lang.String classname

relnumber

public int relnumber
Hold the relnumber to use when creating a node of this builder.
Constructor Detail

InsRel

public InsRel()
empty constructor needed for autoload
Method Detail

init

public boolean init()
Initializes the builder. Determines whether the dir field is defined (and thus whether directionality is supported). If the field cannot be found, a "Warning: No dir field. Directionality support turned off." warning message is issued.
Overrides:
init in class MMObjectBuilder
Returns:
A boolean value, always success (true), as any exceptions are caught and logged.
See Also:
usesdir

insert

public int insert(java.lang.String owner,
                  int snumber,
                  int dnumber,
                  int rnumber)
Deprecated. Use insert(String, MMObjectNode) instead.

Insert a new Instance Relation.
Parameters:
owner - Administrator
snumber - Identifying number of the source object
dnumber - Identifying number of the destination object
rnumber - Identifying number of the relation defintition
Returns:
A integer value identifying the newly inserted relation

insert

public int insert(java.lang.String owner,
                  MMObjectNode node)
Insert a new Instance Relation.
Overrides:
insert in class MMObjectBuilder
Parameters:
owner - Administrator
node - Relation node to add
Returns:
A integer value identifying the newly inserted relation

removeNode

public void removeNode(MMObjectNode node)
Remove a node from the cloud.
Overrides:
removeNode in class MMObjectBuilder
Parameters:
node - The node to remove.

getRelations

public java.util.Enumeration getRelations(int src)
Get relation(s) for a MMObjectNode
Parameters:
src - Identifying number of the object to find the relations of.
Returns:
If succesful, an Enumeration listing the relations. If no relations exist, the method returns null.
See Also:
getRelationsVector(int)

getRelations

public java.util.Enumeration getRelations(int src,
                                          int rnumber)
Get relation(s) for a MMObjectNode, using a specified role (reldef) as a filter
Parameters:
src - Identifying number of the object to find the relations of.
rnumber - The number of the relation definition (role) to filter on
Returns:
If succesful, an Enumeration listing the relations. If no relations exist, the method returns null.
See Also:
getRelationsVector(int,int)

getRelations

public java.util.Enumeration getRelations(int src,
                                          int otype,
                                          int rnumber)
Get relations for a specified MMObjectNode
Parameters:
src - this is the number of the MMObjectNode requesting the relations
otype - the object type of the nodes you want to have. -1 means any node.
rnumber - Identifying number of the role (reldef)

hasRelations

public boolean hasRelations(int src)
Checks whether any relations exist for a MMObjectNode. This includes unidirection relations which would otherwise not be counted. If the query fails to execute, the system will assume that relations exists.
Parameters:
src - Identifying number of the object to find the relations of.
Returns:
true if any relations exist, false otherwise.

getAllRelationsVector

public java.util.Vector getAllRelationsVector(int src)
Get all relation(s) for a MMObjectNode This function returns all relations in which the node is either a source or the destination (even if the direction is unidirectional).
Parameters:
src - Identifying number of the object to find the relations of.
Returns:
If succesful, a Vector containing the relations. Each element in the vector's enumeration is a node object retrieved from the associated table (i.e. 'insrel'), containing the node's fields. If no relations exist (or a database exception occurs), the method returns null.

getRelationsVector

public java.util.Vector getRelationsVector(int src)
Get relation(s) for a MMObjectNode This function returns all relations in which the node is either a source, or where the node is the destination, but the direction is bidirectional.
Parameters:
src - Identifying number of the object to find the relations of.
Returns:
If succesful, a Vector containing the relations. Each element in the vector's enumeration is a node object retrieved from the associated table (i.e. 'insrel'), containing the node's fields. If no relations exist (or a database exception occurs), the method returns null.

getRelationsVector

public java.util.Vector getRelationsVector(int src,
                                           int rnumber)
Get relation(s) for a MMObjectNode, using a specified role (reldef) as a filter This function returns all relations based on this role in which the node is either a source, or where the node is the destination, but the direction is bidirectional.
Parameters:
src - Identifying number of the object to find the relations of.
rnumber - The number of the relation definition (role) to filter on
Returns:
If succesful, a Vector containing the relations. Each element in the vector's enumeration is a node object retrieved from the associated table (i.e. 'insrel'), containing the node's fields. If no relations exist (or a database exception occurs), the method returns null.

getRelation

public MMObjectNode getRelation(int snumber,
                                int dnumber,
                                int rnumber)
Test whether a relation exists and returns the corresponding node. Note that this test is strict: it determines whether a relation exists from a source to a destination with a specific role. If only a role-relation exists where source and destination are reversed, this method assumed that this is a different relation type, and it returns null.
Parameters:
snumber - Identifying number of the source object
dnumber - Identifying number of the destination object
rnumber - Identifying number of the role (reldef)
Returns:
The corresponding MMObjectNode if the exact relation exists,null otherwise

getRelated

public java.util.Enumeration getRelated(java.lang.String sourceNode,
                                        java.lang.String wtype)
get MMObjectNodes related to a specified MMObjectNode
Parameters:
sourceNode - this is the source MMObjectNode
wtype - Specifies the type of the nodes you want to have e.g. wtype="pools"

getRelated

public java.util.Enumeration getRelated(int src,
                                        java.lang.String wtype)
get MMObjectNodes related to a specified MMObjectNode
Parameters:
src - this is the number of the source MMObjectNode
wtype - Specifies the type of the nodes you want to have e.g. wtype="pools"

getRelated

public java.util.Enumeration getRelated(int src,
                                        int otype)
Get MMObjectNodes of a specified type related to a specified MMObjectNode
Parameters:
src - this is the number of the source MMObjectNode
otype - the object type of the nodes you want to have

getRelated

public java.util.Enumeration getRelated(java.lang.String sourceNode,
                                        java.lang.String wtype,
                                        java.lang.String role)
get MMObjectNodes related to a specified MMObjectNode
Parameters:
sourceNode - this is the number of the source MMObjectNode (in string format)
wtype - Specifies the type of the nodes you want to have e.g. wtype="pools"
role - the role of teh relation (name in reldef)

getRelated

public java.util.Enumeration getRelated(int src,
                                        java.lang.String wtype,
                                        java.lang.String role)
get MMObjectNodes related to a specified MMObjectNode
Parameters:
src - this is the number of the source MMObjectNode
wtype - Specifies the type of the nodes you want to have e.g. wtype="pools"
role - the role of teh relation (name in reldef)

getRelated

public java.util.Enumeration getRelated(int src,
                                        int otype,
                                        int rnumber)
Get MMObjectNodes of a specified type related to a specified MMObjectNode
Parameters:
src - this is the number of the source MMObjectNode
otype - the object type of the nodes you want to have
rnumber - Identifying number of the role (reldef)

getRelatedVector

public java.util.Vector getRelatedVector(int src,
                                         int otype)
Get MMObjectNodes related to a specified MMObjectNode
Parameters:
src - this is the number of the MMObjectNode requesting the relations
otype - the object type of the nodes you want to have. -1 means any node.

getRelatedVector

public java.util.Vector getRelatedVector(int src,
                                         int otype,
                                         int rnumber)
Get MMObjectNodes related to a specified MMObjectNode
Parameters:
src - this is the number of the MMObjectNode requesting the relations
otype - the object type of the nodes you want to have. -1 means any node.
rnumber - Identifying number of the role (reldef)

getGUIIndicator

public java.lang.String getGUIIndicator(java.lang.String field,
                                        MMObjectNode node)
Get the display string for a given field of this node. Returns for 'snumber' the name of the source object, for 'dnumber' the name of the destination object, and for 'rnumber' the name of the relation definition.
Overrides:
getGUIIndicator in class MMObjectBuilder
Parameters:
field - name of the field to describe.
node - Node containing the field data.
Returns:
A String describing the requested field's content

reldefCorrect

public boolean reldefCorrect(int n1,
                             int n2,
                             int r)
Deprecated. Use TypeRel.reldefCorrect(int, int, int) instead

Checks whether a specific relation exists. Maintains a cache containing the last checked relations Note that this routine returns false both when a snumber/dnumber are swapped, and when a typecombo does not exist - it is not possible to derive whether one or the other has occurred.
Parameters:
n1 - Number of the source node
n2 - Number of the destination node
r - Number of the relation definition
Returns:
A boolean indicating success when the relation exists, failure if it does not.

deleteRelationCache

public void deleteRelationCache()
Deletes the Relation cache. This is to be called if caching gives problems. Make sure that you can't use the deleteRelationCache(int src) instead.

deleteRelationCache

public void deleteRelationCache(int src)
Delete a specified relation from the relationCache
Parameters:
src - the number of the relation to remove from the cache

getGuessedNumber

public int getGuessedNumber(java.lang.String name)
Search the relation definition table for the identifying number of a relation, by name. Success is dependent on the uniqueness of the relation's name (not enforced, so unpredictable).
Parameters:
name - The name on which to search for the relation
Returns:
A int value indicating the relation's object number, or -1 if not found.

setDefaults

public void setDefaults(MMObjectNode node)
Set defaults for a node. Tries to determine a default for 'relnumber' by searching the RelDef table for an occurrence of the node's builder. Uses the table-mapping system, and should be replaced.
Overrides:
setDefaults in class MMObjectBuilder
Parameters:
node - The node whose defaults to set.


MMBase 2002