Configuring Mappers with a MapperFactory - UML

Similar to previous examples of factories in the case study, the configuration of the PersistenceFacade with a set of IMapper objects can be achieved with a factory object, MapperFactory. However, as a slight twist, it is desirable to not name each mapper with a different operation. For example, this is not desirable:

publicIMappergetSaleMapper() {...}

This does not support Protected Variations with respect to a growing list of mappers - and it will grow. Consequently, the following is preferred:

public Map getAHMappers () { .. . }

where the java.util.Map (probably implemented with a HashMap) keys are the Class objects (the persistent types), and the IMappers are the values.

Then, the facade can initialize its collection of IMappers as follows:

privatejava.util.Map mappers = .getAlIMappers () ;

The factory can assign a set of IMappers using a data - driven design. That is, the factory can read system properties to discover which IMapper classes to instantiate. If a language with reflective programming capabilities is used, such as Java, then the instantiation can be based on reading in the class names as strings, and using something like a Class.newlnstance operation for instantiation. Thus, the mapper set can be reconfigured without changing the source code.

Pattern: Cache Management

It is desirable to maintain materialized objects in a local cache to improve performance (materialization is relatively slow) and support transaction management operations such as a commit.

The Cache Management pattern [BW96] proposes making the Database Mappers responsible for maintaining its cache. If a different mapper is used for each class of persistent object, each mapper can maintain its own cache.

When objects are materialized, they are placed in the cache, with their OID as the key. Subsequent requests to the mapper for an object will cause the mapper to first search the cache, thus avoiding unnecessary materialization.

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd Protection Status

UML Topics