helma.objectmodel.db
Class Relation

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

public final class Relation
extends java.lang.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
static java.lang.String AND
           
static int COLLECTION
           
static int COMPLEX_REFERENCE
           
static int INVALID
           
static java.lang.String OR
           
static int PRIMITIVE
           
static int REFERENCE
           
static java.lang.String XOR
           
 
Constructor Summary
Relation(java.lang.String propName, DbMapping ownType)
          Reads a relation entry from a line in a properties file.
 
Method Summary
protected  void addConstraint(helma.objectmodel.db.Relation.Constraint c)
          Add a constraint to the current list of constraints
protected  void appendAdditionalTables(java.lang.StringBuffer q)
           
protected  void appendFilter(java.lang.StringBuffer q, INode nonvirtual, java.lang.String prefix)
          Build the filter.
 java.lang.String buildQuery(INode home, INode nonvirtual, DbMapping otherDbm, java.lang.String kstr, java.lang.String pre, boolean useOrder)
          Build the second half of an SQL select statement according to this relation and a local object.
 java.lang.String buildQuery(INode home, INode nonvirtual, java.lang.String kstr, java.lang.String pre, boolean useOrder)
          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.
 java.lang.String getAccessName()
           
 int getColumnType()
           
 ResourceProperties getConfig()
          Get the configuration properties for this relation.
 java.lang.String getDbField()
          Return the local field name for updates.
 java.lang.String getGroup()
          Get the group for a collection relation, if defined.
 java.util.Map getKeyParts(INode home)
          Returns a map containing the key/value pairs for a specific Node
 java.lang.String getOrder()
          Get the order section to use for this relation
 DbMapping getPropertyMapping()
          Return the db mapping for a propery relation.
 java.lang.String getPropName()
          Return the name of the local property this relation is defined for
 java.lang.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  void parseOptions(java.util.Vector cnst, java.util.Properties config)
           
protected  void parsePropertyString(java.lang.String value, java.util.Vector fragments, java.util.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(java.lang.StringBuffer q, INode home, INode nonvirtual, DbMapping otherDbm, java.lang.String prefix)
          Render contraints and filter conditions to an SQL query string buffer.
 void renderConstraints(java.lang.StringBuffer q, INode home, INode nonvirtual, java.lang.String prefix)
          Render contraints and filter conditions to an SQL query string buffer.
 void renderJoinConstraints(java.lang.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
 java.lang.String toString()
           
 void unsetConstraints(Node parent, INode child)
          Unset the constraints that link two objects together.
 void update(java.lang.String desc, ResourceProperties props)
           
 boolean usesPrimaryKey()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

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 java.lang.String AND
See Also:
Constant Field Values

OR

public static final java.lang.String OR
See Also:
Constant Field Values

XOR

public static final java.lang.String XOR
See Also:
Constant Field Values
Constructor Detail

Relation

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

Method Detail

update

public void update(java.lang.String desc,
                   ResourceProperties props)

parseOptions

protected void parseOptions(java.util.Vector cnst,
                            java.util.Properties config)

getConfig

public ResourceProperties 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 java.lang.String getPrototype()
Return the prototype to be used for object reached by this relation


getPropName

public java.lang.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 java.lang.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 java.lang.String getAccessName()
Returns:
...

getSubnodeRelation

public Relation getSubnodeRelation()
Returns:
...

getDbField

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


parsePropertyString

protected void parsePropertyString(java.lang.String value,
                                   java.util.Vector fragments,
                                   java.util.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

buildQuery

public java.lang.String buildQuery(INode home,
                                   INode nonvirtual,
                                   java.lang.String kstr,
                                   java.lang.String pre,
                                   boolean useOrder)
                            throws java.sql.SQLException,
                                   java.lang.ClassNotFoundException
Build the second half of an SQL select statement according to this relation and a local object.

Throws:
java.sql.SQLException
java.lang.ClassNotFoundException

buildQuery

public java.lang.String buildQuery(INode home,
                                   INode nonvirtual,
                                   DbMapping otherDbm,
                                   java.lang.String kstr,
                                   java.lang.String pre,
                                   boolean useOrder)
                            throws java.sql.SQLException,
                                   java.lang.ClassNotFoundException
Build the second half of an SQL select statement according to this relation and a local object.

Throws:
java.sql.SQLException
java.lang.ClassNotFoundException

appendAdditionalTables

protected void appendAdditionalTables(java.lang.StringBuffer q)

appendFilter

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


renderConstraints

public void renderConstraints(java.lang.StringBuffer q,
                              INode home,
                              INode nonvirtual,
                              java.lang.String prefix)
                       throws java.sql.SQLException,
                              java.lang.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 node
prefix - the prefix to use to append to the existing query (e.g. " AND ")
Throws:
java.sql.SQLException - sql related exception
java.lang.ClassNotFoundException - driver class not found

renderConstraints

public void renderConstraints(java.lang.StringBuffer q,
                              INode home,
                              INode nonvirtual,
                              DbMapping otherDbm,
                              java.lang.String prefix)
                       throws java.sql.SQLException,
                              java.lang.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:
java.sql.SQLException - sql related exception
java.lang.ClassNotFoundException - driver class not found

renderJoinConstraints

public void renderJoinConstraints(java.lang.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 java.lang.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.


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 java.util.Map getKeyParts(INode home)
Returns a map containing the key/value pairs for a specific Node


toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object
Returns:
...


Copyright © 1998-1998-${year} Helma.org. All Rights Reserved.