Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

DATADOC-264 - Upgraded examples to 1.0.0.M4.

  • Loading branch information...
commit cc392cb55576186a788e8ba371263767c84a1a6c 1 parent e016a92
@olivergierke olivergierke authored
Showing with 445 additions and 546 deletions.
  1. +3 −3 mongodb-customer-service-data/pom.xml
  2. +1 −9 ...c/test/resources/org/springframework/data/mongodb/examples/custsvc/data/CustomerRepositoryTests-context.xml
  3. +2 −2 mongodb-hello/pom.xml
  4. +11 −9 mongodb-hello/src/main/java/org/springframework/data/mongodb/examples/hello/AppConfig.java
  5. +12 −12 mongodb-hello/src/main/java/org/springframework/data/mongodb/examples/hello/HelloMongo.java
  6. +1 −1  mongodb-hello/src/main/java/org/springframework/data/mongodb/examples/hello/domain/Person.java
  7. +44 −43 mongodb-hello/src/test/java/org/springframework/data/mongodb/examples/hello/SimpleMongoTest.java
  8. +1 −1  mongodb-hello/src/test/resources/org/springframework/data/mongodb/examples/hello/SimpleMongoTest-context.xml
  9. +4 −4 mongodb-music/pom.xml
  10. +69 −67 mongodb-music/src/main/java/org/springframework/data/mongodb/examples/music/Album.java
  11. +140 −140 mongodb-music/src/test/java/org/springframework/data/mongodb/examples/music/AbstractIntegrationTest.java
  12. +40 −40 ...odb-music/src/test/java/org/springframework/data/mongodb/examples/music/AlbumRepositoryIntegrationTest.java
  13. +50 −50 mongodb-music/src/test/java/org/springframework/data/mongodb/examples/music/AlbumsIntegrationTest.java
  14. +15 −8 mongodb-music/src/test/java/org/springframework/data/mongodb/examples/music/QueryDslIntegrationTests.java
  15. +1 −1  ...usic/src/test/resources/org/springframework/data/mongodb/examples/music/AbstractIntegrationTest-context.xml
  16. +1 −1  ...sic/src/test/resources/org/springframework/data/mongodb/examples/music/QueryDslIntegrationTests-context.xml
  17. +12 −8 mongodb-myrestaurants-analytics/src/main/java/com/springone/myrestaurants/config/MongoConfiguration.java
  18. +0 −110 mongodb-myrestaurants-analytics/src/main/webapp/WEB-INF/web.xml~
  19. +38 −37 ...staurants-analytics/src/test/java/org/springframework/data/document/mongodb/analytics/MvcAnalyticsTest.java
