org.apache.commons.mapper
Interface Mapper

All Known Implementing Classes:
MapperAdapter

public interface Mapper

A Mapper is responsible for mapping domain objects to a persistent data store. By removing this functionality from the domain objects, the backend datastore implementation is allowed to change without affecting any domain objects. Examples of Mapper implementations include JdbcMapper, EjbMapper, and JdoMapper which store data using their respective technologies.

Additionally, Mappers decouple your application from the underlying mapping technology. You might use JdbcMappers for a small website and then migrate to EjbMappers as the site grows without your application code changing.

Mapper implementations should not use instance variables to maintain state because they will be run in a multi-threaded environment. The MapperFactory will return the same instance of a Mapper every time it's requested. Mappers should use local method variables and method parameters to maintain thread safety.

Mapper is equivalent to the concept of a data access object (DAO).

See Also:
MapperFactory

Method Summary
 Object create(Object object)
          Create the given object in a persistent data store.
 void delete(Object object)
          Remove an object from the data store.
 Collection findAllObjects()
          Returns a Collection of all objects for the given mapper.
 Object findByUniqueId(Object id)
          Find the given Object based on its unique identifier.
 void update(Object object)
          Update the given object in the data store.
 

Method Detail

create

Object create(Object object)
              throws MapperException
Create the given object in a persistent data store. The Mapper should document what type of Object is expected.

Returns:
Object the created object's unique id.
Throws:
MapperException
UnsupportedOperationException - if this mapper doesn't support this method.

findByUniqueId

Object findByUniqueId(Object id)
                      throws MapperException
Find the given Object based on its unique identifier. This could be a primary key for relational database backends or an ID field in an XML file for XML implementations. The Mapper should document what type of object is expected and what type it returns.

Parameters:
id - An Object that represents a unique ID or a container for composite key values.
Returns:
Object a single object with the given id or null if none found
Throws:
MapperException
UnsupportedOperationException - if this mapper doesn't support this method.

delete

void delete(Object object)
            throws MapperException
Remove an object from the data store.

Throws:
MapperException
UnsupportedOperationException - if this mapper doesn't support this method.

update

void update(Object object)
            throws MapperException
Update the given object in the data store.

Throws:
MapperException
UnsupportedOperationException - if this mapper doesn't support this method.

findAllObjects

Collection findAllObjects()
                          throws MapperException
Returns a Collection of all objects for the given mapper.

Throws:
MapperException
UnsupportedOperationException - if this mapper doesn't support this method.


Copyright © 2001-2010 The Apache Software Foundation. All Rights Reserved.