Package org.springframework.data.mongodb.core.index

Examples of org.springframework.data.mongodb.core.index.Index


   * @see org.springframework.data.repository.core.support.QueryCreationListener#onCreation(org.springframework.data.repository.query.RepositoryQuery)
   */
  public void onCreation(PartTreeMongoQuery query) {

    PartTree tree = query.getTree();
    Index index = new Index();
    index.named(query.getQueryMethod().getName());
    Sort sort = tree.getSort();

    for (Part part : tree.getParts()) {
      if (GEOSPATIAL_TYPES.contains(part.getType())) {
        return;
      }
      String property = part.getProperty().toDotPath();
      Direction order = toDirection(sort, property);
      index.on(property, order);
    }

    // Add fixed sorting criteria to index
    if (sort != null) {
      for (Sort.Order order : sort) {
        index.on(order.getProperty(), order.getDirection());
      }
    }

    MongoEntityMetadata<?> metadata = query.getQueryMethod().getEntityInformation();
    operations.indexOps(metadata.getCollectionName()).ensureIndex(index);
View Full Code Here


  @Test
  public void throwsExceptionForIndexViolationIfConfigured() {

    MongoTemplate template = new MongoTemplate(factory);
    template.setWriteResultChecking(WriteResultChecking.EXCEPTION);
    template.indexOps(Person.class).ensureIndex(new Index().on("firstName", Direction.DESC).unique());

    Person person = new Person(new ObjectId(), "Amol");
    person.setAge(28);

    template.save(person);
View Full Code Here

    template.insert(p1);
    Person p2 = new Person("Sven");
    p2.setAge(40);
    template.insert(p2);

    template.indexOps(Person.class).ensureIndex(new Index().on("age", Direction.DESC).unique(Duplicates.DROP));

    DBCollection coll = template.getCollection(template.getCollectionName(Person.class));
    List<DBObject> indexInfo = coll.getIndexInfo();
    assertThat(indexInfo.size(), is(2));
    String indexKey = null;
View Full Code Here

*/
public class IndexUnitTests {

  @Test
  public void testWithAscendingIndex() {
    Index i = new Index().on("name", Direction.ASC);
    assertEquals("{ \"name\" : 1}", i.getIndexKeys().toString());
  }
View Full Code Here

    assertEquals("{ \"name\" : 1}", i.getIndexKeys().toString());
  }

  @Test
  public void testWithDescendingIndex() {
    Index i = new Index().on("name", Direction.DESC);
    assertEquals("{ \"name\" : -1}", i.getIndexKeys().toString());
  }
View Full Code Here

    assertEquals("{ \"name\" : -1}", i.getIndexKeys().toString());
  }

  @Test
  public void testNamedMultiFieldUniqueIndex() {
    Index i = new Index().on("name", Direction.ASC).on("age", Direction.DESC);
    i.named("test").unique();
    assertEquals("{ \"name\" : 1 , \"age\" : -1}", i.getIndexKeys().toString());
    assertEquals("{ \"name\" : \"test\" , \"unique\" : true}", i.getIndexOptions().toString());
  }
View Full Code Here

    assertEquals("{ \"name\" : \"test\" , \"unique\" : true}", i.getIndexOptions().toString());
  }

  @Test
  public void testWithDropDuplicates() {
    Index i = new Index().on("name", Direction.ASC);
    i.unique(Duplicates.DROP);
    assertEquals("{ \"name\" : 1}", i.getIndexKeys().toString());
    assertEquals("{ \"unique\" : true , \"dropDups\" : true}", i.getIndexOptions().toString());
  }
View Full Code Here

    assertEquals("{ \"unique\" : true , \"dropDups\" : true}", i.getIndexOptions().toString());
  }

  @Test
  public void testWithSparse() {
    Index i = new Index().on("name", Direction.ASC);
    i.sparse().unique();
    assertEquals("{ \"name\" : 1}", i.getIndexKeys().toString());
    assertEquals("{ \"unique\" : true , \"sparse\" : true}", i.getIndexOptions().toString());
  }
View Full Code Here

  }

  @Test
  public void ensuresPropertyOrder() {

    Index on = new Index("foo", Direction.ASC).on("bar", Direction.ASC);
    assertThat(on.getIndexKeys().toString(), is("{ \"foo\" : 1 , \"bar\" : 1}"));
  }
View Full Code Here

    */
   @Before
   public void setUp() {
     template.dropCollection(COLLECTION_NAME);
     template.createCollection(COLLECTION_NAME);
     template.indexOps(COLLECTION_NAME).ensureIndex(new Index().on("fullName", Direction.ASC).unique());
   }
View Full Code Here

TOP

Related Classes of org.springframework.data.mongodb.core.index.Index

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.