View
6 mongodb-customer-service-data/pom.xml
@@ -10,9 +10,9 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
- <spring.version>3.0.5.RELEASE</spring.version>
- <spring.data.mongo.version>1.0.0.M3</spring.data.mongo.version>
- <spring.data.jpa.version>1.0.0.BUILD-SNAPSHOT</spring.data.jpa.version>
+ <spring.version>3.0.6.RELEASE</spring.version>
+ <spring.data.mongo.version>1.0.0.M4</spring.data.mongo.version>
+ <spring.data.jpa.version>1.1.0.M1</spring.data.jpa.version>
<aspectj.version>1.6.11.RELEASE</aspectj.version>
<slf4j.version>1.6.1</slf4j.version>
</properties>
View
10 ...est/resources/org/springframework/data/mongodb/examples/custsvc/data/CustomerRepositoryTests-context.xml
@@ -30,12 +30,10 @@
<!-- Mongo config -->
<mongo:db-factory host="localhost" port="27017" dbname="test"/>
- <bean id="mongoTemplate" class="org.springframework.data.document.mongodb.MongoTemplate">
+ <bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate">
<constructor-arg name="mongoDbFactory" ref="mongoDbFactory"/>
</bean>
- <bean class="org.springframework.data.document.mongodb.MongoExceptionTranslator"/>
-
<!-- Mongo aspect config -->
<bean class="org.springframework.data.persistence.document.mongodb.MongoDocumentBacking"
factory-method="aspectOf">
@@ -50,10 +48,4 @@
<!-- Configure JPA Repositories -->
<jpa:repositories base-package="org.springframework.data.mongodb.examples.custsvc.data"/>
- <!-- Necessary to get the entity manager injected into the factory bean -->
- <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
-
- <!-- Adds transaparent exception translation to the DAOs -->
- <bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" />
-
</beans>
View
4 mongodb-hello/pom.xml
@@ -11,8 +11,8 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
- <spring.version>3.0.5.RELEASE</spring.version>
- <spring.data.mongo.version>1.0.0.M3</spring.data.mongo.version>
+ <spring.version>3.0.6.RELEASE</spring.version>
+ <spring.data.mongo.version>1.0.0.M4</spring.data.mongo.version>
<slf4j.version>1.6.1</slf4j.version>
</properties>
View
20 mongodb-hello/src/main/java/org/springframework/data/mongodb/examples/hello/AppConfig.java
@@ -1,32 +1,34 @@
package org.springframework.data.mongodb.examples.hello;
-import com.mongodb.Mongo;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor;
-import org.springframework.data.document.mongodb.MongoFactoryBean;
-import org.springframework.data.document.mongodb.MongoTemplate;
+import org.springframework.data.mongodb.core.MongoFactoryBean;
+import org.springframework.data.mongodb.core.MongoOperations;
+import org.springframework.data.mongodb.core.MongoTemplate;
+
+import com.mongodb.Mongo;
@Configuration
public class AppConfig {
- public @Bean MongoTemplate mongoTemplate(Mongo mongo) {
+ public @Bean MongoOperations mongoTemplate(Mongo mongo) {
MongoTemplate mongoTemplate = new MongoTemplate(mongo, "test");
return mongoTemplate;
}
/*
- * Factory bean that creates the Mongo instance
- */
+ * Factory bean that creates the Mongo instance
+ */
public @Bean MongoFactoryBean mongo() {
MongoFactoryBean mongo = new MongoFactoryBean();
mongo.setHost("localhost");
return mongo;
}
- /*
- * Use this post processor to translate any MongoExceptions thrown in @Repository annotated classes
- */
+ /*
+ * Use this post processor to translate any MongoExceptions thrown in @Repository annotated classes
+ */
public @Bean PersistenceExceptionTranslationPostProcessor persistenceExceptionTranslationPostProcessor() {
return new PersistenceExceptionTranslationPostProcessor();
}
View
24 mongodb-hello/src/main/java/org/springframework/data/mongodb/examples/hello/HelloMongo.java
@@ -3,32 +3,32 @@
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.data.document.mongodb.MongoTemplate;
+import org.springframework.data.mongodb.core.MongoOperations;
import org.springframework.data.mongodb.examples.hello.domain.Account;
import org.springframework.data.mongodb.examples.hello.domain.Person;
import org.springframework.stereotype.Repository;
@Repository
public class HelloMongo {
-
+
@Autowired
- MongoTemplate mongoTemplate;
+ MongoOperations mongoOperations;
public void run() {
-
- if (mongoTemplate.collectionExists(Person.class)) {
- mongoTemplate.dropCollection(Person.class);
+
+ if (mongoOperations.collectionExists(Person.class)) {
+ mongoOperations.dropCollection(Person.class);
}
-
- mongoTemplate.createCollection(Person.class);
+
+ mongoOperations.createCollection(Person.class);
Person p = new Person("John", 39);
Account a = new Account("1234-59873-893-1", Account.Type.SAVINGS, 123.45D);
p.getAccounts().add(a);
-
- mongoTemplate.insert(p);
-
- List<Person> results = mongoTemplate.findAll(Person.class);
+
+ mongoOperations.insert(p);
+
+ List<Person> results = mongoOperations.findAll(Person.class);
System.out.println("Results: " + results);
}
View
2  mongodb-hello/src/main/java/org/springframework/data/mongodb/examples/hello/domain/Person.java
@@ -4,7 +4,7 @@
import java.util.List;
import org.springframework.data.annotation.Id;
-import org.springframework.data.document.mongodb.mapping.Document;
+import org.springframework.data.mongodb.core.mapping.Document;
@Document
public class Person {
View
87 mongodb-hello/src/test/java/org/springframework/data/mongodb/examples/hello/SimpleMongoTest.java
@@ -1,85 +1,86 @@
package org.springframework.data.mongodb.examples.hello;
import static org.junit.Assert.*;
-import static org.springframework.data.document.mongodb.query.Criteria.*;
-import static org.springframework.data.document.mongodb.query.Query.query;
+import static org.springframework.data.mongodb.core.query.Criteria.*;
+import static org.springframework.data.mongodb.core.query.Query.*;
import java.util.List;
-import com.mongodb.DBCollection;
-import com.mongodb.WriteResult;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.data.document.mongodb.MongoCollectionUtils;
-import org.springframework.data.document.mongodb.MongoTemplate;
-import org.springframework.data.document.mongodb.query.Index;
-import org.springframework.data.document.mongodb.query.Order;
-import org.springframework.data.document.mongodb.query.Query;
-import org.springframework.data.document.mongodb.query.Update;
+import org.springframework.data.mongodb.MongoCollectionUtils;
+import org.springframework.data.mongodb.core.MongoOperations;
+import org.springframework.data.mongodb.core.index.Index;
+import org.springframework.data.mongodb.core.query.Order;
+import org.springframework.data.mongodb.core.query.Query;
+import org.springframework.data.mongodb.core.query.Update;
import org.springframework.data.mongodb.examples.hello.domain.Account;
import org.springframework.data.mongodb.examples.hello.domain.Person;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import com.mongodb.DBCollection;
+import com.mongodb.WriteResult;
+
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
public class SimpleMongoTest {
@Autowired
- MongoTemplate mongoTemplate;
+ MongoOperations operations;
@Before
public void setUp() {
- if (mongoTemplate.getCollectionNames().contains("MyNewCollection")) {
- mongoTemplate.dropCollection("MyNewCollection");
+ if (operations.getCollectionNames().contains("MyNewCollection")) {
+ operations.dropCollection("MyNewCollection");
}
String collectionName = MongoCollectionUtils.getPreferredCollectionName(Person.class);
- if (mongoTemplate.getCollectionNames().contains(collectionName)) {
- mongoTemplate.dropCollection(collectionName);
+ if (operations.getCollectionNames().contains(collectionName)) {
+ operations.dropCollection(collectionName);
}
- mongoTemplate.createCollection(collectionName);
+ operations.createCollection(collectionName);
}
@Test
public void createAndDropCollection() {
- assertFalse(mongoTemplate.getCollectionNames().contains("MyNewCollection"));
+ assertFalse(operations.getCollectionNames().contains("MyNewCollection"));
/* create a new collection */
DBCollection collection = null;
- if (!mongoTemplate.getCollectionNames().contains("MyNewCollection")) {
- collection = mongoTemplate.createCollection("MyNewCollection");
+ if (!operations.getCollectionNames().contains("MyNewCollection")) {
+ collection = operations.createCollection("MyNewCollection");
}
assertNotNull(collection);
- assertTrue(mongoTemplate.getCollectionNames().contains("MyNewCollection"));
+ assertTrue(operations.getCollectionNames().contains("MyNewCollection"));
- mongoTemplate.dropCollection("MyNewCollection");
+ operations.dropCollection("MyNewCollection");
- assertFalse(mongoTemplate.getCollectionNames().contains("MyNewCollection"));
+ assertFalse(operations.getCollectionNames().contains("MyNewCollection"));
}
@Test
public void createAnIndex() {
String collectionName = MongoCollectionUtils.getPreferredCollectionName(Person.class);
- if (!mongoTemplate.getCollectionNames().contains(collectionName)) {
- mongoTemplate.createCollection(collectionName);
+ if (!operations.getCollectionNames().contains(collectionName)) {
+ operations.createCollection(collectionName);
}
- mongoTemplate.ensureIndex(new Index().on("name", Order.ASCENDING), collectionName);
+ operations.ensureIndex(new Index().on("name", Order.ASCENDING), collectionName);
}
@Test
public void saveAndRetrieveDocuments() {
- String collectionName = MongoCollectionUtils.getPreferredCollectionName(Person.class);
+ String collectionName = operations.getCollectionName(Person.class);
Person p = new Person("Bob", 33);
- mongoTemplate.insert(p);
+ operations.insert(p);
- assertEquals(1, mongoTemplate.getCollection(collectionName).count());
+ assertEquals(1, operations.getCollection(collectionName).count());
- Person qp = mongoTemplate.findOne(new Query(where("id").is(p.getId())), Person.class);
+ Person qp = operations.findOne(query(where("id").is(p.getId())), Person.class);
assertNotNull(qp);
assertEquals(p.getName(), qp.getName());
@@ -91,20 +92,20 @@ public void queryingForDocuments() {
Person p1 = new Person("Bob", 33);
p1.addAccount(new Account("198-998-2188", Account.Type.SAVINGS, 123.55d));
- mongoTemplate.insert(p1);
+ operations.insert(p1);
Person p2 = new Person("Mary", 25);
p2.addAccount(new Account("860-98107-681", Account.Type.CHECKING, 400.51d));
- mongoTemplate.insert(p2);
+ operations.insert(p2);
Person p3 = new Person("Chris", 68);
p3.addAccount(new Account("761-002-8901", Account.Type.SAVINGS, 10531.00d));
- mongoTemplate.insert(p3);
+ operations.insert(p3);
Person p4 = new Person("Janet", 33);
p4.addAccount(new Account("719-100-0019", Account.Type.SAVINGS, 1209.10d));
- mongoTemplate.insert(p4);
+ operations.insert(p4);
- assertEquals(4, mongoTemplate.getCollection(collectionName).count());
+ assertEquals(4, operations.getCollection(collectionName).count());
- List<Person> result = mongoTemplate.find(
+ List<Person> result = operations.find(
new Query(where("age").lt(50).and("accounts.balance").gt(1000.00d)),
Person.class);
@@ -115,25 +116,25 @@ public void queryingForDocuments() {
@Test
public void updatingDocuments() {
- String collectionName = MongoCollectionUtils.getPreferredCollectionName(Person.class);
+ String collectionName = operations.getCollectionName(Person.class);
Person p1 = new Person("Bob", 33);
p1.addAccount(new Account("198-998-2188", Account.Type.SAVINGS, 123.55d));
- mongoTemplate.insert(p1);
+ operations.insert(p1);
Person p2 = new Person("Mary", 25);
p2.addAccount(new Account("860-98107-681", Account.Type.CHECKING, 400.51d));
- mongoTemplate.insert(p2);
+ operations.insert(p2);
Person p3 = new Person("Chris", 68);
p3.addAccount(new Account("761-002-8901", Account.Type.SAVINGS, 10531.00d));
- mongoTemplate.insert(p3);
+ operations.insert(p3);
Person p4 = new Person("Janet", 33);
p4.addAccount(new Account("719-100-0019", Account.Type.SAVINGS, 1209.10d));
- mongoTemplate.insert(p4);
+ operations.insert(p4);
- assertEquals(4, mongoTemplate.getCollection(collectionName).count());
+ assertEquals(4, operations.getCollection(collectionName).count());
- WriteResult wr = mongoTemplate.updateMulti(
- query(where("accounts.accountType").is(Account.Type.SAVINGS)),
+ WriteResult wr = operations.updateMulti(
+ query(where("accounts.accountType").is(Account.Type.SAVINGS.name())),
new Update().inc("accounts.$.balance", 50.00),
Person.class);
View
2  ...odb-hello/src/test/resources/org/springframework/data/mongodb/examples/hello/SimpleMongoTest-context.xml
@@ -6,7 +6,7 @@
http://www.springframework.org/schema/data/mongo http://www.springframework.org/schema/data/mongo/spring-mongo-1.0.xsd">
<mongo:db-factory dbname="test"/>
- <bean id="mongoTemplate" class="org.springframework.data.document.mongodb.MongoTemplate">
+ <bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate">
<constructor-arg ref="mongoDbFactory"/>
</bean>
View
8 mongodb-music/pom.xml
@@ -11,10 +11,10 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
- <spring.version>3.0.5.RELEASE</spring.version>
- <spring.data.mongo.version>1.0.0.M3</spring.data.mongo.version>
+ <spring.version>3.0.6.RELEASE</spring.version>
+ <spring.data.mongo.version>1.0.0.M4</spring.data.mongo.version>
<slf4j.version>1.6.1</slf4j.version>
- <querydsl.version>2.2.0-beta4</querydsl.version>
+ <querydsl.version>2.2.1</querydsl.version>
</properties>
<repositories>
@@ -208,7 +208,7 @@
</goals>
<configuration>
<outputDirectory>target/generated-sources/queries</outputDirectory>
- <processor>org.springframework.data.document.mongodb.repository.MongoAnnotationProcessor</processor>
+ <processor>org.springframework.data.mongodb.repository.MongoAnnotationProcessor</processor>
</configuration>
</execution>
</executions>
View
136 mongodb-music/src/main/java/org/springframework/data/mongodb/examples/music/Album.java
@@ -4,7 +4,8 @@
import java.util.List;
import org.bson.types.ObjectId;
-import org.springframework.data.document.mongodb.mapping.Document;
+import org.springframework.data.annotation.Id;
+import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
@@ -17,100 +18,101 @@
@Document
public class Album {
- private ObjectId id;
- private String title;
- private String artist;
- private List<Track> tracks = new ArrayList<Track>();
+ @Id
+ private ObjectId id;
+ private String title;
+ private String artist;
+ private List<Track> tracks = new ArrayList<Track>();
- /**
- * Creates a new {@link Album} with the given title and artist.
- *
- * @param string
- * @param artist
- */
- public Album(String title, String artist) {
+ /**
+ * Creates a new {@link Album} with the given title and artist.
+ *
+ * @param string
+ * @param artist
+ */
+ public Album(String title, String artist) {
- Assert.isTrue(StringUtils.hasText(artist), "Artist name must be given!");
- Assert.isTrue(StringUtils.hasText(title), "Album title must be given!");
+ Assert.isTrue(StringUtils.hasText(artist), "Artist name must be given!");
+ Assert.isTrue(StringUtils.hasText(title), "Album title must be given!");
- this.id = new ObjectId();
- this.title = title;
- this.artist = artist;
- }
+ this.id = new ObjectId();
+ this.title = title;
+ this.artist = artist;
+ }
- public ObjectId getId() {
+ public ObjectId getId() {
- return id;
- }
+ return id;
+ }
- public String getTitle() {
+ public String getTitle() {
- return title;
- }
+ return title;
+ }
- public String getArtist() {
+ public String getArtist() {
- return artist;
- }
+ return artist;
+ }
- public List<Track> getTracks() {
+ public List<Track> getTracks() {
- return tracks;
- }
+ return tracks;
+ }
- /**
- * Adds the given {@link Track} to the {@link Album}.
- *
- * @param track
- */
- public void add(Track track) {
+ /**
+ * Adds the given {@link Track} to the {@link Album}.
+ *
+ * @param track
+ */
+ public void add(Track track) {
- this.tracks.add(track);
- }
+ this.tracks.add(track);
+ }
- /**
- * Returns the number of {@link Track}s contained in the {@link Album}.
- *
- * @return
- */
- public int trackCount() {
+ /**
+ * Returns the number of {@link Track}s contained in the {@link Album}.
+ *
+ * @return
+ */
+ public int trackCount() {
- return this.tracks.size();
- }
+ return this.tracks.size();
+ }
- /* (non-Javadoc)
- * @see java.lang.Object#equals(java.lang.Object)
- */
- @Override
- public boolean equals(Object obj) {
+ /* (non-Javadoc)
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
+ if (this == obj) {
+ return true;
+ }
- if (obj == null || !getClass().equals(obj.getClass())) {
- return false;
- }
+ if (obj == null || !getClass().equals(obj.getClass())) {
+ return false;
+ }
- Album that = (Album) obj;
+ Album that = (Album) obj;
- return id == null ? false : this.id.equals(that.id);
- }
+ return id == null ? false : this.id.equals(that.id);
+ }
- /* (non-Javadoc)
- * @see java.lang.Object#hashCode()
- */
- @Override
- public int hashCode() {
+ /* (non-Javadoc)
+ * @see java.lang.Object#hashCode()
+ */
+ @Override
+ public int hashCode() {
- return 17 + ( id == null ? 0 : id.hashCode());
- }
+ return 17 + ( id == null ? 0 : id.hashCode());
+ }
}
View
280 mongodb-music/src/test/java/org/springframework/data/mongodb/examples/music/AbstractIntegrationTest.java
@@ -11,8 +11,8 @@
import org.junit.Before;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.data.document.mongodb.MongoOperations;
-import org.springframework.data.document.mongodb.query.Query;
+import org.springframework.data.mongodb.core.MongoOperations;
+import org.springframework.data.mongodb.core.query.Query;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@@ -27,147 +27,147 @@
@ContextConfiguration
public abstract class AbstractIntegrationTest {
- static final String COLLECTION = "album";
+ static final String COLLECTION = "album";
- @Autowired
- MongoOperations operations;
+ @Autowired
+ MongoOperations operations;
- Album bigWhiskey;
- Album thePursuit;
+ Album bigWhiskey;
+ Album thePursuit;
- List<Album> albums;
+ List<Album> albums;
- @Before
- public void setUp() {
-
- operations.dropCollection(COLLECTION);
-
- albums = new ArrayList<Album>();
-
- bigWhiskey =
- new Album("Big Whiskey and the Groo Grux King",
- "Dave Matthews Band");
- bigWhiskey.add(new Track(0, "Grux"));
- bigWhiskey.add(new Track(1, "Shake me lika a monkey"));
- bigWhiskey.add(new Track(2, "Funny the way it is"));
- bigWhiskey.add(new Track(3, "Lying in the hands of God"));
- bigWhiskey.add(new Track(4, "Why I am"));
- bigWhiskey.add(new Track(5, "Dive in"));
- bigWhiskey.add(new Track(6, "Spaceman"));
- bigWhiskey.add(new Track(7, "Squirm"));
- bigWhiskey.add(new Track(8, "Alligator pie"));
- bigWhiskey.add(new Track(9, "Seven"));
- bigWhiskey.add(new Track(10, "Time bomb"));
- bigWhiskey.add(new Track(11, "My baby blue"));
- bigWhiskey.add(new Track(12, "You and me"));
-
- albums.add(bigWhiskey);
-
- thePursuit = new Album("The Pursuit", "Jamie Cullum");
- thePursuit.add(new Track(0, "Just one of those things"));
- thePursuit.add(new Track(1, "I'm all over it"));
- thePursuit.add(new Track(2, "Wheels"));
- thePursuit.add(new Track(3, "If I ruled the world"));
- thePursuit.add(new Track(4, "You and me are gone"));
- thePursuit.add(new Track(5, "Don't stop the music"));
- thePursuit.add(new Track(6, "Love ain't gonna let you down"));
- thePursuit.add(new Track(7, "Mixtape"));
- thePursuit.add(new Track(8, "I think, I love"));
- thePursuit.add(new Track(9, "We run things"));
- thePursuit.add(new Track(10, "Not while I am around"));
- thePursuit.add(new Track(11, "Music is through"));
- thePursuit.add(new Track(12, "Grand Torino"));
- thePursuit.add(new Track(13, "Grace is gone"));
-
- albums.add(thePursuit);
- }
-
-
- /**
- * Asserts the given query returns the Groo Grux {@link Album} and only
- * that.
- *
- * @param query
- */
- protected void assertSingleGruxAlbum(Query query) {
-
- List<Album> result = operations.find(query, Album.class, COLLECTION);
-
- assertThat(result, is(notNullValue()));
- assertThat(result.size(), is(1));
-
- assertSingleGruxAlbum(result.get(0));
- }
-
-
- /**
- * Asserts the given {@link Album} is the Groo Grux album.
- *
- * @param album
- */
- protected void assertSingleGruxAlbum(Album album) {
-
- assertThat(album, is(notNullValue()));
- assertThat(album.getId(), is(bigWhiskey.getId()));
- assertThat(album.getTitle(), is("Big Whiskey and the Groo Grux King"));
- assertThat(album.getArtist(), is("Dave Matthews Band"));
- assertThat(album.trackCount(), is(13));
- }
-
-
- /**
- * Asserts the given query returns the Pursuit {@link Album} and only that
- * one.
- *
- * @param query
- */
- protected void assertSinglePursuitAlbum(Query query) {
-
- List<Album> result = operations.find(query, Album.class, COLLECTION);
-
- assertThat(result, is(notNullValue()));
- assertThat(result.size(), is(1));
-
- assertSinglePursuitAlbum(result.get(0));
- }
-
-
- /**
- * Asserts the given {@link Album} is the Pursuit {@link Album}.
- *
- * @param album
- */
- protected void assertSinglePursuitAlbum(Album album) {
-
- assertThat(album, is(notNullValue()));
- assertThat(album.getId(), is(thePursuit.getId()));
- assertThat(album.getTitle(), is("The Pursuit"));
- assertThat(album.getArtist(), is("Jamie Cullum"));
- assertThat(album.trackCount(), is(14));
- }
-
-
- /**
- * Asserts that the given {@link List} of {@link Album} contains 2
- * {@link Album}s, Groo Grux and The Pursuit.
- *
- * @param albums
- */
- protected void assertBothAlbums(List<Album> albums) {
-
- assertThat(albums, is(notNullValue()));
- assertThat(albums.size(), is(2));
-
- for (Album album : albums) {
-
- if (album.getId().equals(bigWhiskey.getId())) {
- assertSingleGruxAlbum(album);
- } else if (album.getId().equals(thePursuit.getId())) {
- assertSinglePursuitAlbum(album);
- } else {
- Assert.fail("Album is neither Grux or Pursuit! ");
- }
- }
- }
+ @Before
+ public void setUp() {
+
+ operations.dropCollection(COLLECTION);
+
+ albums = new ArrayList<Album>();
+
+ bigWhiskey =
+ new Album("Big Whiskey and the Groo Grux King",
+ "Dave Matthews Band");
+ bigWhiskey.add(new Track(0, "Grux"));
+ bigWhiskey.add(new Track(1, "Shake me lika a monkey"));
+ bigWhiskey.add(new Track(2, "Funny the way it is"));
+ bigWhiskey.add(new Track(3, "Lying in the hands of God"));
+ bigWhiskey.add(new Track(4, "Why I am"));
+ bigWhiskey.add(new Track(5, "Dive in"));
+ bigWhiskey.add(new Track(6, "Spaceman"));
+ bigWhiskey.add(new Track(7, "Squirm"));
+ bigWhiskey.add(new Track(8, "Alligator pie"));
+ bigWhiskey.add(new Track(9, "Seven"));
+ bigWhiskey.add(new Track(10, "Time bomb"));
+ bigWhiskey.add(new Track(11, "My baby blue"));
+ bigWhiskey.add(new Track(12, "You and me"));
+
+ albums.add(bigWhiskey);
+
+ thePursuit = new Album("The Pursuit", "Jamie Cullum");
+ thePursuit.add(new Track(0, "Just one of those things"));
+ thePursuit.add(new Track(1, "I'm all over it"));
+ thePursuit.add(new Track(2, "Wheels"));
+ thePursuit.add(new Track(3, "If I ruled the world"));
+ thePursuit.add(new Track(4, "You and me are gone"));
+ thePursuit.add(new Track(5, "Don't stop the music"));
+ thePursuit.add(new Track(6, "Love ain't gonna let you down"));
+ thePursuit.add(new Track(7, "Mixtape"));
+ thePursuit.add(new Track(8, "I think, I love"));
+ thePursuit.add(new Track(9, "We run things"));
+ thePursuit.add(new Track(10, "Not while I am around"));
+ thePursuit.add(new Track(11, "Music is through"));
+ thePursuit.add(new Track(12, "Grand Torino"));
+ thePursuit.add(new Track(13, "Grace is gone"));
+
+ albums.add(thePursuit);
+ }
+
+
+ /**
+ * Asserts the given query returns the Groo Grux {@link Album} and only
+ * that.
+ *
+ * @param query
+ */
+ protected void assertSingleGruxAlbum(Query query) {
+
+ List<Album> result = operations.find(query, Album.class, COLLECTION);
+
+ assertThat(result, is(notNullValue()));
+ assertThat(result.size(), is(1));
+
+ assertSingleGruxAlbum(result.get(0));
+ }
+
+
+ /**
+ * Asserts the given {@link Album} is the Groo Grux album.
+ *
+ * @param album
+ */
+ protected void assertSingleGruxAlbum(Album album) {
+
+ assertThat(album, is(notNullValue()));
+ assertThat(album.getId(), is(bigWhiskey.getId()));
+ assertThat(album.getTitle(), is("Big Whiskey and the Groo Grux King"));
+ assertThat(album.getArtist(), is("Dave Matthews Band"));
+ assertThat(album.trackCount(), is(13));
+ }
+
+
+ /**
+ * Asserts the given query returns the Pursuit {@link Album} and only that
+ * one.
+ *
+ * @param query
+ */
+ protected void assertSinglePursuitAlbum(Query query) {
+
+ List<Album> result = operations.find(query, Album.class, COLLECTION);
+
+ assertThat(result, is(notNullValue()));
+ assertThat(result.size(), is(1));
+
+ assertSinglePursuitAlbum(result.get(0));
+ }
+
+
+ /**
+ * Asserts the given {@link Album} is the Pursuit {@link Album}.
+ *
+ * @param album
+ */
+ protected void assertSinglePursuitAlbum(Album album) {
+
+ assertThat(album, is(notNullValue()));
+ assertThat(album.getId(), is(thePursuit.getId()));
+ assertThat(album.getTitle(), is("The Pursuit"));
+ assertThat(album.getArtist(), is("Jamie Cullum"));
+ assertThat(album.trackCount(), is(14));
+ }
+
+
+ /**
+ * Asserts that the given {@link List} of {@link Album} contains 2
+ * {@link Album}s, Groo Grux and The Pursuit.
+ *
+ * @param albums
+ */
+ protected void assertBothAlbums(List<Album> albums) {
+
+ assertThat(albums, is(notNullValue()));
+ assertThat(albums.size(), is(2));
+
+ for (Album album : albums) {
+
+ if (album.getId().equals(bigWhiskey.getId())) {
+ assertSingleGruxAlbum(album);
+ } else if (album.getId().equals(thePursuit.getId())) {
+ assertSinglePursuitAlbum(album);
+ } else {
+ Assert.fail("Album is neither Grux or Pursuit! ");
+ }
+ }
+ }
}
View
80 ...-music/src/test/java/org/springframework/data/mongodb/examples/music/AlbumRepositoryIntegrationTest.java
@@ -20,62 +20,62 @@
@ContextConfiguration
public class AlbumRepositoryIntegrationTest extends AbstractIntegrationTest {
- @Autowired
- AlbumRepository repository;
+ @Autowired
+ AlbumRepository repository;
- @Before
- public void purgeRepository() {
- repository.deleteAll();
- super.setUp();
- }
+ @Before
+ public void purgeRepository() {
+ repository.deleteAll();
+ super.setUp();
+ }
- @Test
- public void createAlbum() throws Exception {
+ @Test
+ public void createAlbum() throws Exception {
- repository.save(albums);
- assertSingleGruxAlbum(repository.findOne(bigWhiskey.getId()));
- }
+ repository.save(albums);
+ assertSingleGruxAlbum(repository.findOne(bigWhiskey.getId()));
+ }
- @Test
- public void findsAlbumByConcreteTrackName() throws Exception {
+ @Test
+ public void findsAlbumByConcreteTrackName() throws Exception {
- repository.save(albums);
- assertSingleGruxAlbum(repository.findByTracksName("Grux"));
+ repository.save(albums);
+ assertSingleGruxAlbum(repository.findByTracksName("Grux"));
- List<Album> albums = repository.findByTracksName("Foo");
- assertThat(albums.isEmpty(), is(true));
- }
+ List<Album> albums = repository.findByTracksName("Foo");
+ assertThat(albums.isEmpty(), is(true));
+ }
- @Test
- public void findsAllAlbumsByTrackNameLike() throws Exception {
+ @Test
+ public void findsAllAlbumsByTrackNameLike() throws Exception {
- repository.save(albums);
- assertBothAlbums(repository.findByTracksNameLike("*it*"));
- }
+ repository.save(albums);
+ assertBothAlbums(repository.findByTracksNameLike("*it*"));
+ }
- @Test
- public void findsAlbumsByTrackRating() throws Exception {
+ @Test
+ public void findsAlbumsByTrackRating() throws Exception {
- bigWhiskey.getTracks().get(4).setRating(Stars.FOUR);
- repository.save(albums);
+ bigWhiskey.getTracks().get(4).setRating(Stars.FOUR);
+ repository.save(albums);
- assertSingleGruxAlbum(repository
- .findByTracksRatingGreaterThan(Stars.THREE));
+ assertSingleGruxAlbum(repository
+ .findByTracksRatingGreaterThan(Stars.THREE));
- List<Album> albums =
- repository.findByTracksRatingGreaterThan(Stars.FOUR);
- assertThat(albums.isEmpty(), is(true));
- }
+ List<Album> albums =
+ repository.findByTracksRatingGreaterThan(Stars.FOUR);
+ assertThat(albums.isEmpty(), is(true));
+ }
- private void assertSingleGruxAlbum(List<Album> albums) {
+ private void assertSingleGruxAlbum(List<Album> albums) {
- assertThat(albums, is(notNullValue()));
- assertThat(albums.size(), is(1));
- assertThat(albums.get(0), is(notNullValue(Album.class)));
- assertSingleGruxAlbum(albums.get(0));
- }
+ assertThat(albums, is(notNullValue()));
+ assertThat(albums.size(), is(1));
+ assertThat(albums.get(0), is(notNullValue(Album.class)));
+ assertSingleGruxAlbum(albums.get(0));
+ }
}
View
100 mongodb-music/src/test/java/org/springframework/data/mongodb/examples/music/AlbumsIntegrationTest.java
@@ -1,12 +1,12 @@
package org.springframework.data.mongodb.examples.music;
-import static org.springframework.data.document.mongodb.query.Criteria.*;
+import static org.springframework.data.mongodb.core.query.Criteria.*;
import org.junit.Test;
-import org.springframework.data.document.mongodb.MongoOperations;
-import org.springframework.data.document.mongodb.MongoTemplate;
-import org.springframework.data.document.mongodb.query.BasicQuery;
-import org.springframework.data.document.mongodb.query.Query;
+import org.springframework.data.mongodb.core.MongoOperations;
+import org.springframework.data.mongodb.core.MongoTemplate;
+import org.springframework.data.mongodb.core.query.BasicQuery;
+import org.springframework.data.mongodb.core.query.Query;
/**
@@ -17,71 +17,71 @@
*/
public class AlbumsIntegrationTest extends AbstractIntegrationTest {
- /*
- * (non-Javadoc)
- *
- * @see
- * org.springframework.data.mongodb.examples.music.AbstractIntegrationTests
- * #setUp()
- */
- @Override
- public void setUp() {
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.springframework.data.mongodb.core.core.examples.music.AbstractIntegrationTests
+ * #setUp()
+ */
+ @Override
+ public void setUp() {
- super.setUp();
+ super.setUp();
- // Stores both albums
- operations.insert(albums, COLLECTION);
- }
+ // Stores both albums
+ operations.insertAll(albums);
+ }
- @Test
- public void lookupAlbumByIdWithQueryBuilder() throws Exception {
+ @Test
+ public void lookupAlbumByIdWithQueryBuilder() throws Exception {
- Query build =
- new Query(where("_id").is(bigWhiskey.getId()));
+ Query build =
+ new Query(where("_id").is(bigWhiskey.getId()));
- assertSingleGruxAlbum(build);
- }
+ assertSingleGruxAlbum(build);
+ }
- @Test
- public void lookupAlbumByIdUsingJson() throws Exception {
+ @Test
+ public void lookupAlbumByIdUsingJson() throws Exception {
- Query query =
- parseQuery("{'_id' : { '$oid' : '%s' }}", bigWhiskey.getId());
- assertSingleGruxAlbum(query);
- }
+ Query query =
+ parseQuery("{'_id' : { '$oid' : '%s' }}", bigWhiskey.getId());
+ assertSingleGruxAlbum(query);
+ }
- @Test
- public void lookupAlbumsByTrackNameUsingJson() throws Exception {
+ @Test
+ public void lookupAlbumsByTrackNameUsingJson() throws Exception {
- Query query = parseQuery("{'tracks.name' : 'Wheels'}");
- assertSinglePursuitAlbum(query);
- }
+ Query query = parseQuery("{'tracks.name' : 'Wheels'}");
+ assertSinglePursuitAlbum(query);
+ }
- @Test
- public void lookupAlbumByTrackNameUsingQueryBuilder() {
+ @Test
+ public void lookupAlbumByTrackNameUsingQueryBuilder() {
- Query spec =
- new Query(where("tracks.name").is("Grux"));
- assertSingleGruxAlbum(spec);
- }
+ Query spec =
+ new Query(where("tracks.name").is("Grux"));
+ assertSingleGruxAlbum(spec);
+ }
- @Test
- public void lookupAlbumByTrackNamePattern() throws Exception {
+ @Test
+ public void lookupAlbumByTrackNamePattern() throws Exception {
- Query query =
- parseQuery("{ 'tracks.name' : { '$regex' : '.*it.*' , '$options' : '' }}");
- assertBothAlbums(operations.find(query, Album.class, COLLECTION));
- }
+ Query query =
+ parseQuery("{ 'tracks.name' : { '$regex' : '.*it.*' , '$options' : '' }}");
+ assertBothAlbums(operations.find(query, Album.class, COLLECTION));
+ }
- private Query parseQuery(String query, Object... arguments) {
+ private Query parseQuery(String query, Object... arguments) {
- return new BasicQuery(String.format(query, arguments));
- }
+ return new BasicQuery(String.format(query, arguments));
+ }
}
View
23 mongodb-music/src/test/java/org/springframework/data/mongodb/examples/music/QueryDslIntegrationTests.java
@@ -1,5 +1,6 @@
package org.springframework.data.mongodb.examples.music;
+import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
@@ -13,15 +14,21 @@
@ContextConfiguration
public class QueryDslIntegrationTests extends AbstractIntegrationTest {
- @Autowired
- AlbumRepository repository;
+ @Autowired
+ AlbumRepository repository;
- QAlbum album = QAlbum.album;
+ QAlbum album = QAlbum.album;
- @Test
- public void testname() {
+ @Override
+ @Before
+ public void setUp() {
+ repository.deleteAll();
+ }
- repository.save(albums);
- assertSinglePursuitAlbum(repository.findOne(album.title.eq("The Pursuit")));
- }
+ @Test
+ public void invokesQuerydslPredicateCorrectly() {
+
+ repository.save(albums);
+ assertSinglePursuitAlbum(repository.findOne(album.title.eq("The Pursuit")));
+ }
}
View
2  ...c/src/test/resources/org/springframework/data/mongodb/examples/music/AbstractIntegrationTest-context.xml
@@ -8,7 +8,7 @@
<!-- Sets up a Mongo DB instance. Configure host, port and credentials if needed. -->
<mongo:db-factory dbname="music"/>
- <bean id="mongoTemplate" class="org.springframework.data.document.mongodb.MongoTemplate">
+ <bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate">
<constructor-arg ref="mongoDbFactory" />
</bean>
View
2  .../src/test/resources/org/springframework/data/mongodb/examples/music/QueryDslIntegrationTests-context.xml
@@ -11,6 +11,6 @@
in AlbumRepository e.g. The repository support will use the bean called
'mongoTemplate' by default. Use 'mongo-template-ref' attribute to customize.
-->
- <mongo:repositories base-package="org.springframework.data.mongodb.examples.music" />
+ <mongo:repositories base-package="org.springframework.data.mongodb.core.core.examples.music" />
</beans>
View
20 mongodb-myrestaurants-analytics/src/main/java/com/springone/myrestaurants/config/MongoConfiguration.java
@@ -1,25 +1,29 @@
package com.springone.myrestaurants.config;
-import com.mongodb.Mongo;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
+import org.springframework.data.document.mongodb.MongoOperations;
import org.springframework.data.document.mongodb.MongoTemplate;
import org.springframework.data.document.mongodb.SimpleMongoDbFactory;
+import com.mongodb.Mongo;
+
@Configuration
public class MongoConfiguration {
@Bean
- public MongoTemplate mongoTemplate() throws Exception {
+ public MongoOperations mongoTemplate() throws Exception {
Mongo m = new Mongo();
- MongoTemplate mongoTemplate = new MongoTemplate(new SimpleMongoDbFactory(m, "mvc"));
- if (!mongoTemplate.collectionExists("mvc")) {
- mongoTemplate.createCollection("mvc");
+ MongoOperations operations = new MongoTemplate(new SimpleMongoDbFactory(m, "mvc"));
+
+ if (!operations.collectionExists("mvc")) {
+ operations.createCollection("mvc");
}
- if (!mongoTemplate.collectionExists("counters")) {
- mongoTemplate.createCollection("counters");
+ if (!operations.collectionExists("counters")) {
+ operations.createCollection("counters");
}
- return mongoTemplate;
+
+ return operations;
}
}
View
110 mongodb-myrestaurants-analytics/src/main/webapp/WEB-INF/web.xml~
@@ -1,110 +0,0 @@
-<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
-<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.4" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
-
-
- <display-name>myrestaurants-original</display-name>
-
- <description>Roo generated myrestaurants application</description>
-
-
- <!-- Enable escaping of form submission contents -->
- <context-param>
- <param-name>defaultHtmlEscape</param-name>
- <param-value>true</param-value>
- </context-param>
-
- <context-param>
- <param-name>contextConfigLocation</param-name>
- <param-value>classpath*:META-INF/spring/applicationContext*.xml</param-value>
- </context-param>
-
- <filter>
- <filter-name>Spring OpenEntityManagerInViewFilter</filter-name>
- <filter-class>org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter</filter-class>
- </filter>
-
-
-
-
-
- <filter>
- <filter-name>springSecurityFilterChain</filter-name>
- <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
- </filter>
- <filter>
- <filter-name>CharacterEncodingFilter</filter-name>
- <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
- <init-param>
- <param-name>encoding</param-name>
- <param-value>UTF-8</param-value>
- </init-param>
- <init-param>
- <param-name>forceEncoding</param-name>
- <param-value>true</param-value>
- </init-param>
- </filter>
-
- <filter>
- <filter-name>HttpMethodFilter</filter-name>
- <filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class>
- </filter>
- <filter-mapping>
- <filter-name>Spring OpenEntityManagerInViewFilter</filter-name>
- <url-pattern>/*</url-pattern>
- </filter-mapping>
-
-
-
- <filter-mapping>
- <filter-name>springSecurityFilterChain</filter-name>
- <url-pattern>/*</url-pattern>
- </filter-mapping>
- <filter-mapping>
- <filter-name>CharacterEncodingFilter</filter-name>
- <url-pattern>/*</url-pattern>
- </filter-mapping>
-
- <filter-mapping>
- <filter-name>HttpMethodFilter</filter-name>
- <url-pattern>/*</url-pattern>
- </filter-mapping>
-
- <!-- Creates the Spring Container shared by all Servlets and Filters -->
- <listener>
- <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
- </listener>
-
- <!-- Handles Spring requests -->
- <servlet>
- <servlet-name>myrestaurants</servlet-name>
- <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
- <init-param>
- <param-name>contextConfigLocation</param-name>
- <param-value>/WEB-INF/spring/webmvc-config.xml</param-value>
- </init-param>
- <load-on-startup>1</load-on-startup>
- </servlet>
-
- <servlet-mapping>
- <servlet-name>myrestaurants</servlet-name>
- <url-pattern>/</url-pattern>
- </servlet-mapping>
-
- <session-config>
- <session-timeout>10</session-timeout>
- </session-config>
-
- <welcome-file-list>
- <welcome-file>/</welcome-file>
- </welcome-file-list>
-
- <error-page>
- <exception-type>java.lang.Exception</exception-type>
- <location>/uncaughtException</location>
- </error-page>
-
- <error-page>
- <error-code>404</error-code>
- <location>/resourceNotFound</location>
- </error-page>
-</web-app>
View
75 ...urants-analytics/src/test/java/org/springframework/data/document/mongodb/analytics/MvcAnalyticsTest.java
@@ -10,6 +10,7 @@
import org.springframework.data.document.analytics.ControllerCounter;
import org.springframework.data.document.analytics.MvcEvent;
import org.springframework.data.document.analytics.Parameters;
+import org.springframework.data.document.mongodb.MongoOperations;
import org.springframework.data.document.mongodb.MongoTemplate;
import org.springframework.data.document.mongodb.query.BasicQuery;
@@ -23,37 +24,37 @@
public class MvcAnalyticsTest {
- private MongoTemplate mongoTemplate;
+ MongoOperations operations;
@Before
public void setUp() throws Exception {
Mongo m = new Mongo();
- mongoTemplate = new MongoTemplate(m, "mvc");
+ operations = new MongoTemplate(m, "mvc");
}
@Test
public void clean() {
- mongoTemplate.dropCollection("mvc");
- mongoTemplate.createCollection("mvc");
- mongoTemplate.dropCollection("counters");
- mongoTemplate.createCollection("counters");
+ operations.dropCollection("mvc");
+ operations.createCollection("mvc");
+ operations.dropCollection("counters");
+ operations.createCollection("counters");
}
@Test
public void loadMvcEventData() {
- mongoTemplate.dropCollection("mvc");
- mongoTemplate.createCollection("mvc");
+ operations.dropCollection("mvc");
+ operations.createCollection("mvc");
// datasize, favoriteRestId
createAndStoreMvcEvent(5, 1);
createAndStoreMvcEvent(6, 2);
createAndStoreMvcEvent(3, 3);
createAndStoreMvcEvent(8, 4);
- List<MvcEvent> mvcEvents = mongoTemplate.findAll(MvcEvent.class, "mvc");
+ List<MvcEvent> mvcEvents = operations.findAll(MvcEvent.class, "mvc");
Assert.assertEquals(22, mvcEvents.size());
- mongoTemplate.findAll(MvcEvent.class, "mvc");
+ operations.findAll(MvcEvent.class, "mvc");
}
@@ -75,11 +76,11 @@ public void loadCounterData() {
@Test
public void queryCounterData() {
DBObject query = QueryBuilder.start("name").is("SignUpController").get();
- for (DBObject dbo : mongoTemplate.getCollection("counters").find(query)) {
+ for (DBObject dbo : operations.getCollection("counters").find(query)) {
System.out.println(dbo);
}
- List<ControllerCounter> counters = mongoTemplate.find(
- new BasicQuery("{ 'name' : 'SignUpController'} "),
+ List<ControllerCounter> counters = operations.find(
+ new BasicQuery("{ 'name' : 'SignUpController'} "),
ControllerCounter.class,
"counters");
for (ControllerCounter controllerCounter : counters) {
@@ -88,16 +89,16 @@ public void queryCounterData() {
}
/*
- *
- * var start = new Date(2010,9,1); var end = new Date(2010,11,1);
- * db.mvc.group( { cond: {"action": "addFavoriteRestaurant", "date": {$gte:
- * start, $lt: end}} , key: {"parameters.p1": true} , initial: {count: 0} ,
- * reduce: function(doc, out){ out.count++; } } );
- */
+ *
+ * var start = new Date(2010,9,1); var end = new Date(2010,11,1);
+ * db.mvc.group( { cond: {"action": "addFavoriteRestaurant", "date": {$gte:
+ * start, $lt: end}} , key: {"parameters.p1": true} , initial: {count: 0} ,
+ * reduce: function(doc, out){ out.count++; } } );
+ */
@Test
public void listAllMvcEvents() {
- List<MvcEvent> mvcEvents = mongoTemplate.findAll(MvcEvent.class, "mvc");
+ List<MvcEvent> mvcEvents = operations.findAll(MvcEvent.class, "mvc");
for (MvcEvent mvcEvent : mvcEvents) {
System.out.println(mvcEvent.getDate());
}
@@ -106,7 +107,7 @@ public void listAllMvcEvents() {
@Test
public void groupQuery() {
// This circumvents exception translation
- DBCollection collection = mongoTemplate.getDb().getCollection("mvc");
+ DBCollection collection = operations.getCollection("mvc");
// QueryBuilder qb = new QueryBuilder();
// qb.start("date").greaterThan(object)
@@ -120,21 +121,21 @@ public void groupQuery() {
endDate.set(Calendar.MONTH, 12);
/*
- * QueryBuilder qb = new QueryBuilder(); Query q =
- * qb.find("date").gte(startDate
- * .getTime()).lt(endDate.getTime()).and("action"
- * ).is("addFavoriteRestaurant").build(); DBObject cond2 =
- * q.getQueryObject();
- */
+ * QueryBuilder qb = new QueryBuilder(); Query q =
+ * qb.find("date").gte(startDate
+ * .getTime()).lt(endDate.getTime()).and("action"
+ * ).is("addFavoriteRestaurant").build(); DBObject cond2 =
+ * q.getQueryObject();
+ */
DBObject cond = QueryBuilder.start("date").greaterThanEquals(startDate.getTime()).lessThan(endDate.getTime())
.and("action").is("addFavoriteRestaurant").get();
DBObject key = new BasicDBObject("parameters.p1", true);
/*
- * DBObject dateQ = new BasicDBObject(); dateQ.put("$gte",
- * startDate.getTime()); dateQ.put("$lt", endDate.getTime()); DBObject
- * cond = new BasicDBObject(); cond.put("action",
- * "addFavoriteRestaurant"); cond.put("date", dateQ);
- */
+ * DBObject dateQ = new BasicDBObject(); dateQ.put("$gte",
+ * startDate.getTime()); dateQ.put("$lt", endDate.getTime()); DBObject
+ * cond = new BasicDBObject(); cond.put("action",
+ * "addFavoriteRestaurant"); cond.put("date", dateQ);
+ */
DBObject intitial = new BasicDBObject("count", 0);
DBObject result = collection.group(key, cond, intitial, "function(doc, out){ out.count++; }");
@@ -162,7 +163,7 @@ public void storeControllerCounterInfo() {
// /mongoTemplate.update(collection("counters")
- WriteResult r = mongoTemplate.getCollection("counters").update(query, changes, true, false);
+ WriteResult r = operations.getCollection("counters").update(query, changes, true, false);
// { "err" : "Modifiers and non-modifiers cannot be mixed" , "code" : 10154 , "n" : 0 , "ok" : 1.0}
// { "err" : null , "updatedExisting" : false , "upserted" : { "$oid" : "4cba814a5a4900000000495d"} , "n" : 1 , "ok"
// : 1.0}
@@ -178,7 +179,7 @@ public void storeControllerCounterInfo() {
public void updateMethodCounter() {
DBObject query = new BasicDBObject("name", "controller1");
DBObject changes = new BasicDBObject("$inc", new BasicDBObject("methods.find", 1));
- mongoTemplate.getDb().getCollection("counters").update(query, changes, true, false);
+ operations.getCollection("counters").update(query, changes, true, false);
}
public void storeCounterData(String controllerName, String methodName) {
@@ -188,18 +189,18 @@ public void storeCounterData(String controllerName, String methodName) {
changes.put("$set", new BasicDBObject("name", controllerName));
changes.put("$inc", new BasicDBObject("count", 1));
- WriteResult r = mongoTemplate.getCollection("counters").update(query, changes, true, false);
+ WriteResult r = operations.getCollection("counters").update(query, changes, true, false);
System.out.println(r);
changes = new BasicDBObject("$inc", new BasicDBObject("methods." + methodName, 1));
- r = mongoTemplate.getDb().getCollection("counters").update(query, changes, true, false);
+ r = operations.getCollection("counters").update(query, changes, true, false);
System.out.println(r);
}
private void createAndStoreMvcEvent(int dataSize, int p1) {
for (int i = 0; i < dataSize; i++) {
MvcEvent event = generateEvent(p1);
- mongoTemplate.save(event, "mvc");
+ operations.save(event, "mvc");
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.