com.jenkov.mrpersister.itf.mapping
Interface IObjectMapper

All Known Implementing Classes:
ObjectMapper

public interface IObjectMapper

This interface represents the functions made available by the object mapper in Mr. Persister. The object mapper is responsible for mapping a class to a database table automatically. The result of such a method is an object mapping instance. See IObjectMapping for more info on these.

The object mapper uses a database name guesser, a database name determiner and a database primary key determiner internally to do it's job.

Author:
Jakob Jenkov, Jenkov Development

Method Summary
 IDbNameDeterminer getDbNameDeterminer()
          Returns the database name determiner used by this object mapper.
 IDbNameGuesser getDbNameGuesser()
          Returns the database name guesser used by this object mapper.
 IDbPrimaryKeyDeterminer getDbPrimaryKeyDeterminer()
          Returns the database primary key determiner used by this object mapper.
 IObjectMapping getObjectMapping(java.lang.Object objectMappingKey, IPersistenceConfiguration configuration, java.sql.Connection connection)
          Returns an object mapping from the cache in the given configuration, if one already exists.
 IObjectMapping mapGettersToTable(java.lang.Class persistentObjectClass, IObjectMapping objectMapping, java.sql.Connection connection, java.lang.String databaseName, java.lang.String table)
          Maps an object to the table provided as parameter, using method name guessing for the members/fields.
 IObjectMapping mapSettersToSelf(java.lang.Class persistentObjectClass, IObjectMapping objectMapping)
          Maps an object to fields named the same as it's setters and adds the method mappings to the provided object mapping.
 IObjectMapping mapSettersToTable(java.lang.Class persistentObjectClass, IObjectMapping objectMapping, java.sql.Connection connection, java.lang.String databaseName, java.lang.String table)
          Maps an object to the table provided as parameter, using method name guessing for the members/fields.
 IObjectMapping mapToTable(java.lang.Class persistentObjectClass, IObjectMapping objectMapping, java.sql.Connection connection, java.lang.String databaseName, java.lang.String table)
          Maps an object to the table provided as parameter, using method name guessing for the members/fields.
 void setDbNameDeterminer(IDbNameDeterminer nameDeterminer)
          Sets the database name determiner to be used by this object mapper.
 void setDbNameGuesser(IDbNameGuesser guesser)
          Sets the database name determiner used by this object mapper.
 void setDbPrimaryKeyDeterminer(IDbPrimaryKeyDeterminer primaryKeyDeterminer)
          Sets the database primary key determiner to be used by this object mapper.
 

Method Detail

getDbNameGuesser

IDbNameGuesser getDbNameGuesser()
Returns the database name guesser used by this object mapper.

Returns:
The database name guesser used by this object mapper.

setDbNameGuesser

void setDbNameGuesser(IDbNameGuesser guesser)
Sets the database name determiner used by this object mapper.

Parameters:
guesser - The databa name guesser to be used by this object mapper.

getDbNameDeterminer

IDbNameDeterminer getDbNameDeterminer()
Returns the database name determiner used by this object mapper.

Returns:
The database name determiner used by this object mapper.

setDbNameDeterminer

void setDbNameDeterminer(IDbNameDeterminer nameDeterminer)
Sets the database name determiner to be used by this object mapper.

Parameters:
nameDeterminer - The database name determiner to be used by this object mapper.

getDbPrimaryKeyDeterminer

IDbPrimaryKeyDeterminer getDbPrimaryKeyDeterminer()
Returns the database primary key determiner used by this object mapper.

Returns:
The database primary key determiner used by this object mapper.

setDbPrimaryKeyDeterminer

void setDbPrimaryKeyDeterminer(IDbPrimaryKeyDeterminer primaryKeyDeterminer)
Sets the database primary key determiner to be used by this object mapper.

Parameters:
primaryKeyDeterminer - The database primary key determiner to be used by this object mapper.

getObjectMapping

IObjectMapping getObjectMapping(java.lang.Object objectMappingKey,
                                IPersistenceConfiguration configuration,
                                java.sql.Connection connection)
                                throws PersistenceException
Returns an object mapping from the cache in the given configuration, if one already exists. If not a new object mapping is tried generated, cached for later use, and returned.

Parameters:
objectMappingKey - The key under which to retrieve and/or store the object mapping.
configuration - The configuration containing the object mapping cache.
connection - A database connection used in case the mapper
Returns:
Throws:
PersistenceException

mapToTable

IObjectMapping mapToTable(java.lang.Class persistentObjectClass,
                          IObjectMapping objectMapping,
                          java.sql.Connection connection,
                          java.lang.String databaseName,
                          java.lang.String table)
                          throws PersistenceException
Maps an object to the table provided as parameter, using method name guessing for the members/fields.

Parameters:
persistentObjectClass - The class of the object to map.
objectMapping - An optional object mapping to add the method mappings to. If null is provided the object mapper will create an empty object mapping, add the method mappings to it and return it.
connection - A connection to the database containing the table the objects should be mapped to.
databaseName - The name of the database the table is residing in. In most cases this parameter can be null, since the connection is normally pointing to a certain database.
table - The name of the database table to map the objects to. Optional. If null is given the object mapper will try to guess the table name from the objects class name.
Returns:
An object mapping with guessed method names from the given table. If a method name for an object mapping (getter/setter) could not be guessed there will be no method method for that method.
Throws:
PersistenceException - If anything goes wrong during the method.

mapGettersToTable

IObjectMapping mapGettersToTable(java.lang.Class persistentObjectClass,
                                 IObjectMapping objectMapping,
                                 java.sql.Connection connection,
                                 java.lang.String databaseName,
                                 java.lang.String table)
                                 throws PersistenceException
Maps an object to the table provided as parameter, using method name guessing for the members/fields.

Parameters:
persistentObjectClass - The class of the object to map.
objectMapping - An optional object mapping to add the method mappings to. If null is provided the object mapper will create an empty object mapping, add the method mappings to it and return it.
connection - A connection to the database containing the table the objects should be mapped to.
databaseName - The name of the database the table is residing in. In most cases this parameter can be null, since the connection is normally pointing to a certain database.
table - The name of the database table to map the objects to. Optional. If null is given the object mapper will try to guess the table name from the objects class name.
Returns:
An object mapping with guessed method names from the given table. If a method name for an object mapping (getter/setter) could not be guessed there will be no method method for that method.
Throws:
PersistenceException - If anything goes wrong during the method.

mapSettersToTable

IObjectMapping mapSettersToTable(java.lang.Class persistentObjectClass,
                                 IObjectMapping objectMapping,
                                 java.sql.Connection connection,
                                 java.lang.String databaseName,
                                 java.lang.String table)
                                 throws PersistenceException
Maps an object to the table provided as parameter, using method name guessing for the members/fields.

Parameters:
persistentObjectClass - The class of the object to map.
objectMapping - An optional object mapping to add the method mappings to. If null is provided the object mapper will create an empty object mapping, add the method mappings to it and return it.
connection - A connection to the database containing the table the objects should be mapped to.
databaseName - The name of the database the table is residing in. In most cases this parameter can be null, since the connection is normally pointing to a certain database.
table - The name of the database table to map the objects to. Optional. If null is given the object mapper will try to guess the table name from the objects class name.
Returns:
An object mapping with guessed method names from the given table. If a method name for an object mapping (getter/setter) could not be guessed there will be no method method for that method.
Throws:
PersistenceException - If anything goes wrong during the method.

mapSettersToSelf

IObjectMapping mapSettersToSelf(java.lang.Class persistentObjectClass,
                                IObjectMapping objectMapping)
                                throws PersistenceException
Maps an object to fields named the same as it's setters and adds the method mappings to the provided object mapping. If null is provided as object mapping an empty object method instance is created and used. An object containing a setHomeAddress will have a method method with the method name "setHomeAddress". This method is very useful when method objects to SQL queries instead of tables. With a self-mapped object you can read values into it using an sql like: select homeAddr as setHomeAddress from users. The method in the result set will be called setHomeAddres. The object mapping will then translate that name to the setHomeAddress(...) method (because that method is mapped to a method called "setHomeAddress" in the object mapping).

Parameters:
persistentObjectClass - The class to map to itself.
Returns:
An object mapping with all setters mapped to fields with the same name as the coresponding setter method.
Throws:
PersistenceException