Skip to content

DATAMONGO-1163 #325

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>
Expand All @@ -15,7 +15,7 @@
<parent>
<groupId>org.springframework.data.build</groupId>
<artifactId>spring-data-parent</artifactId>
<version>1.8.0.BUILD-SNAPSHOT</version>
<version>1.7.0.RELEASE</version>
</parent>

<modules>
Expand All @@ -28,7 +28,7 @@
<properties>
<project.type>multi</project.type>
<dist.id>spring-data-mongodb</dist.id>
<springdata.commons>1.12.0.BUILD-SNAPSHOT</springdata.commons>
<springdata.commons>1.11.0.RELEASE</springdata.commons>
<mongo>2.13.0</mongo>
<mongo.osgi>2.13.0</mongo.osgi>
</properties>
Expand Down Expand Up @@ -156,8 +156,8 @@

<repositories>
<repository>
<id>spring-libs-snapshot</id>
<url>https://repo.spring.io/libs-snapshot</url>
<id>spring-libs-release</id>
<url>https://repo.spring.io/libs-release</url>
</repository>
</repositories>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@
* @author Johno Crawford
* @author Thomas Darimont
* @author Christoph Strobl
* @author Jordi Llach
*/
@Target(ElementType.FIELD)
@Target({ElementType.ANNOTATION_TYPE, ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
public @interface Indexed {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,16 @@
*/
package org.springframework.data.mongodb.core.index;

import com.mongodb.DBCollection;
import com.mongodb.DBObject;
import com.mongodb.MongoException;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;

import org.junit.After;
import static org.junit.Assert.*;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -30,10 +36,6 @@
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import com.mongodb.DBCollection;
import com.mongodb.DBObject;
import com.mongodb.MongoException;

/**
* Integration tests for index handling.
*
Expand All @@ -45,26 +47,33 @@
public class IndexingIntegrationTests {

@Autowired MongoOperations operations;

@After
@After
public void tearDown() {
operations.dropCollection(IndexedPerson.class);
operations.dropCollection(IndexedPerson.class);
}

/**
/**
* @see DATADOC-237
* @see DATAMONGO-1163
*/
@Test
public void createsIndexWithFieldName() {

operations.save(new IndexedPerson());
assertThat(hasIndex("_firstname", IndexedPerson.class), is(true));
assertThat(hasIndex("_lastname", IndexedPerson.class), is(true));
}

@Target({ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
@Indexed
@interface IndexedFieldAnnotation {}

@Document
class IndexedPerson {

@Field("_firstname") @Indexed String firstname;
@Field("_lastname") @IndexedFieldAnnotation String lastname;
}

/**
Expand All @@ -87,4 +96,4 @@ public Boolean doInCollection(DBCollection collection) throws MongoException, Da
}
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,21 @@
*/
package org.springframework.data.mongodb.core.index;

import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;

import com.mongodb.BasicDBObjectBuilder;
import com.mongodb.DBObject;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.util.Collections;
import java.util.List;

import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
import static org.mockito.Mockito.*;
import org.springframework.data.geo.Point;
import org.springframework.data.mongodb.core.DBObjectTestUtils;
import org.springframework.data.mongodb.core.index.MongoPersistentEntityIndexResolver.IndexDefinitionHolder;
Expand All @@ -44,9 +48,6 @@
import org.springframework.data.mongodb.core.mapping.MongoPersistentProperty;
import org.springframework.data.util.ClassTypeInformation;

import com.mongodb.BasicDBObjectBuilder;
import com.mongodb.DBObject;

/**
* @author Christoph Strobl
*/
Expand Down Expand Up @@ -148,6 +149,17 @@ public void resolvesIndexCollectionNameCorrectlyWhenDefinedInAnnotation() {
assertThat(indexDefinitions.get(0).getCollection(), equalTo("CollectionOverride"));
}

/**
* @see DATAMONGO-1163
*/
@Test
public void resolveIndexDefinitionInMetaAnnotatedFields() {
List<IndexDefinitionHolder> indexDefinitions = prepareMappingContextAndResolveIndexForType(IndexOnMetaAnnotatedField.class);
assertThat(indexDefinitions, hasSize(1));
assertThat(indexDefinitions.get(0).getCollection(), equalTo("indexOnMetaAnnotatedField"));
assertThat(indexDefinitions.get(0).getIndexOptions(), equalTo(new BasicDBObjectBuilder().add("name", "_name").get()));
}

@Document(collection = "Zero")
static class IndexOnLevelZero {
@Indexed String indexedProperty;
Expand Down Expand Up @@ -181,7 +193,18 @@ static class IndexOnLevelZeroWithExplicityNamedField {

@Indexed @Field("customFieldName") String namedProperty;
}

@Target({ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
@Indexed
@interface IndexedFieldAnnotation {

}

@Document
static class IndexOnMetaAnnotatedField {
@Field("_name") @IndexedFieldAnnotation String lastname;
}
}

/**
Expand Down