Spring Data MongoDB

org.springframework.data.mongodb.core.index
Class MongoPersistentEntityIndexCreator

java.lang.Object
  extended by org.springframework.data.mongodb.core.index.MongoPersistentEntityIndexCreator
All Implemented Interfaces:
EventListener, ApplicationListener<MappingContextEvent<MongoPersistentEntity<?>,MongoPersistentProperty>>

public class MongoPersistentEntityIndexCreator
extends Object
implements ApplicationListener<MappingContextEvent<MongoPersistentEntity<?>,MongoPersistentProperty>>

Component that inspects MongoPersistentEntity instances contained in the given MongoMappingContext for indexing metadata and ensures the indexes to be available.

Author:
Jon Brisbin, Oliver Gierke

Constructor Summary
MongoPersistentEntityIndexCreator(MongoMappingContext mappingContext, MongoDbFactory mongoDbFactory)
          Creats a new MongoPersistentEntityIndexCreator for the given MongoMappingContext and MongoDbFactory.
 
Method Summary
protected  void checkForIndexes(MongoPersistentEntity<?> entity)
           
protected  void ensureIndex(String collection, String name, com.mongodb.DBObject indexDefinition, boolean unique, boolean dropDups, boolean sparse)
          Triggers the actual index creation.
 boolean isIndexCreatorFor(MappingContext<?,?> context)
          Returns whether the current index creator was registered for the given MappingContext.
 void onApplicationEvent(MappingContextEvent<MongoPersistentEntity<?>,MongoPersistentProperty> event)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MongoPersistentEntityIndexCreator

public MongoPersistentEntityIndexCreator(MongoMappingContext mappingContext,
                                         MongoDbFactory mongoDbFactory)
Creats a new MongoPersistentEntityIndexCreator for the given MongoMappingContext and MongoDbFactory.

Parameters:
mappingContext - must not be null
mongoDbFactory - must not be null
Method Detail

onApplicationEvent

public void onApplicationEvent(MappingContextEvent<MongoPersistentEntity<?>,MongoPersistentProperty> event)
Specified by:
onApplicationEvent in interface ApplicationListener<MappingContextEvent<MongoPersistentEntity<?>,MongoPersistentProperty>>

checkForIndexes

protected void checkForIndexes(MongoPersistentEntity<?> entity)

isIndexCreatorFor

public boolean isIndexCreatorFor(MappingContext<?,?> context)
Returns whether the current index creator was registered for the given MappingContext.

Parameters:
context -
Returns:

ensureIndex

protected void ensureIndex(String collection,
                           String name,
                           com.mongodb.DBObject indexDefinition,
                           boolean unique,
                           boolean dropDups,
                           boolean sparse)
Triggers the actual index creation.

Parameters:
collection - the collection to create the index in
name - the name of the index about to be created
indexDefinition - the index definition
unique - whether it shall be a unique index
dropDups - whether to drop duplicates
sparse - sparse or not

Spring Data MongoDB

Copyright © 2011-2013-2013 SpringSource. All Rights Reserved.