com.jenkov.mrpersister.impl.mapping
Class ObjectMapping

java.lang.Object
  extended by com.jenkov.mrpersister.impl.mapping.ObjectMapping
All Implemented Interfaces:
IObjectMapping

public class ObjectMapping
extends java.lang.Object
implements IObjectMapping


Field Summary
protected  java.util.Map getterMappingMap
           
protected  java.util.Collection getterMappingSet
           
protected  java.lang.Class objectType
           
protected  IKey primaryKey
           
protected  java.lang.String primaryKeyColumnName
           
protected  java.util.Map setterMappingMap
           
protected  java.util.Collection setterMappingSet
           
protected  java.lang.String tableName
           
 
Constructor Summary
ObjectMapping()
           
 
Method Summary
 void addGetterMapping(IGetterMapping mapping)
          Adds a getter method method to this object method.
 void addSetterMapping(ISetterMapping mapping)
          Adds a getter method method to this object method.
protected  void appendMethodMappings(java.lang.StringBuffer buffer, java.util.Collection mappings, java.lang.String direction, int length)
           
 boolean equals(java.lang.Object o)
           
 IGetterMapping getGetterMapping(java.lang.reflect.Method objectMethod)
          Returns the getter method method that is mapped to the object method passed as parameter objectMethod.
 IGetterMapping getGetterMapping(java.lang.String columnName)
          Returns the getter method method that is mapped to the database column name passed in parameter columnName.
 java.util.Collection getGetterMappings()
          Returns the method mappings that are mapped to getter methods on the mapped object class.
 java.lang.Class getObjectClass()
          Returns the class that this object method maps.
 IKey getPrimaryKey()
          Returns the current primary key mapping.
 java.lang.String getPrimaryKeyColumnName()
          Returns the database column name of the primary key for the table that this object method maps to, if any.
 IGetterMapping getPrimaryKeyGetterMapping()
          Returns the method method (if any) that maps to the primary key of the table mapped to.
 ISetterMapping getPrimaryKeySetterMapping()
          Returns the method method (if any) that maps to the primary key of the table mapped to.
 IKeyValue getPrimaryKeyValueForObject(java.lang.Object object, IKeyValue keyValue)
          Returns an IKeyValue instance matching the primary key of this object mapping, and with the key values extracted from the given object.
 IKeyValue getPrimaryKeyValueForRecord(java.sql.ResultSet result, IKeyValue keyValue)
          Returns the primary key value as an IKeyValue instance for the record the ResultSet is pointing to.
 ISetterMapping getSetterMapping(java.lang.reflect.Method objectMethod)
          Returns the setter method method that is mapped to the object method passed as parameter objectMethod.
 ISetterMapping getSetterMapping(java.lang.String columnName)
          Returns the setter method method that is mapped to the database column name passed in parameter columnName.
 java.util.Collection getSetterMappings()
          Returns the method mappings that are mapped to setter methods on the mapped object class.
 java.lang.String getTableName()
          Returns the name of the database table that this object method maps to.
 boolean hasAutoGeneratedKeys()
          Returns true if this object mapping maps to auto generated keys.
 int hashCode()
           
 void removeGetterFieldMapping(IGetterMapping getterMapping)
           
 void removeGetterMapping(java.lang.reflect.Method method)
          Removes the getter method method that maps from the given Method to some database column.
 void removeGetterMapping(java.lang.String columnName)
          Removes the getter method method that maps to the provided database column name (column in table).
 void removeSetterFieldMapping(ISetterMapping setterMapping)
           
 void removeSetterMapping(java.lang.reflect.Method method)
          Removes the setter method method that maps from the given Method to some database column.
 void removeSetterMapping(java.lang.String columnName)
          Removes the setter method method that maps to the given database column name (column in table).
 void setObjectClass(java.lang.Class objectType)
          Sets the class that this object method maps.
 void setPrimaryKey(IKey primaryKey)
          Sets the current primary key mapping.
 void setPrimaryKeyColumnName(java.lang.String primaryKeyColumnName)
          Sets the database column name of the primary key for the table that this object method maps to, if any.
 void setTableName(java.lang.String tableName)
          Sets the name of the database table that this object method maps to.
 java.lang.String toString()
           
protected  void validateMethodMapping(IMethodMapping mapping)
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

tableName

protected java.lang.String tableName

primaryKeyColumnName

protected java.lang.String primaryKeyColumnName

objectType

protected java.lang.Class objectType

getterMappingSet

protected java.util.Collection getterMappingSet

setterMappingSet

protected java.util.Collection setterMappingSet

getterMappingMap

protected java.util.Map getterMappingMap

setterMappingMap

protected java.util.Map setterMappingMap

primaryKey

protected IKey primaryKey
Constructor Detail

ObjectMapping

public ObjectMapping()
Method Detail

getTableName

public java.lang.String getTableName()
Description copied from interface: IObjectMapping
Returns the name of the database table that this object method maps to.

