Package helma.objectmodel.db

# Class Relation

java.lang.Object
helma.objectmodel.db.Relation

public final class Relation extends Object
This describes how a property of a persistent Object is stored in a relational database table. This can be either a scalar property (string, date, number etc.) or a reference to one or more other objects.

## Field Summary

Fields
Modifier and Type
Field
Description
`static final String`
`AND`
`static final int`
`COLLECTION`
`static final int`
`COMPLEX_REFERENCE`
`static final int`
`INVALID`
`static final String`
`OR`
`static final int`
`PRIMITIVE`
`static final int`
`REFERENCE`
`static final String`
`XOR`

## Constructor Summary

Constructors
Modifier
Constructor
Description
`protected`
`Relation(Relation rel)`
This constructor makes a copy of an existing relation.
``
`Relation(String propName, DbMapping ownType)`
Reads a relation entry from a line in a properties file.

## Method Summary

Modifier and Type
Method
Description
`protected void`
`addConstraint(helma.objectmodel.db.Relation.Constraint c)`
Add a constraint to the current list of constraints
`protected void`
`appendAdditionalTables(StringBuffer q)`
`protected void`
`appendFilter(StringBuffer q, INode nonvirtual, String prefix)`
Build the filter.
`void`
`buildQuery(StringBuffer q, Node home, boolean useOrder, boolean isCount)`
Build the second half of an SQL select statement according to this relation and a local object.
`void`
`buildQuery(StringBuffer q, Node home, DbMapping otherDbm, String kstr, boolean useOrder, boolean isCount)`
Build the second half of an SQL select statement according to this relation and a local object.
`boolean`
`checkConstraints(Node parent, Node child)`
Check if the child node fullfills the constraints defined by this relation.
`int`
`countConstraints()`
Returns the number of constraints for this relation.
`boolean`
`createOnDemand()`
Returns true if the object represented by this Relation has to be created on demand at runtime by the NodeManager.
`String`
`getAccessName()`
`Relation`
`getClone()`
Get a copy of this relation.
`int`
`getColumnType()`
`Map`
`getConfig()`
Get the configuration properties for this relation.
`StringBuffer`
`getCountSelect()`
`String`
`getDbField()`
Return the local field name for updates.
`String`
`getGroup()`
Get the group for a collection relation, if defined.
`StringBuffer`
`getIdSelect()`
`Map`
`getKeyParts(INode home)`
Returns a map containing the key/value pairs for a specific Node
`StringBuffer`
`getNamesSelect()`
`String`
`getOrder()`
Get the order section to use for this relation
`DbMapping`
`getPropertyMapping()`
Return the db mapping for a propery relation.
`String`
`getPropName()`
Return the name of the local property this relation is defined for
`String`
`getPrototype()`
Return the prototype to be used for object reached by this relation
`int`
`getRefType()`
Get the reference type of this relation.
`Relation`
`getSubnodeRelation()`
`DbMapping`
`getTargetType()`
Return the target type of this relation, or null if this is a primitive mapping.
`DbMapping`
`getVirtualMapping()`
get a DbMapping to use for virtual aka collection nodes.
`boolean`
`hasAccessName()`
`boolean`
`isCollection()`
Returns true if this Relation describes a collection.
`boolean`
`isComplexReference()`
Returns true if this Relation describes a complex object reference property
`boolean`
`isPrimitive()`
Tell if this relation represents a primitive (scalar) value mapping.
`boolean`
`isPrimitiveOrReference()`
Returns true if this Relation describes either a primitive value or an object reference.
`boolean`
`isPrivate()`
Tell wether the property described by this relation is to be handled as private, i.e.
`boolean`
`isReadonly()`
Tell wether the property described by this relation is to be handled as readonly/write protected.
`boolean`
`isReference()`
Returns true if this Relation describes an object reference property
`boolean`
`isVirtual()`
Does this relation describe a virtual (collection) node?
`boolean`
`loadAggressively()`
Check whether aggressive loading is set for this relation
`boolean`
`needsPersistence()`
Returns true if the object represented by this Relation has to be persisted in the internal db in order to be functional.
`protected boolean`
`parseDescriptor(Object value, Map config)`
Converts old style foo = collection(Bar) mapping to new style foo.collection = Bar mappinng and returns true if a non-primitive mapping was encountered.
`protected void`
`parseOptions(Vector cnst, Properties props)`
`protected void`
`parsePropertyString(String value, Vector fragments, Vector propertyRefs)`
This is taken from org.apache.tools.ant ProjectHelper.java distributed under the Apache Software License, Version 1.1 Parses a string containing `${xxx}` style property references into two lists.
`void`
`renderConstraints(StringBuffer q, Node home, Node nonvirtual, DbMapping otherDbm, String prefix)`
Render contraints and filter conditions to an SQL query string buffer.
`void`
`renderConstraints(StringBuffer q, Node home, String prefix)`
Render contraints and filter conditions to an SQL query string buffer.
`void`
`renderJoinConstraints(StringBuffer select, boolean isOracle)`
Render the constraints for this relation for use within a left outer join select statement for the base object.
`void`
`setColumnType(int ct)`
`void`
`setConstraints(Node parent, Node child)`
Make sure that the child node fullfills the constraints defined by this relation by setting the appropriate properties
`String`
`toString()`
`void`
`unsetConstraints(Node parent, INode child)`
Unset the constraints that link two objects together.
`void`
`update(Object desc, Properties props)`
Update this relation object from a properties object.
`boolean`
`usesPrimaryKey()`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

