com.jenkov.mrpersister.itf.mapping
Interface IObjectMappingFactory

All Known Implementing Classes:
ObjectMappingFactory

public interface IObjectMappingFactory

This interface represents the functions of the object mapping factorie(s) used by Mr. Persister. The purpose of the object mapping factory is to make it easier for the users of the API to create customized object mappings and method mappings.

The object mapping factory is also used by the object mapper in Mr. Persister.

Author:
Jakob Jenkov, Jenkov Development

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.
 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 objectType)
          Creates an empty getter method mapping of the type that matches the objectType parameter.
 IGetterMapping createGetterMapping(java.lang.Class methodOwner, java.lang.String methodName, java.lang.String columnName)
           
 IGetterMapping createGetterMapping(java.lang.Class methodOwner, java.lang.String methodName, java.lang.String columnName, boolean isTableMapped)
           
 IGetterMapping createGetterMapping(java.lang.reflect.Method method, java.lang.String dbFieldName, boolean isTableMapped)
          Creates a getter method mapping with the given Method, database column name, and isTableMapped values prefilled.
 IObjectMappingKey createInstance(java.lang.Class objectClass)
          Deprecated. Renamed to createObjectMappingKey
 IObjectMappingKey createInstance(java.lang.Class objectClass, ICustomObjectMapper mapper)
          Deprecated. Renamed to createObjectMappingKey
 IObjectMappingKey createInstance(java.lang.Class objectClass, java.lang.String name)
          Deprecated. Renamed to createObjectMappingKey
 IObjectMappingKey createInstance(java.lang.Class objectClass, java.lang.String name, ICustomObjectMapper mapper)
          Deprecated. Renamed to createObjectMappingKey
 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 objectType)
          Creates an empty setter method mapping of a type matching the objectType class.
 ISetterMapping createSetterMapping(java.lang.Class methodOwner, java.lang.String methodName, java.lang.Class parameterType, java.lang.String columnName)
           
 ISetterMapping createSetterMapping(java.lang.Class methodOwner, 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 method, java.lang.String dbFieldName, boolean isTableMapped)
          Creates a setter method mapping prefilled with the Method, database column name, and isTableMapped values prefilled.
 

Method Detail

createInstance

IObjectMappingKey createInstance(java.lang.Class objectClass)
Deprecated. Renamed to createObjectMappingKey

Creates an object mapping key with the class set. The class is used when auto-mapping to the database.

Parameters:
objectClass - The class this object mapping key represents an object mapping for.
Returns:
A new object mapping key.

createInstance

IObjectMappingKey createInstance(java.lang.Class objectClass,
                                 java.lang.String name)
Deprecated. Renamed to createObjectMappingKey

Creates an object mapping key with the class set. The class is used when auto-mapping to the database.

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

IObjectMappingKey createInstance(java.lang.Class objectClass,
                                 ICustomObjectMapper mapper)
Deprecated. Renamed to createObjectMappingKey

Creates an object mapping key with the class set. The class is used when auto-mapping to the database.

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

IObjectMappingKey createInstance(java.lang.Class objectClass,
                                 java.lang.String name,
                                 ICustomObjectMapper mapper)
Deprecated. Renamed to createObjectMappingKey

Creates an object mapping key with the class set. The class is used when auto-mapping to the database.

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

IObjectMapping createObjectMapping()
Creates an empty object mapping instance.

Returns:
An empty object mapping instance.

createObjectMapping

IObjectMapping createObjectMapping(java.lang.Class objectClass,
                                   java.lang.String tableName)
Creates an object mapping with the object class and table.

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

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.

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

IObjectMapping copyObjectMapping(IObjectMapping source)
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.

Parameters:
source - The object mapping to copy.
Returns:
The copy of the object mapping as an independent object mapping instance.

createGetterMapping

IGetterMapping createGetterMapping(java.lang.Class objectType)
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 .

Parameters:
objectType - 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

IGetterMapping createGetterMapping(java.lang.Class methodOwner,
                                   java.lang.String methodName,
                                   java.lang.String columnName)
                                   throws PersistenceException
