org.xorm
Class ClassMapping

java.lang.Object
  |
  +--org.xorm.ClassMapping
All Implemented Interfaces:
Cloneable, I15d

public class ClassMapping
extends Object
implements I15d, Cloneable

A ClassMapping provides the mapping from a Java type (class or interface) to a datastore type. Each field of a Class can map to a Column in a Table, or may be mapped as a RelationshipMapping. A ClassMapping is also the repository for default fetch group information.


Field Summary
 
Fields inherited from interface org.xorm.I15d
I18N
 
Constructor Summary
ClassMapping(ModelMapping modelMapping, Class clazz)
          Creates a new ClassMapping that maps the given Class.
ClassMapping(ModelMapping modelMapping, Class clazz, JDOClass jdoClass)
           
 
Method Summary
 Object clone()
          Creates a shallow clone.
 Column getColumn(String field)
          Get the Column mapped to the given field.
 Column getColumnForMethod(Method method)
          Convenience method that gets the Column mapped to a particular get or set method.
 Class getDatastoreIdentityType()
          Returns the Class specified as the identity-type for a class mapping, or null if none was specified.
 DataFetchGroup getDefaultFetchGroup()
           
 FieldDescriptor getFieldDescriptor(String field)
          Retrieves the FieldDescriptor associated with the given field name by iterating through the collection of all FieldDescriptors for this class.
 Collection getFieldDescriptors()
          Gets the field descriptors found by introspection on the class or interface.
 String getFieldForMethod(Method method)
          Retrieves the field associated with a get or set method.
 Class getFieldType(String field)
          Returns the Java type of the field.
 String getInverse(String field)
           
 Set getManagedFields()
          Returns the set of managed field names.
 Class getMappedClass()
          Get the class that this mapping references.
 Set getMappedFieldDescriptors()
          Gets the set of FieldDescriptors that have column mappings defined in the JDO metadata file.
 RelationshipMapping getRelationship(String field)
          Get the relationship mapped to a field.
 RelationshipMapping getRelationshipForMethod(Method method)
          Convenience method to go from a get/set method to the associated relationship mapping.
 Map getRelationships()
          Get the map of relationships.
 Table getTable()
          Get the table the class is mapped to.
static boolean isUserType(Class clazz)
          Returns true if the class parameter is not a primitive type, a wrapper class for a primitive type, or java.util.Date, java.lang.String, java.util.Locale, java.math.BigDecimal, or java.math.BigInteger.
 void setColumn(String field, Column column, Boolean inDefaultFetchGroup)
          Set the Column mapped to the given field.
 void setDatastoreIdentityType(Class datastoreIdentityType)
           
 void setInverse(String localField, String inverseField)
           
 void setRelationship(String field, RelationshipMapping relation)
          Define a to-many relationship on a field.
 void setTable(Table table)
          Defines the table that will be used to map the class.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ClassMapping

public ClassMapping(ModelMapping modelMapping,
                    Class clazz)
Creates a new ClassMapping that maps the given Class. The class will be introspected and assigned relationships for all properties that are of a user-defined (non-collection) type.


ClassMapping

public ClassMapping(ModelMapping modelMapping,
                    Class clazz,
                    JDOClass jdoClass)
See Also:
ClassMapping(ModelMapping, Class)
Method Detail

clone

public Object clone()
Creates a shallow clone.

Overrides:
clone in class Object

isUserType

public static boolean isUserType(Class clazz)
Returns true if the class parameter is not a primitive type, a wrapper class for a primitive type, or java.util.Date, java.lang.String, java.util.Locale, java.math.BigDecimal, or java.math.BigInteger.


setTable

public void setTable(Table table)
Defines the table that will be used to map the class. If table is null, defaults will be applied to create a mapping for the table. This will include a datastore identity column called "xorm_pk"; other column names will be the same as the field name.


getRelationships

public Map getRelationships()
Get the map of relationships. The keys are Strings and the values are RelationshipMapping objects. A relationship is defined as a -to-one or -to-many relationship to another first class user object.


getDefaultFetchGroup

public DataFetchGroup getDefaultFetchGroup()

getMappedFieldDescriptors

public Set getMappedFieldDescriptors()
Gets the set of FieldDescriptors that have column mappings defined in the JDO metadata file.


getFieldDescriptors

public Collection getFieldDescriptors()
Gets the field descriptors found by introspection on the class or interface. This includes primitive types, user types, and collection references. The returned items are instances of org.xorm.FieldDescriptor. Not all fields found by introspection are required to be mapped.


getManagedFields

public Set getManagedFields()
Returns the set of managed field names. This set is the union of fields that are mapped and fields that are defined as relationships.


getInverse

public String getInverse(String field)

setInverse

public void setInverse(String localField,
                       String inverseField)

getFieldForMethod

public String getFieldForMethod(Method method)
Retrieves the field associated with a get or set method. Returns null if there is no mapping.


getColumnForMethod

public Column getColumnForMethod(Method method)
Convenience method that gets the Column mapped to a particular get or set method. Returns null for unmapped methods.


getTable

public Table getTable()
Get the table the class is mapped to.


getMappedClass

public Class getMappedClass()
Get the class that this mapping references.


getColumn

public Column getColumn(String field)
Get the Column mapped to the given field.


setColumn

public void setColumn(String field,
                      Column column,
                      Boolean inDefaultFetchGroup)
Set the Column mapped to the given field.

Throws:
JDOUserException - if the field does not exist, or if the field has a set() method but the column is marked as read-only.

setRelationship

public void setRelationship(String field,
                            RelationshipMapping relation)
Define a to-many relationship on a field.

Throws:
JDOUserException - if the field does not exist

getFieldDescriptor

public FieldDescriptor getFieldDescriptor(String field)
Retrieves the FieldDescriptor associated with the given field name by iterating through the collection of all FieldDescriptors for this class.

Throws:
JDOUserException - if the named field does not exist.

getRelationship

public RelationshipMapping getRelationship(String field)
Get the relationship mapped to a field. If no relationship exists, returns null.


getRelationshipForMethod

public RelationshipMapping getRelationshipForMethod(Method method)
Convenience method to go from a get/set method to the associated relationship mapping.


getFieldType

public Class getFieldType(String field)
Returns the Java type of the field.


getDatastoreIdentityType

public Class getDatastoreIdentityType()
Returns the Class specified as the identity-type for a class mapping, or null if none was specified.


setDatastoreIdentityType

public void setDatastoreIdentityType(Class datastoreIdentityType)


$Header: /cvsroot/xorm/xorm/docs/api/org/xorm/ClassMapping.html,v 1.9 2004/05/30 08:55:03 wbiggs Exp $