Specified by:
getTableName in interface IObjectMapping
Returns:
The database table name mapped to.

setTableName

public void setTableName(java.lang.String tableName)
Description copied from interface: IObjectMapping
Sets the name of the database table that this object method maps to.

Specified by:
setTableName in interface IObjectMapping
Parameters:
tableName - The database table name to map to.

hasAutoGeneratedKeys

public boolean hasAutoGeneratedKeys()
Description copied from interface: IObjectMapping
Returns true if this object mapping maps to auto generated keys. Note: It only returns true if a column of the primary key is auto generated. Non-key columns are not taken into account.

Specified by:
hasAutoGeneratedKeys in interface IObjectMapping
Returns:
True if any column of the primary key is auto generated. False if not.

getPrimaryKey

public IKey getPrimaryKey()
Description copied from interface: IObjectMapping
Returns the current primary key mapping. This IKey instance replaces the previous primary key methods getPrimaryKeyColumn(), setPrimaryKeyColumn(...), getPrimaryKeyGetterMapping() and getPrimaryKeySetterMapping() . This new key mapping object supports compound keys, which the previous methods did not.

Specified by:
getPrimaryKey in interface IObjectMapping
Returns:
The current primary key mapping.

setPrimaryKey

public void setPrimaryKey(IKey primaryKey)
Description copied from interface: IObjectMapping
Sets the current primary key mapping. This IKey instance replaces the previous primary key methods getPrimaryKeyColumn(), setPrimaryKeyColumn(...), getPrimaryKeyGetterMapping() and getPrimaryKeySetterMapping() . This new key mapping object supports compound keys, which the previous methods did not.

Specified by:
setPrimaryKey in interface IObjectMapping
Parameters:
primaryKey - The key mapping to use as the primary key mapping.

getPrimaryKeyColumnName

public java.lang.String getPrimaryKeyColumnName()
Description copied from interface: IObjectMapping
Returns the database column name of the primary key for the table that this object method maps to, if any. If this object method doesn't map directly to a table but to some query instead, there may be no primary key for the object method. In that case, null is returned.

Specified by:
getPrimaryKeyColumnName in interface IObjectMapping
Returns:
The name of the primary key column for this object method. Null if no primary key is set.

setPrimaryKeyColumnName

public void setPrimaryKeyColumnName(java.lang.String primaryKeyColumnName)
Description copied from interface: IObjectMapping
Sets the database column name of the primary key for the table that this object method maps to, if any. If this object method doesn't map directly to a table but to some query instead, there may be no primary key for the object method. In that case, set it to null (or don't set it at all. Defaults to null).

Specified by:
setPrimaryKeyColumnName in interface IObjectMapping
Parameters:
primaryKeyColumnName - The name of the primary key column in the table that this object method maps to.

getObjectClass

public java.lang.Class getObjectClass()
Description copied from interface: IObjectMapping
Returns the class that this object method maps.

Specified by:
getObjectClass in interface IObjectMapping
Returns:
The class mapped by this object method.

setObjectClass

public void setObjectClass(java.lang.Class objectType)
Description copied from interface: IObjectMapping
Sets the class that this object method maps.

Specified by:
setObjectClass in interface IObjectMapping
Parameters:
objectType - The class mapped by this object method.

getPrimaryKeyValueForObject

public IKeyValue getPrimaryKeyValueForObject(java.lang.Object object,
                                             IKeyValue keyValue)
                                      throws PersistenceException
Description copied from interface: IObjectMapping
Returns an IKeyValue instance matching the primary key of this object mapping, and with the key values extracted from the given object. The object must be of the same class as the class this object mapping maps to (the class returned from getObjectClass()).

Specified by:
getPrimaryKeyValueForObject in interface IObjectMapping
Parameters:
object - The object containing the primary key values to extract into the IKeyValue instance.
Returns:
An IKeyValue matching the IKey primary key of this object mapping, with the values extracted from this object.
Throws:
PersistenceException

getPrimaryKeyValueForRecord

public IKeyValue getPrimaryKeyValueForRecord(java.sql.ResultSet result,
                                             IKeyValue keyValue)
                                      throws PersistenceException
Description copied from interface: IObjectMapping
Returns the primary key value as an IKeyValue instance for the record the ResultSet is pointing to.

Specified by:
getPrimaryKeyValueForRecord in interface IObjectMapping
Returns:
Throws:
PersistenceException

addGetterMapping

public void addGetterMapping(IGetterMapping mapping)
                      throws PersistenceException
Description copied from interface: IObjectMapping
Adds a getter method method to this object method.

Specified by:
addGetterMapping in interface IObjectMapping
Parameters:
mapping - The method method to add.
Throws:
PersistenceException - If the given method method is not valid (is not null, and does at least contain object method and column name);

addSetterMapping

public void addSetterMapping(ISetterMapping mapping)
                      throws PersistenceException
Description copied from interface: IObjectMapping
Adds a getter method method to this object method.

