com.jenkov.mrpersister.impl.mapping
Class ObjectMappingFactory

java.lang.Object
  extended by com.jenkov.mrpersister.impl.mapping.ObjectMappingFactory
All Implemented Interfaces:
IObjectMappingFactory

public class ObjectMappingFactory
extends java.lang.Object
implements IObjectMappingFactory

Author:
Jakob Jenkov Copyright 2004-2005 Jenkov Development

Constructor Summary
ObjectMappingFactory()
           
 
Method Summary
 void addGetterMapping(IObjectMapping mapping, java.lang.String methodName, java.lang.String columnName, boolean isTableMapped)
          Adds a getter method to the given object mapping.
 void addGetterMapping(IObjectMapping mapping, java.lang.String methodName, java.lang.String columnName, boolean isTableMapped, boolean isPrimaryKey, boolean isAutoGenerated)
          Adds a getter method to the given object mapping.
 void addSetterMapping(IObjectMapping mapping, java.lang.String methodName, java.lang.Class parameterType, java.lang.String columnName, boolean isTableMapped)
          Adds a setter method to the given object mapping.
 void addSetterMapping(IObjectMapping mapping, java.lang.String methodName, java.lang.Class parameterType, java.lang.String columnName, boolean isTableMapped, boolean isPrimaryKey)
          Adds a setter method to the given object mapping.
 void addSetterMapping(IObjectMapping mapping, java.lang.String methodName, java.lang.String columnName, boolean isTableMapped)
          Adds a setter method to the given object mapping.
 void addSetterMapping(IObjectMapping mapping, java.lang.String methodName, java.lang.String columnName, boolean isTableMapped, boolean isPrimaryKey)
          Adds a setter method to the given object mapping.
protected  void assureObjectClass(IObjectMapping mapping)
           
 IGetterMapping copyGetterMapping(IGetterMapping source)
          Copies a getter method mapping.
 IObjectMapping copyObjectMapping(IObjectMapping source)
          Returns a new object mapping that is an exact copy of the original.
 ISetterMapping copySetterMapping(ISetterMapping source)
          Copies the original setter method mapping.
 IGetterMapping createGetterMapping(java.lang.Class memberType)
          Creates an empty getter method mapping of the type that matches the objectType parameter.
 IGetterMapping createGetterMapping(java.lang.Class theClass, java.lang.String methodName, java.lang.String columnName)
           
 IGetterMapping createGetterMapping(java.lang.Class theClass, java.lang.String methodName, java.lang.String columnName, boolean isTableMapped)
           
 IGetterMapping createGetterMapping(java.lang.reflect.Method member, java.lang.String columnName, boolean isTableMapped)
          Creates a getter method mapping with the given Method, database column name, and isTableMapped values prefilled.
 IObjectMappingKey createInstance(java.lang.Class objectClass)
          Creates an object mapping key with the class set.
 IObjectMappingKey createInstance(java.lang.Class objectClass, ICustomObjectMapper mapper)
          Creates an object mapping key with the class set.
 IObjectMappingKey createInstance(java.lang.Class objectClass, java.lang.String name)
          Creates an object mapping key with the class set.
 IObjectMappingKey createInstance(java.lang.Class objectClass, java.lang.String name, ICustomObjectMapper mapper)
          Creates an object mapping key with the class set.
 IKey createKey()
          Creates a new IKey instance.
 IObjectMapping createObjectMapping()
          Creates an empty object mapping instance.
 IObjectMapping createObjectMapping(java.lang.Class objectClass, java.lang.String tableName)
          Creates an object mapping with the object class and table.
 IObjectMapping createObjectMapping(java.lang.Class objectClass, java.lang.String tableName, java.lang.String primaryKeyColumn)
          Creates an object mapping with the object class, table name, and primary key column preset.
 ISetterMapping createSetterMapping(java.lang.Class memberType)
          Creates an empty setter method mapping of a type matching the objectType class.
 ISetterMapping createSetterMapping(java.lang.Class theClass, java.lang.String methodName, java.lang.Class parameterType, java.lang.String columnName)
           
 ISetterMapping createSetterMapping(java.lang.Class theClass, java.lang.String methodName, java.lang.Class parameterType, java.lang.String columnName, boolean isTableMapped)
           
 ISetterMapping createSetterMapping(java.lang.Class methodOwner, java.lang.String methodName, java.lang.String columnName)
           
 ISetterMapping createSetterMapping(java.lang.Class methodOwner, java.lang.String methodName, java.lang.String columnName, boolean isTableMapped)
           
 ISetterMapping createSetterMapping(java.lang.reflect.Method member, java.lang.String columnName, boolean isTableMapped)
          Creates a setter method mapping prefilled with the Method, database column name, and isTableMapped values prefilled.