## Field Details

### INVALID

public static final int INVALID

See Also:
  - Constant Field Values

### PRIMITIVE

public static final int PRIMITIVE

See Also:
  - Constant Field Values

### REFERENCE

public static final int REFERENCE

See Also:
  - Constant Field Values

### COLLECTION

public static final int COLLECTION

See Also:
  - Constant Field Values

### COMPLEX_REFERENCE

public static final int COMPLEX_REFERENCE

See Also:
  - Constant Field Values

### AND

public static final String AND

See Also:
  - Constant Field Values

### OR

public static final String OR

See Also:
  - Constant Field Values

### XOR

public static final String XOR

See Also:
  - Constant Field Values

## Constructor Details

### Relation

protected Relation(Relation rel)
This constructor makes a copy of an existing relation. Not all fields are copied, just those which are needed in groupby- and virtual nodes defined by this relation. use `getClone()` to get a full copy of this relation.

### Relation

public Relation(String propName, DbMapping ownType)
Reads a relation entry from a line in a properties file.

## Method Details

### update

public void update(Object desc, Properties props)
Update this relation object from a properties object.

Parameters:
  `desc` - the top level relation descriptor. For relations defined in a type.properties file, this is a string like "collection(Type)", but for relations defined from JavaScript, it is the top level descriptor object.
  `props` - The subproperties for this relation.

### parseDescriptor

protected boolean parseDescriptor(Object value, Map config)
Converts old style foo = collection(Bar) mapping to new style foo.collection = Bar mappinng and returns true if a non-primitive mapping was encountered.

Parameters:
  `value` - the value of the top level property mapping
  `config` - the sub-map for this property mapping
Returns:
  true if the value describes a valid, non-primitive property mapping

### parseOptions

protected void parseOptions(Vector cnst, Properties props)

### getConfig

public Map getConfig()
Get the configuration properties for this relation.

### isVirtual

public boolean isVirtual()
Does this relation describe a virtual (collection) node?

### getTargetType

public DbMapping getTargetType()
Return the target type of this relation, or null if this is a primitive mapping.

### getRefType

public int getRefType()
Get the reference type of this relation.

### isPrimitive

public boolean isPrimitive()
Tell if this relation represents a primitive (scalar) value mapping.

### isReference

public boolean isReference()
Returns true if this Relation describes an object reference property

### isPrimitiveOrReference

public boolean isPrimitiveOrReference()
Returns true if this Relation describes either a primitive value or an object reference.

### isCollection

public boolean isCollection()
Returns true if this Relation describes a collection. NOTE: this will return true both for collection objects (aka virtual nodes) and direct child object relations, so isVirtual() should be used to identify relations that define collection properties!

### isComplexReference

public boolean isComplexReference()
Returns true if this Relation describes a complex object reference property

### isPrivate

public boolean isPrivate()
Tell wether the property described by this relation is to be handled as private, i.e. a change on it should not result in any changed object/collection relations.

### loadAggressively

public boolean loadAggressively()
Check whether aggressive loading is set for this relation

### countConstraints

public int countConstraints()
Returns the number of constraints for this relation.

### createOnDemand

public boolean createOnDemand()
Returns true if the object represented by this Relation has to be created on demand at runtime by the NodeManager. This is true for: - collection (aka virtual) nodes - nodes accessed via accessname - group nodes - complex reference nodes

### needsPersistence

public boolean needsPersistence()
Returns true if the object represented by this Relation has to be persisted in the internal db in order to be functional. This is true if the subnodes contained in this collection are stored in the embedded database. In this case, the collection itself must also be an ordinary object stored in the db, since a virtual collection would lose its its content after restarts.

### getPrototype

public String getPrototype()
Return the prototype to be used for object reached by this relation

### getPropName

public String getPropName()
Return the name of the local property this relation is defined for

### setColumnType

public void setColumnType(int ct)

Parameters:
  `ct` - ...

### getColumnType

public int getColumnType()

Returns:
  ...

### getGroup

public String getGroup()
Get the group for a collection relation, if defined.