Throws:
PersistenceException

createGetterMapping

IGetterMapping createGetterMapping(java.lang.Class methodOwner,
                                   java.lang.String methodName,
                                   java.lang.String columnName,
                                   boolean isTableMapped)
                                   throws PersistenceException
Throws:
PersistenceException

createGetterMapping

IGetterMapping createGetterMapping(java.lang.reflect.Method method,
                                   java.lang.String dbFieldName,
                                   boolean isTableMapped)
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.

Parameters:
method - The getter Method to map from.
dbFieldName - 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

IGetterMapping copyGetterMapping(IGetterMapping source)
Copies a getter method mapping. The copy is an independent getter method mapping instance. Changing it will not affect the original getter method mapping.

Parameters:
source - The IGetterMapping instance to copy.
Returns:
A IGetterMapping that is equal to the original.

createSetterMapping

ISetterMapping createSetterMapping(java.lang.Class objectType)
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 .

Parameters:
objectType - 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

ISetterMapping createSetterMapping(java.lang.Class methodOwner,
                                   java.lang.String methodName,
                                   java.lang.String columnName)
                                   throws PersistenceException
Throws:
PersistenceException

createSetterMapping

ISetterMapping createSetterMapping(java.lang.Class methodOwner,
                                   java.lang.String methodName,
                                   java.lang.Class parameterType,
                                   java.lang.String columnName)
                                   throws PersistenceException
Throws:
PersistenceException

createSetterMapping

ISetterMapping createSetterMapping(java.lang.Class methodOwner,
                                   java.lang.String methodName,
                                   java.lang.Class parameterType,
                                   java.lang.String columnName,
                                   boolean isTableMapped)
                                   throws PersistenceException
Throws:
PersistenceException

createSetterMapping

ISetterMapping createSetterMapping(java.lang.Class methodOwner,
                                   java.lang.String methodName,
                                   java.lang.String columnName,
                                   boolean isTableMapped)
                                   throws PersistenceException
Throws:
PersistenceException

createSetterMapping

ISetterMapping createSetterMapping(java.lang.reflect.Method method,
                                   java.lang.String dbFieldName,
                                   boolean isTableMapped)
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.

Parameters:
method - The setter method to map from.
dbFieldName - 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

ISetterMapping copySetterMapping(ISetterMapping source)
Copies the original setter method mapping. The copy is an independent ISetterMapping instance. Changing the copy will not affect the original.

Parameters:
source - The ISetterMapping instance to copy.
Returns:
A ISetterMapping that is equal to the original.

addGetterMapping

void addGetterMapping(IObjectMapping mapping,
                      java.lang.String methodName,
                      java.lang.String columnName,
                      boolean isTableMapped)
                      throws java.lang.NoSuchMethodException,
                             PersistenceException
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.

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

void addGetterMapping(IObjectMapping mapping,
                      java.lang.String methodName,
                      java.lang.String columnName,
                      boolean isTableMapped,
                      boolean isPrimaryKey,
                      boolean isAutoGenerated)
                      throws java.lang.NoSuchMethodException,
                             PersistenceException
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.

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

void addSetterMapping(IObjectMapping mapping,
                      java.lang.String methodName,
                      java.lang.String columnName,
                      boolean isTableMapped)
                      throws java.lang.NoSuchMethodException,
                             PersistenceException
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.

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

void addSetterMapping(IObjectMapping mapping,
                      java.lang.String methodName,
                      java.lang.String columnName,
                      boolean isTableMapped,
                      boolean isPrimaryKey)
                      throws java.lang.NoSuchMethodException,
                             PersistenceException
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.

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

void addSetterMapping(IObjectMapping mapping,
                      java.lang.String methodName,
                      java.lang.Class parameterType,
                      java.lang.String columnName,
                      boolean isTableMapped)
                      throws java.lang.NoSuchMethodException,
                             PersistenceException
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.

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

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
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.

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

IKey createKey()
Creates a new IKey instance. Key instances are used to represent database keys. For instance primary keys and foreign keys.