protected  java.lang.Class getMemberType(java.lang.reflect.Method method)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ObjectMappingFactory

public ObjectMappingFactory()
Method Detail

createInstance

public IObjectMappingKey createInstance(java.lang.Class objectClass)
Description copied from interface: IObjectMappingFactory
Creates an object mapping key with the class set. The class is used when auto-mapping to the database.

Specified by:
createInstance in interface IObjectMappingFactory
Parameters:
objectClass - The class this object mapping key represents an object mapping for.
Returns:
A new object mapping key.

createInstance

public IObjectMappingKey createInstance(java.lang.Class objectClass,
                                        java.lang.String name)
Description copied from interface: IObjectMappingFactory
Creates an object mapping key with the class set. The class is used when auto-mapping to the database.

Specified by:
createInstance in interface IObjectMappingFactory
Parameters:
objectClass - The class this object mapping key represents an object mapping for.
name - The name to set on the object mapping key. Name is only for debug use.
Returns:
A new object mapping key.

createInstance

public IObjectMappingKey createInstance(java.lang.Class objectClass,
                                        ICustomObjectMapper mapper)
Description copied from interface: IObjectMappingFactory
Creates an object mapping key with the class set. The class is used when auto-mapping to the database.

Specified by:
createInstance in interface IObjectMappingFactory
Parameters:
objectClass - The class this object mapping key represents an object mapping for.
mapper - A custom object mapper that can assist the auto-mapper when mapping the class to the database.
Returns:
A new object mapping key.

createInstance

public IObjectMappingKey createInstance(java.lang.Class objectClass,
                                        java.lang.String name,
                                        ICustomObjectMapper mapper)
Description copied from interface: IObjectMappingFactory
Creates an object mapping key with the class set. The class is used when auto-mapping to the database.

Specified by:
createInstance in interface IObjectMappingFactory
Parameters:
objectClass - The class this object mapping key represents an object mapping for.
name - The name to set on the object mapping key. Name is only for debug use.
mapper - A custom object mapper that can assist the auto-mapper when mapping the class to the database.
Returns:
A new object mapping key.

createObjectMapping

public IObjectMapping createObjectMapping()
Description copied from interface: IObjectMappingFactory
Creates an empty object mapping instance.

Specified by:
createObjectMapping in interface IObjectMappingFactory
Returns:
An empty object mapping instance.

createObjectMapping

public IObjectMapping createObjectMapping(java.lang.Class objectClass,
                                          java.lang.String tableName)
Description copied from interface: IObjectMappingFactory
Creates an object mapping with the object class and table.

Specified by:
createObjectMapping in interface IObjectMappingFactory
Parameters:
objectClass - The object class to map
tableName - The database table to map to
Returns:
An object mapping with the object class, table name, and primary key column preset.

createObjectMapping

public IObjectMapping createObjectMapping(java.lang.Class objectClass,
                                          java.lang.String tableName,
                                          java.lang.String primaryKeyColumn)
Description copied from interface: IObjectMappingFactory
Creates an object mapping with the object class, table name, and primary key column preset.

Specified by:
createObjectMapping in interface IObjectMappingFactory
Parameters:
objectClass - The object class to map
tableName - The database table to map to
primaryKeyColumn - The name of the primary key column in that table
Returns:
An object mapping with the object class, table name, and primary key column preset.

copyObjectMapping

public IObjectMapping copyObjectMapping(IObjectMapping source)
Description copied from interface: IObjectMappingFactory
Returns a new object mapping that is an exact copy of the original. Changing this new object mapping will not affect the original object method.

Specified by:
copyObjectMapping in interface IObjectMappingFactory
Parameters:
source - The object mapping to copy.
Returns:
The copy of the object mapping as an independent object mapping instance.

