diff --git a/src/docbkx/reference/cross-store.xml b/src/docbkx/reference/cross-store.xml index a200a28c2..50d945262 100644 --- a/src/docbkx/reference/cross-store.xml +++ b/src/docbkx/reference/cross-store.xml @@ -150,13 +150,13 @@ <!-- Mongo config --> <mongo:mongo host="localhost" port="27017"/> - <bean id="mongoTemplate" class="org.springframework.data.document.mongodb.MongoTemplate"> + <bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate"> <constructor-arg name="mongo" ref="mongo"/> <constructor-arg name="databaseName" value="test"/> <constructor-arg name="defaultCollectionName" value="cross-store"/> </bean> - <bean class="org.springframework.data.document.mongodb.MongoExceptionTranslator"/> + <bean class="org.springframework.data.mongodb.core.MongoExceptionTranslator"/> <!-- Mongo cross-store aspect config --> <bean class="org.springframework.data.persistence.document.mongo.MongoDocumentBacking" diff --git a/src/docbkx/reference/mapping.xml b/src/docbkx/reference/mapping.xml index e023ca77e..bcb538ba0 100644 --- a/src/docbkx/reference/mapping.xml +++ b/src/docbkx/reference/mapping.xml @@ -174,8 +174,8 @@ public class GeoSpatialAppConfig extends AbstractMongoConfiguration { @Override protected void afterMappingMongoConverterCreation(MappingMongoConverter converter) { Set<Converter<?, ?>> converterList = new HashSet<Converter<?, ?>>(); - converterList.add(new org.springframework.data.document.mongodb.PersonReadConverter()); - converterList.add(new org.springframework.data.document.mongodb.PersonWriteConverter()); + converterList.add(new org.springframework.data.mongodb.test.PersonReadConverter()); + converterList.add(new org.springframework.data.mongodb.test.PersonWriteConverter()); converter.setCustomConverters(converterList); } @@ -193,7 +193,7 @@ public class GeoSpatialAppConfig extends AbstractMongoConfiguration { AbstractMongoConfiguration also has a method you can override named 'getMappingBasePackage' which tells the converter where to scan for classes annotated with the - @org.springframework.data.document.mongodb.mapping.Document + @org.springframework.data.mongodb.core.mapping.Document annotation. You can add additional converters to the converter by overriding the @@ -237,20 +237,20 @@ public class GeoSpatialAppConfig extends AbstractMongoConfiguration { <mongo:custom-converters> <mongo:converter ref="readConverter"/> <mongo:converter> - <bean class="org.springframework.data.document.mongodb.PersonWriteConverter"/> + <bean class="org.springframework.data.mongodb.test.PersonWriteConverter"/> </mongo:converter> </mongo:custom-converters> </mongo:mapping-converter> - <bean id="readConverter" class="org.springframework.data.document.mongodb.PersonReadConverter"/> + <bean id="readConverter" class="org.springframework.data.mongodb.test.PersonReadConverter"/> <!-- set the mapping converter to be used by the MongoTemplate --> - <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"/> <constructor-arg name="mongoConverter" ref="mappingConverter"/> </bean> - <bean class="org.springframework.data.document.mongodb.mapping.event.LoggingEventListener"/> + <bean class="org.springframework.data.mongodb.core.mapping.event.LoggingEventListener"/> </beans @@ -258,7 +258,7 @@ public class GeoSpatialAppConfig extends AbstractMongoConfiguration { The base-package property tells it where to scan for classes annotated with the - @org.springframework.data.document.mongodb.mapping.Document + @org.springframework.data.mongodb.core.mapping.Document annotation. @@ -268,7 +268,7 @@ public class GeoSpatialAppConfig extends AbstractMongoConfiguration { To take full advantage of the object mapping functionality inside the Spring Data/MongoDB support, you should annotate your mapped objects with the - @org.springframework.data.document.mongodb.mapping.Document + @org.springframework.data.mongodb.core.mapping.Document annotation. Although it is not necessary for the mapping framework to have this annotation (your POJOs will be mapped correctly, even without any annotations), it allows the classpath scanner to find and pre-process your diff --git a/src/docbkx/reference/mongo-repositories.xml b/src/docbkx/reference/mongo-repositories.xml index 7d2b279dd..2102098f4 100644 --- a/src/docbkx/reference/mongo-repositories.xml +++ b/src/docbkx/reference/mongo-repositories.xml @@ -73,7 +73,7 @@ <mongo:mongo id="mongo" /> - <bean id="mongoTemplate" class="org.springframework.data.document.mongodb.MongoTemplate"> + <bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate"> <constructor-arg ref="mongo" /> <constructor-arg value="databaseName" /> </bean> @@ -349,7 +349,7 @@ Distance distance = new Distance(200, Metrics.KILOMETERS); Mongo JSON based query methods and field restriction By adding the annotation - org.springframework.data.document.mongodb.repository.Query + org.springframework.data.mongodb.repository.Query repository finder methods you can specify a Mongo JSON query string to use instead of having the query derived from the method name. For example diff --git a/src/docbkx/reference/mongodb.xml b/src/docbkx/reference/mongodb.xml index 926b295d1..6298aa4c3 100644 --- a/src/docbkx/reference/mongodb.xml +++ b/src/docbkx/reference/mongodb.xml @@ -81,7 +81,7 @@ Getting Started Spring MongoDB support requires MongoDB 1.4 or higher and Java SE 5 - or higher. The latest production release (1.8.x as of this writing) is + or higher. The latest production release (2.0.x as of this writing) is recommended. An easy way to bootstrap setting up a working environment is to create a Spring based project in STS. @@ -106,7 +106,7 @@ <dependency> <groupId>org.springframework.data</groupId> <artifactId>spring-data-mongodb</artifactId> - <version>1.0.0.M4</version> + <version>1.0.0.M5</version> </dependency> </dependencies> @@ -174,13 +174,13 @@ public class Person { package org.spring.mongodb.example; -import static org.springframework.data.document.mongodb.query.Criteria.where; +import static org.springframework.data.mongodb.core.query.Criteria.where; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.springframework.data.document.mongodb.MongoOperations; -import org.springframework.data.document.mongodb.MongoTemplate; -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.Query; import com.mongodb.Mongo; @@ -203,10 +203,10 @@ public class MongoApp { This will produce the following output 10:01:32,062 DEBUG apping.MongoPersistentEntityIndexCreator: 80 - Analyzing class class org.spring.example.Person for index information. -10:01:32,265 DEBUG work.data.document.mongodb.MongoTemplate: 631 - insert DBObject containing fields: [_class, age, name] in collection: Person -10:01:32,765 DEBUG work.data.document.mongodb.MongoTemplate:1243 - findOne using query: { "name" : "Joe"} in db.collection: database.Person +10:01:32,265 DEBUG work.data.mongodb.core.MongoTemplate: 631 - insert DBObject containing fields: [_class, age, name] in collection: Person +10:01:32,765 DEBUG work.data.mongodb.core.MongoTemplate:1243 - findOne using query: { "name" : "Joe"} in db.collection: database.Person 10:01:32,953 INFO org.spring.mongodb.example.MongoApp: 25 - Person [id=4ddbba3c0be56b7e1b210166, name=Joe, age=34] -10:01:32,984 DEBUG work.data.document.mongodb.MongoTemplate: 375 - Dropped collection [database.person] +10:01:32,984 DEBUG work.data.mongodb.core.MongoTemplate: 375 - Dropped collection [database.person] Even in this simple example, there are few things to take notice of @@ -535,7 +535,7 @@ public class AppConfig { username and password. With that information you can obtain a com.mongodb.DB object and access all the functionality of a specific MongoDB database instance. Spring provides the - org.springframework.data.document.mongodb.MongoDbFactory + org.springframework.data.mongodb.core.MongoDbFactory interface shown below to bootstrap connectivity to the database. public interface MongoDbFactory { @@ -553,7 +553,7 @@ public class AppConfig { MongoTemplate. The class - org.springframework.data.document.mongodb.SimpleMongoDbFactory + org.springframework.data.mongodb.core.SimpleMongoDbFactory provides implements the MongoDbFactory interface and is created with a standard com.mongodb.Mongo instance, the database name and an optional @@ -681,7 +681,7 @@ public class MongoConfiguration { <mongo:db-factory dbname="database" mongo-ref="mongo"/> -<bean id="anotherMongoTemplate" class="org.springframework.data.document.mongodb.MongoTemplate"> +<bean id="anotherMongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate"> <constructor-arg name="mongoDbFactory" ref="mongoDbFactory"/> </bean> @@ -832,7 +832,7 @@ public class AppConfig { <mongo:mongo host="localhost" port="27017"/> - <bean id="mongoTemplate" class="org.springframework.data.document.mongodb.MongoTemplate"> + <bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate"> <constructor-arg ref="mongo"/> <constructor-arg name="databaseName" value="geospatial"/> </bean> @@ -933,17 +933,17 @@ public class AppConfig { package org.spring.example; -import static org.springframework.data.document.mongodb.query.Criteria.where; -import static org.springframework.data.document.mongodb.query.Update.update; -import static org.springframework.data.document.mongodb.query.Query.query; +import static org.springframework.data.mongodb.core.query.Criteria.where; +import static org.springframework.data.mongodb.core.query.Update.update; +import static org.springframework.data.mongodb.core.query.Query.query; import java.util.List; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.springframework.data.document.mongodb.MongoOperations; -import org.springframework.data.document.mongodb.MongoTemplate; -import org.springframework.data.document.mongodb.SimpleMongoDbFactory; +import org.springframework.data.mongodb.core.MongoOperations; +import org.springframework.data.mongodb.core.MongoTemplate; +import org.springframework.data.mongodb.core.SimpleMongoDbFactory; import com.mongodb.Mongo; @@ -987,16 +987,16 @@ public class MongoApp { messages from MongoTemplate itself) DEBUG apping.MongoPersistentEntityIndexCreator: 80 - Analyzing class class org.spring.example.Person for index information. -DEBUG work.data.document.mongodb.MongoTemplate: 632 - insert DBObject containing fields: [_class, age, name] in collection: person +DEBUG work.data.mongodb.core.MongoTemplate: 632 - insert DBObject containing fields: [_class, age, name] in collection: person INFO org.spring.example.MongoApp: 30 - Insert: Person [id=4ddc6e784ce5b1eba3ceaf5c, name=Joe, age=34] -DEBUG work.data.document.mongodb.MongoTemplate:1246 - findOne using query: { "_id" : { "$oid" : "4ddc6e784ce5b1eba3ceaf5c"}} in db.collection: database.person +DEBUG work.data.mongodb.core.MongoTemplate:1246 - findOne using query: { "_id" : { "$oid" : "4ddc6e784ce5b1eba3ceaf5c"}} in db.collection: database.person INFO org.spring.example.MongoApp: 34 - Found: Person [id=4ddc6e784ce5b1eba3ceaf5c, name=Joe, age=34] -DEBUG work.data.document.mongodb.MongoTemplate: 778 - calling update using query: { "name" : "Joe"} and update: { "$set" : { "age" : 35}} in collection: person -DEBUG work.data.document.mongodb.MongoTemplate:1246 - findOne using query: { "name" : "Joe"} in db.collection: database.person +DEBUG work.data.mongodb.core.MongoTemplate: 778 - calling update using query: { "name" : "Joe"} and update: { "$set" : { "age" : 35}} in collection: person +DEBUG work.data.mongodb.core.MongoTemplate:1246 - findOne using query: { "name" : "Joe"} in db.collection: database.person INFO org.spring.example.MongoApp: 39 - Updated: Person [id=4ddc6e784ce5b1eba3ceaf5c, name=Joe, age=35] -DEBUG work.data.document.mongodb.MongoTemplate: 823 - remove using query: { "id" : "4ddc6e784ce5b1eba3ceaf5c"} in collection: person +DEBUG work.data.mongodb.core.MongoTemplate: 823 - remove using query: { "id" : "4ddc6e784ce5b1eba3ceaf5c"} in collection: person INFO org.spring.example.MongoApp: 46 - Number of people = : 0 -DEBUG work.data.document.mongodb.MongoTemplate: 376 - Dropped collection [database.person] +DEBUG work.data.mongodb.core.MongoTemplate: 376 - Dropped collection [database.person] There was implicit conversion using the MongoConverter between a String and ObjectId as stored in the database and recognizing a convention @@ -1108,8 +1108,8 @@ DEBUG work.data.document.mongodb.MongoTemplate: 376 - Dropped collection [databa Inserting and retrieving documents using the MongoTemplate - import static org.springframework.data.document.mongodb.query.Criteria.where; -import static org.springframework.data.document.mongodb.query.Criteria.query; + import static org.springframework.data.mongodb.core.query.Criteria.where; +import static org.springframework.data.mongodb.core.query.Criteria.query; ... @@ -1227,9 +1227,9 @@ import static org.springframework.data.document.mongodb.query.Criteria.query; Updating documents using the MongoTemplate - import static org.springframework.data.document.mongodb.query.Criteria.where; -import static org.springframework.data.document.mongodb.query.Query; -import static org.springframework.data.document.mongodb.query.Update; + import static org.springframework.data.mongodb.core.query.Criteria.where; +import static org.springframework.data.mongodb.core.query.Query; +import static org.springframework.data.mongodb.core.query.Update; ... @@ -1402,8 +1402,8 @@ import static org.springframework.data.document.mongodb.query.Update; Querying for documents using the MongoTemplate - import static org.springframework.data.document.mongodb.query.Criteria.where; -import static org.springframework.data.document.mongodb.query.Query.query; + import static org.springframework.data.mongodb.core.query.Criteria.where; +import static org.springframework.data.mongodb.core.query.Query.query; ... @@ -1418,7 +1418,7 @@ import static org.springframework.data.document.mongodb.query.Query.query; named where used to instantiate a new Criteria object. We recommend using a static import for - org.springframework.data.document.mongodb.query.Criteria.where + org.springframework.data.mongodb.core.query.Criteria.where and Query.query to make the query more readable. @@ -1450,6 +1450,14 @@ import static org.springframework.data.document.mongodb.query.Query.query; one + + Criteria andOperator + (Criteria... + criteria)Creates an and query using the + $and operator for all of the provided + criteria (requires MongoDB 2.0 or later) + + Criteria elemMatch (Criteria c) @@ -1526,6 +1534,14 @@ import static org.springframework.data.document.mongodb.query.Query.query; using the $nin operator + + Criteria norOperator + (Criteria... + criteria)Creates an nor query using the + $nor operator for all of the provided + criteria + + Criteria not ()Creates a criterion using the @@ -1534,11 +1550,11 @@ import static org.springframework.data.document.mongodb.query.Query.query; - Criteria or - (List<Query> - queries)Creates an or query using the + Criteria orOperator + (Criteria... + criteria)Creates an or query using the $or operator for all of the provided - queries + criteria @@ -1624,14 +1640,6 @@ import static org.springframework.data.document.mongodb.query.Query.query; additional criteria to the query - - void or (List<Query> - queries) Creates an or query using the - $or operator for all of the provided - queries - - Field fields () used to define fields to be @@ -2038,14 +2046,14 @@ public class PersonWriteConverter implements Converter<Person, DBObject> { <mongo:custom-converters> <mongo:converter ref="readConverter"/> <mongo:converter> - <bean class="org.springframework.data.document.mongodb.PersonWriteConverter"/> + <bean class="org.springframework.data.mongodb.test.PersonWriteConverter"/> </mongo:converter> </mongo:custom-converters> </mongo:mapping-converter> -<bean id="readConverter" class="org.springframework.data.document.mongodb.PersonReadConverter"/> +<bean id="readConverter" class="org.springframework.data.mongodb.test.PersonReadConverter"/> -<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"/> <constructor-arg name="mongoConverter" ref="mappingConverter"/> </bean> @@ -2193,7 +2201,7 @@ mongoTemplate.dropCollection("MyNewCollection"); To intercept an object before it goes into the database, you'd register a subclass of - org.springframework.data.document.mongodb.mapping.event.AbstractMappingEventListener + org.springframework.data.mongodb.core.mapping.event.AbstractMongoEventListener that overrides the onBeforeSave method. When the event is dispatched, your listener will be called and passed the domain object and the converted com.mongodb.DBObject.