Returns:
  the name of the column used to group child objects, if any.

### addConstraint

protected void addConstraint(helma.objectmodel.db.Relation.Constraint c)
Add a constraint to the current list of constraints

### usesPrimaryKey

public boolean usesPrimaryKey()

Returns:
  true if the foreign key used for this relation is the other object's primary key.

### hasAccessName

public boolean hasAccessName()

Returns:
  ...

### getAccessName

public String getAccessName()

Returns:
  ...

### getSubnodeRelation

public Relation getSubnodeRelation()

Returns:
  ...

### getDbField

public String getDbField()
Return the local field name for updates.

### parsePropertyString

protected void parsePropertyString(String value, Vector fragments, Vector propertyRefs)
This is taken from org.apache.tools.ant ProjectHelper.java distributed under the Apache Software License, Version 1.1 Parses a string containing `${xxx}` style property references into two lists. The first list is a collection of text fragments, while the other is a set of string property names. `null` entries in the first list indicate a property reference from the second list.

Parameters:
  `value` - Text to parse. Must not be `null`.
  `fragments` - List to add text fragments to. Must not be `null`.
  `propertyRefs` - List to add property names to. Must not be `null`.

### getVirtualMapping

public DbMapping getVirtualMapping()
get a DbMapping to use for virtual aka collection nodes.

### getPropertyMapping

public DbMapping getPropertyMapping()
Return the db mapping for a propery relation.

Returns:
  the target mapping of this property relation

### getIdSelect

public StringBuffer getIdSelect()

### getCountSelect

public StringBuffer getCountSelect()

### getNamesSelect

public StringBuffer getNamesSelect()

### buildQuery

public void buildQuery(StringBuffer q, Node home, boolean useOrder, boolean isCount) throws SQLException, ClassNotFoundException
Build the second half of an SQL select statement according to this relation and a local object.

Throws:
  `SQLException`
  `ClassNotFoundException`

### buildQuery

public void buildQuery(StringBuffer q, Node home, DbMapping otherDbm, String kstr, boolean useOrder, boolean isCount) throws SQLException, ClassNotFoundException
Build the second half of an SQL select statement according to this relation and a local object.

Throws:
  `SQLException`
  `ClassNotFoundException`

### appendAdditionalTables

protected void appendAdditionalTables(StringBuffer q)

### appendFilter

protected void appendFilter(StringBuffer q, INode nonvirtual, String prefix)
Build the filter.

### renderConstraints

public void renderConstraints(StringBuffer q, Node home, String prefix) throws SQLException, ClassNotFoundException
Render contraints and filter conditions to an SQL query string buffer.

Parameters:
  `q` - the query string
  `home` - our home node
  `prefix` - the prefix to use to append to the existing query (e.g. " AND ")
Throws:
  `SQLException` - sql related exception
  `ClassNotFoundException` - driver class not found

### renderConstraints

public void renderConstraints(StringBuffer q, Node home, Node nonvirtual, DbMapping otherDbm, String prefix) throws SQLException, ClassNotFoundException
Render contraints and filter conditions to an SQL query string buffer.

Parameters:
  `q` - the query string
  `home` - our home node
  `nonvirtual` - our non-virtual home nod
  `otherDbm` - the DbMapping of the remote Node
  `prefix` - the prefix to use to append to the existing query (e.g. " AND ")
Throws:
  `SQLException` - sql related exception
  `ClassNotFoundException` - driver class not found

### renderJoinConstraints

public void renderJoinConstraints(StringBuffer select, boolean isOracle)
Render the constraints for this relation for use within a left outer join select statement for the base object.

Parameters:
  `select` - the string buffer to write to
  `isOracle` - create Oracle pre-9 style left outer join

### getOrder

public String getOrder()
Get the order section to use for this relation

### isReadonly

public boolean isReadonly()
Tell wether the property described by this relation is to be handled as readonly/write protected.

### getClone

public Relation getClone()
Get a copy of this relation.

Returns:
  a clone of this relation

### checkConstraints

public boolean checkConstraints(Node parent, Node child)
Check if the child node fullfills the constraints defined by this relation. FIXME: This always returns false if the relation has a filter value set, since we can't determine if the filter constraints are met without querying the database.

Parameters:
  `parent` - the parent object - may be a virtual or group node
  `child` - the child object
Returns:
  true if all constraints are met

### setConstraints

public void setConstraints(Node parent, Node child)
Make sure that the child node fullfills the constraints defined by this relation by setting the appropriate properties

### unsetConstraints

public void unsetConstraints(Node parent, INode child)
Unset the constraints that link two objects together.

### getKeyParts

public Map getKeyParts(INode home)
Returns a map containing the key/value pairs for a specific Node

### toString

public String toString()

Overrides:
  `toString` in class `Object`
Returns:
  ...