Specified by:
addSetterMapping in interface IObjectMapping
Parameters:
mapping - The method method to add.
Throws:
PersistenceException - If the given method method is not valid (is not null, and does at least contain object method and column name);

validateMethodMapping

protected void validateMethodMapping(IMethodMapping mapping)
                              throws PersistenceException
Throws:
PersistenceException

removeGetterMapping

public void removeGetterMapping(java.lang.String columnName)
Description copied from interface: IObjectMapping
Removes the getter method method that maps to the provided database column name (column in table).

Specified by:
removeGetterMapping in interface IObjectMapping
Parameters:
columnName - The database column name of the method method to remove.

removeGetterFieldMapping

public void removeGetterFieldMapping(IGetterMapping getterMapping)

removeGetterMapping

public void removeGetterMapping(java.lang.reflect.Method method)
Description copied from interface: IObjectMapping
Removes the getter method method that maps from the given Method to some database column.

Specified by:
removeGetterMapping in interface IObjectMapping
Parameters:
method - The method mapped from of the method method to remove.

removeSetterMapping

public void removeSetterMapping(java.lang.String columnName)
Description copied from interface: IObjectMapping
Removes the setter method method that maps to the given database column name (column in table).

Specified by:
removeSetterMapping in interface IObjectMapping
Parameters:
columnName - The database column name of the setter method method to remove.

removeSetterMapping

public void removeSetterMapping(java.lang.reflect.Method method)
Description copied from interface: IObjectMapping
Removes the setter method method that maps from the given Method to some database column.

Specified by:
removeSetterMapping in interface IObjectMapping
Parameters:
method - The method mapped from of the method method to remove.

removeSetterFieldMapping

public void removeSetterFieldMapping(ISetterMapping setterMapping)

getGetterMappings

public java.util.Collection getGetterMappings()
Description copied from interface: IObjectMapping
Returns the method mappings that are mapped to getter methods on the mapped object class.

Specified by:
getGetterMappings in interface IObjectMapping
Returns:
A Collection of getter method mappings.

getSetterMappings

public java.util.Collection getSetterMappings()
Description copied from interface: IObjectMapping
Returns the method mappings that are mapped to setter methods on the mapped object class.

Specified by:
getSetterMappings in interface IObjectMapping
Returns:
A Collection of setter method mappings.

getPrimaryKeyGetterMapping

public IGetterMapping getPrimaryKeyGetterMapping()
Description copied from interface: IObjectMapping
Returns the method method (if any) that maps to the primary key of the table mapped to.

Specified by:
getPrimaryKeyGetterMapping in interface IObjectMapping
Returns:
The method method of the primary key.

getPrimaryKeySetterMapping

public ISetterMapping getPrimaryKeySetterMapping()
Description copied from interface: IObjectMapping
Returns the method method (if any) that maps to the primary key of the table mapped to.

Specified by:
getPrimaryKeySetterMapping in interface IObjectMapping
Returns:
The method method of the primary key.

getGetterMapping

public IGetterMapping getGetterMapping(java.lang.String columnName)
Description copied from interface: IObjectMapping
Returns the getter method method that is mapped to the database column name passed in parameter columnName. If no getter method method is found with that database column name, null is returned.

Specified by:
getGetterMapping in interface IObjectMapping
Parameters:
columnName - The database column name to get the getter method method for.
Returns:
The getter method method matching the given database column name. Null if no matching getter method method is found.

getGetterMapping

public IGetterMapping getGetterMapping(java.lang.reflect.Method objectMethod)
Description copied from interface: IObjectMapping
Returns the getter method method that is mapped to the object method passed as parameter objectMethod. If no getter method method is found matching that Method, null is returned.

Specified by:
getGetterMapping in interface IObjectMapping
Parameters:
objectMethod - The method to get the getter method method for.
Returns:
The getter method method matching the given method. Null if no matching getter method method is found.

getSetterMapping

public ISetterMapping getSetterMapping(java.lang.String columnName)
Description copied from interface: IObjectMapping
Returns the setter method method that is mapped to the database column name passed in parameter columnName. If no setter method method is found with that database column name, null is returned.

Specified by:
getSetterMapping in interface IObjectMapping
Parameters:
columnName - The database column name to get the setter method method for.
Returns:
The setter method method matching the given database column name. Null if no matching setter method method is found.

getSetterMapping

public ISetterMapping getSetterMapping(java.lang.reflect.Method objectMethod)
Description copied from interface: IObjectMapping
Returns the setter method method that is mapped to the object method passed as parameter objectMethod. If no setter method method is found matching that Method, null is returned.

Specified by:
getSetterMapping in interface IObjectMapping
Parameters:
objectMethod - The method to get the setter method method for.
Returns:
The setter method method matching the given method. Null if no matching setter method method is found.

toString

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

appendMethodMappings

protected void appendMethodMappings(java.lang.StringBuffer buffer,
                                    java.util.Collection mappings,
                                    java.lang.String direction,
                                    int length)

equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object