org.apache.ojb.broker.ant
Class PreparedModel

java.lang.Object
  extended by org.apache.ojb.broker.ant.PreparedModel

public class PreparedModel
extends Object

Provides a model derived from DescriptorRepository that is preprocessed for data handling (inserting data, generating data dtd).

Author:
Thomas Dudziak

Field Summary
private  HashMap _elementToClassDescriptors
          Maps dtd elements to lists of class descriptors (which all map to the same table)
private  HashMap _elementToColumnMap
          Maps dtd elements to colum maps which in turn map attribute names to columns
private  HashMap _elementToRequiredAttributesMap
          Maps dtd elements to maps that specify which attributes are required
private  TreeMap _elementToTable
          Maps dtd elements to tables
private  org.apache.ddlutils.model.Database _schema
          The database model.
 
Constructor Summary
PreparedModel(DescriptorRepository model, org.apache.ddlutils.model.Database schema)
           
 
Method Summary
 org.apache.commons.beanutils.DynaBean createBeanFor(String elementName)
          Creates a dyna bean for the table associated to the given element.
private  void extractAttributes(ClassDescriptor classDesc, org.apache.ddlutils.model.Table mappedTable, Map columnsMap, Map requiredColumnsMap)
           
private  void extractIndirectionTables(DescriptorRepository model, org.apache.ddlutils.model.Database schema)
          Extracts indirection tables from the given class descriptor, and adds elements for them.
 Iterator getAttributeNames(String elementName)
           
 List getClassDescriptorsMappingTo(String elementName)
           
 org.apache.ddlutils.model.Column getColumnFor(String elementName, String attrName)
           
 Map getColumnsFor(String elementName)
           
private  String getElementName(ClassDescriptor classDesc)
          Returns the element name for the class descriptor which is the adjusted short (unqualified) class name.
 Iterator getElementNames()
           
 Map getRequiredAttributes(String elementName)
           
private  String getShortAttributeName(String attrName)
          Adjusts the local attribute name (the part after the last '::' for nested fields).
 org.apache.ddlutils.model.Table getTableFor(String elementName)
           
 boolean isRequired(String elementName, String attributeName)
           
private  void prepareModel(DescriptorRepository model)
          Prepares a representation of the model that is easier accessible for our purposes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_schema

private org.apache.ddlutils.model.Database _schema
The database model.


_elementToTable

private TreeMap _elementToTable
Maps dtd elements to tables


_elementToClassDescriptors

private HashMap _elementToClassDescriptors
Maps dtd elements to lists of class descriptors (which all map to the same table)


_elementToColumnMap

private HashMap _elementToColumnMap
Maps dtd elements to colum maps which in turn map attribute names to columns


_elementToRequiredAttributesMap

private HashMap _elementToRequiredAttributesMap
Maps dtd elements to maps that specify which attributes are required

Constructor Detail

PreparedModel

public PreparedModel(DescriptorRepository model,
                     org.apache.ddlutils.model.Database schema)
Method Detail

getElementNames

public Iterator getElementNames()

getAttributeNames

public Iterator getAttributeNames(String elementName)

getRequiredAttributes

public Map getRequiredAttributes(String elementName)

isRequired

public boolean isRequired(String elementName,
                          String attributeName)

getTableFor

public org.apache.ddlutils.model.Table getTableFor(String elementName)

createBeanFor

public org.apache.commons.beanutils.DynaBean createBeanFor(String elementName)
Creates a dyna bean for the table associated to the given element.

Parameters:
elementName - The element name
Returns:
The dyna bean

getClassDescriptorsMappingTo

public List getClassDescriptorsMappingTo(String elementName)

getColumnsFor

public Map getColumnsFor(String elementName)

getColumnFor

public org.apache.ddlutils.model.Column getColumnFor(String elementName,
                                                     String attrName)

prepareModel

private void prepareModel(DescriptorRepository model)
Prepares a representation of the model that is easier accessible for our purposes.

Parameters:
model - The original model

extractAttributes

private void extractAttributes(ClassDescriptor classDesc,
                               org.apache.ddlutils.model.Table mappedTable,
                               Map columnsMap,
                               Map requiredColumnsMap)

extractIndirectionTables

private void extractIndirectionTables(DescriptorRepository model,
                                      org.apache.ddlutils.model.Database schema)
Extracts indirection tables from the given class descriptor, and adds elements for them. In contrast to normal elements, for indirection tables the element name matches the table name, and the attribute names match the column names.

Parameters:
model - The model
elements - The elements

getElementName

private String getElementName(ClassDescriptor classDesc)
Returns the element name for the class descriptor which is the adjusted short (unqualified) class name. Also takes care that the element name does not clash with another class of the same short name that maps to a different table though.

Parameters:
classDesc - The class descriptor
Returns:
The element name

getShortAttributeName

private String getShortAttributeName(String attrName)
Adjusts the local attribute name (the part after the last '::' for nested fields).

Parameters:
attrName - The original attribute name
Returns:
The local attribute name


Copyright © 2007-2011 The Kuali Foundation. All Rights Reserved.