Results 1 to 7 of 7

Thread: New constructor for SimpleMongoRepository

  1. #1
    Join Date
    Feb 2012
    Posts
    4

    Exclamation New constructor for SimpleMongoRepository

    Can't SimpleMongoRepository implements a new constructor that require only the MongoOperations interface like my example?


    Code:
    	public SimpleMongoRepository(MongoOperations mongoOperations) {
    		this(new DefaultEntityInformationCreator(mongoOperations.getConverter().getMappingContext()).getEntityInformation(T),
    				mongoOperations);
    	}
    Last edited by stefger; Feb 24th, 2012 at 04:48 AM.

  2. #2
    Join Date
    Apr 2006
    Location
    Dresden, Germany
    Posts
    483

    Default

    No,

    1. it heavily violates the law of demeter [0]
    2. the way the EntityInformation is created has to be pluggable and thus customizable in the factory
    3. (and the probably most convincing argument) the code doesn't compile.



    [0] http://en.wikipedia.org/wiki/Law_Of_Demeter

  3. #3
    Join Date
    Feb 2012
    Posts
    4

    Default

    Ok, thanks for your time.

    Now I need help. How can I extend SimpleMongoRepository without violate law of demeter or how can i create a MongoEntityInformation to autowire it? My actual class is:

    Code:
    @Repository
    public class MyClassRepository extends SimpleMongoRepository<MyClass, Serializable> implements MyClassRepositoryDAO {
    
    	@Autowired
    	public MyClassRepository(MongoOperations mongoOperations) {
    		this(new DefaultEntityInformationCreator(mongoOperations.getConverter().getMappingContext()).getEntityInformation(MyClass.class),
    				mongoOperations);
    	}
    
    	public MyClassRepository(MongoEntityInformation<MyClass, Serializable> metadata, MongoOperations mongoOperations) {
    		super(metadata, mongoOperations);
    	}
    
            ....
    
    }

  4. #4
    Join Date
    Apr 2006
    Location
    Dresden, Germany
    Posts
    483

    Default

    In what context are you trying to use that class? What's the reason you extend SimpleMongoRepository in the first place? (Not saying you shouldn't do this, just want to get more context)

  5. #5
    Join Date
    Feb 2012
    Posts
    4

    Default

    I need to do geospatial queries but i don't want to rewrite the crud operation... so I extended SimpleMongoRepository. My code work but I don't think it's the correct way.

  6. #6
    Join Date
    Apr 2006
    Location
    Dresden, Germany
    Posts
    483

    Default

    Are you aware of the repository abstraction [0] that can execute geospatial queries?

    [0] http://static.springsource.org/sprin...o.repositories

  7. #7
    Join Date
    Feb 2012
    Posts
    4

    Default

    Yeah, but i'm querying events. So i need to search by location and start/end time. Can i do multiqueries with the repository abstraction? I didn't find any evidence, so I guessed on extend the class...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •