hibernate/hibernate-ogm — pull request #217 by gunnarmorling (2013-08-21 14:23:20+00:00)
Title: OGM-208 Approach 2 using proxies

Based on the work of @DavideD, this PR provides a slightly different scheme for implementing the option context types.

The idea is to require only the actual option conversion routine to be implemented in the provider specific context types, while the implementations for the "context switch" methods (`entity()` and `property()`) are "mixed in" using Javassist dynamic sub-class proxies.

This reduces the effort for the provider-specific context types as much as possible, e.g. like this:

public interface MongoDBEntityContext {
MongoDBEntityContext writeConcern(WriteConcern concern);
}

//declaring the type as abstract avoids the need for entity() and property()
public abstract class MongoDBEntityImpl extends OptionSupport implements MongoDBEntityContext {

public MongoDBEntityImpl(MappingContext context ) {
super( context );
}

@Override
public MongoDBEntityContext writeConcern(WriteConcern concern) {
addEntityOption( new WriteConcernOption( concern ) );
return this;
}
}

Within the provider-specific factory class, the three context implementation types need to be made known:

@Override
public MongoDBGlobalContext createMapping(MappingContext context) {
return context.createGlobalMappingContext(
MongoDBGlobalImpl.class,
MongoDBEntityImpl.class,
MongoDBPropertyImpl.class );
}

The returned context object is a dynamic proxy which invokes the manually implemented methods as well as `entity()` and `property()` contributed via a method handler as required.