createGetterMapping

public IGetterMapping createGetterMapping(java.lang.Class memberType)
Description copied from interface: IObjectMappingFactory
Creates an empty getter method mapping of the type that matches the objectType parameter. The objectType parameter is the class of the values that this getter method mapping will be able to extract from target objects and insert into PreparedStatement instances. For instance, if this getter method mapping is supposed to extract values from the getter method String getName() the class passed in the objectType parameter should be String.class .

Specified by:
createGetterMapping in interface IObjectMappingFactory
Parameters:
memberType - The class of the object returned by the getter (it's return type) to be mapped by this getter method mapping.
Returns:
An empty IGetterMapping instance.

createGetterMapping

public IGetterMapping createGetterMapping(java.lang.Class theClass,
                                          java.lang.String methodName,
                                          java.lang.String columnName)
                                   throws PersistenceException
Specified by:
createGetterMapping in interface IObjectMappingFactory
Throws:
PersistenceException

createGetterMapping

public IGetterMapping createGetterMapping(java.lang.Class theClass,
                                          java.lang.String methodName,
                                          java.lang.String columnName,
                                          boolean isTableMapped)
                                   throws PersistenceException
Specified by:
createGetterMapping in interface IObjectMappingFactory
Throws:
PersistenceException

createGetterMapping

public IGetterMapping createGetterMapping(java.lang.reflect.Method member,
                                          java.lang.String columnName,
                                          boolean isTableMapped)
Description copied from interface: IObjectMappingFactory
Creates a getter method mapping with the given Method, database column name, and isTableMapped values prefilled. The getter method mapping will be of a type matching the return type of the getter method.

Specified by:
createGetterMapping in interface IObjectMappingFactory
Parameters:
member - The getter Method to map from.
columnName - The database column name to map to.
isTableMapped - Set to true if the database column exists in a table. False if not (if it only exists in a SQL query).
Returns:
An new IGetterMapping with the given parameters prefilled.

copyGetterMapping

public IGetterMapping copyGetterMapping(IGetterMapping source)
Description copied from interface: IObjectMappingFactory
Copies a getter method mapping. The copy is an independent getter method mapping instance. Changing it will not affect the original getter method mapping.

Specified by:
copyGetterMapping in interface IObjectMappingFactory
Parameters:
source - The IGetterMapping instance to copy.
Returns:
A IGetterMapping that is equal to the original.

createSetterMapping

public ISetterMapping createSetterMapping(java.lang.Class memberType)
Description copied from interface: IObjectMappingFactory
Creates an empty setter method mapping of a type matching the objectType class. The objectType is the class of the values that this setter method mapping will be able to set on target objects. For instance, if this setter method is to set values on target objects using the setter method setName(String name) then the class passed in the objectType parameter should be String.class .

Specified by:
createSetterMapping in interface IObjectMappingFactory
Parameters:
memberType - The type/class that this setter method mapping will be able to set on target objects.
Returns:
An empty ISetterMapping instance matching the given objectType.

createSetterMapping

public ISetterMapping createSetterMapping(java.lang.Class methodOwner,
                                          java.lang.String methodName,
                                          java.lang.String columnName)
Specified by:
createSetterMapping in interface IObjectMappingFactory

createSetterMapping

public ISetterMapping createSetterMapping(java.lang.Class methodOwner,
                                          java.lang.String methodName,
                                          java.lang.String columnName,
                                          boolean isTableMapped)
Specified by:
createSetterMapping in interface IObjectMappingFactory

createSetterMapping

public ISetterMapping createSetterMapping(java.lang.Class theClass,
                                          java.lang.String methodName,
                                          java.lang.Class parameterType,
                                          java.lang.String columnName)
                                   throws PersistenceException
Specified by:
createSetterMapping in interface IObjectMappingFactory
Throws:
PersistenceException

createSetterMapping

public ISetterMapping createSetterMapping(java.lang.Class theClass,
                                          java.lang.String methodName,
                                          java.lang.Class parameterType,
                                          java.lang.String columnName,
                                          boolean isTableMapped)
                                   throws PersistenceException
Specified by:
createSetterMapping in interface IObjectMappingFactory
Throws:
PersistenceException

createSetterMapping

public ISetterMapping createSetterMapping(java.lang.reflect.Method member,
                                          java.lang.String columnName,
                                          boolean isTableMapped)
Description copied from interface: IObjectMappingFactory
Creates a setter method mapping prefilled with the Method, database column name, and isTableMapped values prefilled. The setter method mapping will be of a type matching the class of setter methods parameter.

Specified by:
createSetterMapping in interface IObjectMappingFactory
Parameters:
member - The setter method to map from.
columnName - The database column to map to.
isTableMapped - Set to true if the database column exists in a table. False if not (if for instance the database column only exists in an SQL query).
Returns:
A ISetterMapping with the passed parameter values prefilled, matching the parameter type of the setter method.

copySetterMapping

public ISetterMapping copySetterMapping(ISetterMapping source)
Description copied from interface: IObjectMappingFactory
Copies the original setter method mapping. The copy is an independent ISetterMapping instance. Changing the copy will not affect the original.

Specified by:
copySetterMapping in interface IObjectMappingFactory
Parameters:
source - The ISetterMapping instance to copy.
Returns:
A ISetterMapping that is equal to the original.

addGetterMapping

public void addGetterMapping(IObjectMapping mapping,
                             java.lang.String methodName,
                             java.lang.String columnName,
                             boolean isTableMapped)
                      throws java.lang.NoSuchMethodException,
                             PersistenceException
Description copied from interface: IObjectMappingFactory
Adds a getter method to the given object mapping. The getter method will map from the getter method with the given method name to the column with the given column name.

The parameter isTableMapped tells whether the column exists in a table in the database, or only in an SQL query. This information is used when generating SQL for reads and writes.

Specified by:
addGetterMapping in interface IObjectMappingFactory
Parameters:
mapping - The object mapping to add the getter method to.
methodName - The name of the method to map from.
columnName - The name of the column to map to.
isTableMapped - Set to true if the column exists in a database table. False if the column only exists in an SQL query.
Throws:
java.lang.NoSuchMethodException - If no method is found with the given method name.
PersistenceException - If the object mapping does not contain an object class (getObjectClass()== null).

addGetterMapping

public void addGetterMapping(IObjectMapping mapping,
                             java.lang.String methodName,
                             java.lang.String columnName,
                             boolean isTableMapped,
                             boolean isPrimaryKey,
                             boolean isAutoGenerated)
                      throws java.lang.NoSuchMethodException,
                             PersistenceException
Description copied from interface: IObjectMappingFactory
Adds a getter method to the given object mapping. The getter method will map from the getter method with the given method name to the column with the given column name.

The parameter isTableMapped tells whether the column exists in a table in the database, or only in an SQL query. This information is used when generating SQL for reads and writes.

Specified by:
addGetterMapping in interface IObjectMappingFactory
Parameters:
mapping - The object mapping to add the getter method to.
methodName - The name of the method to map from.
columnName - The name of the column to map to.
isTableMapped - Set to true if the column exists in a database table. False if the column only exists in an SQL query.
isPrimaryKey - Set to true if the column is the primary key of the table. False if not.
isAutoGenerated - Set to true if the column is auto generated by the database. False if not.
Throws:
java.lang.NoSuchMethodException - If no method is found with the given method name.
PersistenceException - If the object mapping does not contain an object class (getObjectClass()== null).

addSetterMapping

public void addSetterMapping(IObjectMapping mapping,
                             java.lang.String methodName,
                             java.lang.String columnName,
                             boolean isTableMapped)
                      throws java.lang.NoSuchMethodException,
                             PersistenceException
Description copied from interface: IObjectMappingFactory
Adds a setter method to the given object mapping. The setter method will map from the setter method with the given name to the column with the supplied column name.

The parameter isTableMapped tells whether the column exists in a table in the database, or only in an SQL query. This information is used when generating SQL for reads and writes.

Specified by:
addSetterMapping in interface IObjectMappingFactory
Parameters:
mapping - The object mapping to add the setter method to.
methodName - The name of the method to map from.
columnName - The name of the column to map to.
isTableMapped - Set to true if the column exists in a database table. False if the column only exists in an SQL query.
Throws:
java.lang.NoSuchMethodException - If no method is found with the given method name.
PersistenceException - If the object mapping does not contain an object class (getObjectClass()== null).

addSetterMapping

public void addSetterMapping(IObjectMapping mapping,
                             java.lang.String methodName,
                             java.lang.String columnName,
                             boolean isTableMapped,
                             boolean isPrimaryKey)
                      throws java.lang.NoSuchMethodException,
                             PersistenceException
Description copied from interface: IObjectMappingFactory
Adds a setter method to the given object mapping. The setter method will map from the setter method with the given name to the column with the supplied column name.

The parameter isTableMapped tells whether the column exists in a table in the database, or only in an SQL query. This information is used when generating SQL for reads and writes.

Specified by:
addSetterMapping in interface IObjectMappingFactory
Parameters:
mapping - The object mapping to add the setter method to.
methodName - The name of the method to map from.
columnName - The name of the column to map to.
isTableMapped - Set to true if the column exists in a database table. False if the column only exists in an SQL query.
isPrimaryKey - Set to true if the column is the primary key of the table. False if not.
Throws:
java.lang.NoSuchMethodException - If no method is found with the given method name.
PersistenceException - If the object mapping does not contain an object class (getObjectClass()== null).

addSetterMapping

public void addSetterMapping(IObjectMapping mapping,
                             java.lang.String methodName,
                             java.lang.Class parameterType,
                             java.lang.String columnName,
                             boolean isTableMapped)
                      throws java.lang.NoSuchMethodException,
                             PersistenceException
Description copied from interface: IObjectMappingFactory
Adds a setter method to the given object mapping. The setter method will map from the setter method with the given name to the column with the supplied column name.

The parameterType parameter tells which setter method to use, if you have more than one setter method with the same name, but different parameter types (overloaded setter methods).

The parameter isTableMapped tells whether the column exists in a table in the database, or only in an SQL query. This information is used when generating SQL for reads and writes.

Specified by:
addSetterMapping in interface IObjectMappingFactory
Parameters:
mapping - The object mapping to add the setter method to.
methodName - The name of the method to map from.
parameterType - The parameter type of the setter method to map, in case of overloaded setter methods.
columnName - The name of the column to map to.
isTableMapped - Set to true if the column exists in a database table. False if the column only exists in an SQL query.
Throws:
java.lang.NoSuchMethodException - If no method is found with the given method name and parameter type.
PersistenceException - If the object mapping does not contain an object class (getObjectClass()== null).

addSetterMapping

public void addSetterMapping(IObjectMapping mapping,
                             java.lang.String methodName,
                             java.lang.Class parameterType,
                             java.lang.String columnName,
                             boolean isTableMapped,
                             boolean isPrimaryKey)
                      throws java.lang.NoSuchMethodException,
                             PersistenceException
Description copied from interface: IObjectMappingFactory
Adds a setter method to the given object mapping. The setter method will map from the setter method with the given name to the column with the supplied column name.

The parameterType parameter tells which setter method to use, if you have more than one setter method with the same name, but different parameter types (overloaded setter methods).

The parameter isTableMapped tells whether the column exists in a table in the database, or only in an SQL query. This information is used when generating SQL for reads and writes.

Specified by:
addSetterMapping in interface IObjectMappingFactory
Parameters:
mapping - The object mapping to add the setter method to.
methodName - The name of the method to map from.
parameterType - The parameter type of the setter method to map, in case of overloaded setter methods.
columnName - The name of the column to map to.
isTableMapped - Set to true if the column exists in a database table. False if the column only exists in an SQL query.
isPrimaryKey - Set to true if the column is the priary key of the table. False if not.
Throws:
java.lang.NoSuchMethodException - If no method is found with the given method name and parameter type.
PersistenceException - If the object mapping does not contain an object class (getObjectClass()== null).

createKey

public IKey createKey()
Description copied from interface: IObjectMappingFactory
Creates a new IKey instance. Key instances are used to represent database keys. For instance primary keys and foreign keys.

Specified by:
createKey in interface IObjectMappingFactory

getMemberType

protected java.lang.Class getMemberType(java.lang.reflect.Method method)

assureObjectClass

protected void assureObjectClass(IObjectMapping mapping)
                          throws PersistenceException
Throws:
PersistenceException