Class 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.
    • Constructor Summary

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

      All Methods Instance Methods Concrete Methods 
      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​(java.lang.StringBuffer q)  
      protected void appendFilter​(java.lang.StringBuffer q, INode nonvirtual, java.lang.String prefix)
      Build the filter.
      void buildQuery​(java.lang.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​(java.lang.StringBuffer q, Node home, DbMapping otherDbm, java.lang.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.
      java.lang.String getAccessName()  
      Relation getClone()
      Get a copy of this relation.
      int getColumnType()  
      java.util.Map getConfig()
      Get the configuration properties for this relation.
      java.lang.StringBuffer getCountSelect()  
      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.lang.StringBuffer getIdSelect()  
      java.util.Map getKeyParts​(INode home)
      Returns a map containing the key/value pairs for a specific Node
      java.lang.StringBuffer getNamesSelect()  
      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 boolean parseDescriptor​(java.lang.Object value, java.util.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​(java.util.Vector cnst, java.util.Properties props)  
      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, Node home, Node nonvirtual, DbMapping otherDbm, java.lang.String prefix)
      Render contraints and filter conditions to an SQL query string buffer.
      void renderConstraints​(java.lang.StringBuffer q, Node home, 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.Object desc, java.util.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
    • Constructor Detail

      • 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​(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.Object desc,
                           java.util.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​(java.lang.Object value,
                                          java.util.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​(java.util.Vector cnst,
                                    java.util.Properties props)
      • getConfig

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

        public java.lang.StringBuffer getIdSelect()
      • getCountSelect

        public java.lang.StringBuffer getCountSelect()
      • getNamesSelect

        public java.lang.StringBuffer getNamesSelect()
      • buildQuery

        public void buildQuery​(java.lang.StringBuffer q,
                               Node home,
                               boolean useOrder,
                               boolean isCount)
                        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 void buildQuery​(java.lang.StringBuffer q,
                               Node home,
                               DbMapping otherDbm,
                               java.lang.String kstr,
                               boolean useOrder,
                               boolean isCount)
                        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,
                                      Node home,
                                      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
        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,
                                      Node home,
                                      Node 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.
      • 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 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:
        ...