SpringSource/spring-data-neo4j — pull request #109 by spaetzold (2013-05-27 15:19:01+00:00)
Title: Type safety with find methods

Hi there,

I've implemented a type safety policy to allow type safe usage of repositories' find methods. I had the problem in my code base that I sometimes have an ID, but I'm not sure about the Java type of the associated entity. Loading an entity with a given ID works if the ID is somewhere in the database, but no error is raised if the the type does not match (i.e. a organisation can perfectly loaded as person).

I've implemented a TypeSafetyPolicy class with three default implementations. These represent three levels of type safety:

* NONE: No type safety is enforced on repository level. Thus the behaviour is the same as in past release. This is the default if the user selects no other policy.
* RETURNS_NULL: If an entity with a given ID is loaded, but is from a different type as requested null is returned.
* THROWS_EXCEPTION: If an entity with a given ID is loaded, but is from a different type as requested a InvalidEntityTypeException is thrown.

The policy can be selected by defining a Spring bean which is then autowired in the Neo config.

I don't know if this patch is up to your standards, but I'm willing to improve it. In that case please give me some hints where improvement is needed.

-Sebastian