org.apache.cayenne.map
Class DerivedDbAttribute

java.lang.Object
  extended by org.apache.cayenne.map.Attribute
      extended by org.apache.cayenne.map.DbAttribute
          extended by org.apache.cayenne.map.DerivedDbAttribute
All Implemented Interfaces:
java.io.Serializable, CayenneMapEntry, XMLSerializable

public class DerivedDbAttribute
extends DbAttribute

A DerivedDbAttribute is a DbAttribute that resolves to an SQL expression based on a set of other attributes. DerivedDbAttribute's allow to build expressions like " count(id)", "sum(price)", etc.

Internally DerivedDbAttribute is defined as a specification string and a set of substitution DbAttribute parameters. Specification string is an SQL expression that contains placeholders (%@) for attribute parameters, for example:

sum(%@) + sum(%@)

Author:
Andrei Adamchik
See Also:
Serialized Form

Field Summary
static java.lang.String ATTRIBUTE_TOKEN
           
protected  java.lang.String expressionSpec
           
protected  boolean groupBy
           
protected  java.util.List params
           
 
Fields inherited from class org.apache.cayenne.map.DbAttribute
generated, mandatory, maxLength, precision, primaryKey, type
 
Fields inherited from class org.apache.cayenne.map.Attribute
entity, name
 
Constructor Summary
DerivedDbAttribute()
          Constructor for DerivedDbAttribute.
DerivedDbAttribute(DbEntity entity, DbAttribute parentProto)
          Creates and initializes a derived attribute with an attribute of a parent entity.
DerivedDbAttribute(java.lang.String name)
          Constructor for DerivedDbAttribute.
DerivedDbAttribute(java.lang.String name, int type, DbEntity entity, java.lang.String spec)
          Constructor for DerivedDbAttribute.
 
Method Summary
 void addParam(DbAttribute param)
          Adds parameter.
 void clearParams()
           
 void encodeAsXML(XMLEncoder encoder)
          Prints itself as XML to the provided XMLEncoder.
 java.lang.String getAliasedName(java.lang.String alias)
           
 java.lang.String getExpressionSpec()
          Returns the expressionSpec.
 java.util.List getParams()
          Returns the params.
 boolean isGroupBy()
          Returns true if this attribute is used in GROUP BY clause of the parent entity.
 void removeParam(DbAttribute param)
           
 void setExpressionSpec(java.lang.String expressionSpec)
          Sets the expressionSpec.
 void setGroupBy(boolean flag)
           
 
Methods inherited from class org.apache.cayenne.map.DbAttribute
getMaxLength, getPrecision, getType, isForeignKey, isGenerated, isMandatory, isPrimaryKey, setGenerated, setMandatory, setMaxLength, setPrecision, setPrimaryKey, setType
 
Methods inherited from class org.apache.cayenne.map.Attribute
getEntity, getName, getParent, setEntity, setName, setParent
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ATTRIBUTE_TOKEN

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

expressionSpec

protected java.lang.String expressionSpec

params

protected java.util.List params

groupBy

protected boolean groupBy
Constructor Detail

DerivedDbAttribute

public DerivedDbAttribute()
Constructor for DerivedDbAttribute.


DerivedDbAttribute

public DerivedDbAttribute(java.lang.String name)
Constructor for DerivedDbAttribute.


DerivedDbAttribute

public DerivedDbAttribute(java.lang.String name,
                          int type,
                          DbEntity entity,
                          java.lang.String spec)
Constructor for DerivedDbAttribute.


DerivedDbAttribute

public DerivedDbAttribute(DbEntity entity,
                          DbAttribute parentProto)
Creates and initializes a derived attribute with an attribute of a parent entity.

Method Detail

encodeAsXML

public void encodeAsXML(XMLEncoder encoder)
Prints itself as XML to the provided XMLEncoder.

Specified by:
encodeAsXML in interface XMLSerializable
Overrides:
encodeAsXML in class DbAttribute
Since:
1.1

getAliasedName

public java.lang.String getAliasedName(java.lang.String alias)
Overrides:
getAliasedName in class DbAttribute

isGroupBy

public boolean isGroupBy()
Returns true if this attribute is used in GROUP BY clause of the parent entity.


setGroupBy

public void setGroupBy(boolean flag)

getParams

public java.util.List getParams()
Returns the params.

Returns:
List

getExpressionSpec

public java.lang.String getExpressionSpec()
Returns the expressionSpec.


addParam

public void addParam(DbAttribute param)
Adds parameter.


removeParam

public void removeParam(DbAttribute param)

clearParams

public void clearParams()

setExpressionSpec

public void setExpressionSpec(java.lang.String expressionSpec)
Sets the expressionSpec.



Copyright © 2001-2006 Apache.org All Rights Reserved.