Skip to content

Commit 87657aa

Browse files
mp911dechristophstrobl
authored andcommitted
DATAMONGO-1412 - Fix backticks and code element highlighting.
Fixed broken highlighting using backticks followed by chars/single quotes. Convert single quote emphasis of id to backtick code fences. Add missing spaces between words and backticks. Original Pull Request: #359
1 parent 034c90f commit 87657aa

File tree

3 files changed

+42
-42
lines changed

3 files changed

+42
-42
lines changed

src/main/asciidoc/reference/mapping.adoc

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,25 @@ NOTE: `SimpleMongoConverter` has been deprecated in Spring Data MongoDB M3 as al
1212

1313
`MongoMappingConverter` has a few conventions for mapping objects to documents when no additional mapping metadata is provided. The conventions are:
1414

15-
* The short Java class name is mapped to the collection name in the following manner. The class '`com.bigbank.SavingsAccount`' maps to '`savingsAccount`' collection name.
15+
* The short Java class name is mapped to the collection name in the following manner. The class `com.bigbank.SavingsAccount` maps to `savingsAccount` collection name.
1616
* All nested objects are stored as nested objects in the document and *not* as DBRefs
1717
* The converter will use any Spring Converters registered with it to override the default mapping of object properties to document field/values.
1818
* The fields of an object are used to convert to and from fields in the document. Public JavaBean properties are not used.
1919
* You can have a single non-zero argument constructor whose constructor argument names match top level field names of document, that constructor will be used. Otherwise the zero arg constructor will be used. if there is more than one non-zero argument constructor an exception will be thrown.
2020

2121
[[mapping.conventions.id-field]]
22-
=== How the '_id' field is handled in the mapping layer
22+
=== How the `_id` field is handled in the mapping layer
2323

24-
MongoDB requires that you have an '_id' field for all documents. If you don't provide one the driver will assign a ObjectId with a generated value. The "_id" field can be of any type the, other than arrays, so long as it is unique. The driver naturally supports all primitive types and Dates. When using the `MongoMappingConverter` there are certain rules that govern how properties from the Java class is mapped to this '_id' field.
24+
MongoDB requires that you have an `_id` field for all documents. If you don't provide one the driver will assign a ObjectId with a generated value. The "_id" field can be of any type the, other than arrays, so long as it is unique. The driver naturally supports all primitive types and Dates. When using the `MongoMappingConverter` there are certain rules that govern how properties from the Java class is mapped to this `_id` field.
2525

26-
The following outlines what field will be mapped to the '_id' document field:
26+
The following outlines what field will be mapped to the `_id` document field:
2727

28-
* A field annotated with `@Id` (`org.springframework.data.annotation.Id`) will be mapped to the '_id' field.
29-
* A field without an annotation but named 'id' will be mapped to the '_id' field.
30-
* The default field name for identifiers is '_id' and can be customized via the `@Field` annotation.
28+
* A field annotated with `@Id` (`org.springframework.data.annotation.Id`) will be mapped to the `_id` field.
29+
* A field without an annotation but named `id` will be mapped to the `_id` field.
30+
* The default field name for identifiers is `_id` and can be customized via the `@Field` annotation.
3131

3232
[cols="1,2", options="header"]
33-
.Examples for the translation of '_id'-field definitions
33+
.Examples for the translation of `_id` field definitions
3434
|===
3535
| Field definition
3636
| Resulting Id-Fieldname in MongoDB
@@ -41,21 +41,21 @@ The following outlines what field will be mapped to the '_id' document field:
4141
| `@Field` `String` id
4242
| `_id`
4343

44-
| `@Field('x')` `String` id
44+
| `@Field("x")` `String` id
4545
| `x`
4646

4747
| `@Id` `String` x
4848
| `_id`
4949

50-
| `@Field('x')` `@Id` `String` x
50+
| `@Field("x")` `@Id` `String` x
5151
| `_id`
5252
|===
5353

5454
The following outlines what type conversion, if any, will be done on the property mapped to the _id document field.
5555

56-
* If a field named 'id' is declared as a String or BigInteger in the Java class it will be converted to and stored as an ObjectId if possible. ObjectId as a field type is also valid. If you specify a value for 'id' in your application, the conversion to an ObjectId is detected to the MongoDBdriver. If the specified 'id' value cannot be converted to an ObjectId, then the value will be stored as is in the document's _id field.
57-
* If a field named ' id' id field is not declared as a String, BigInteger, or ObjectID in the Java class then you should assign it a value in your application so it can be stored 'as-is' in the document's _id field.
58-
* If no field named 'id' is present in the Java class then an implicit '_id' file will be generated by the driver but not mapped to a property or field of the Java class.
56+
* If a field named `id` is declared as a String or BigInteger in the Java class it will be converted to and stored as an ObjectId if possible. ObjectId as a field type is also valid. If you specify a value for `id` in your application, the conversion to an ObjectId is detected to the MongoDBdriver. If the specified `id` value cannot be converted to an ObjectId, then the value will be stored as is in the document's _id field.
57+
* If a field named `id` id field is not declared as a String, BigInteger, or ObjectID in the Java class then you should assign it a value in your application so it can be stored 'as-is' in the document's _id field.
58+
* If no field named `id` is present in the Java class then an implicit `_id` file will be generated by the driver but not mapped to a property or field of the Java class.
5959

6060
When querying and updating `MongoTemplate` will use the converter to handle conversions of the `Query` and `Update` objects that correspond to the above rules for saving documents so field names and types used in your queries will be able to match what is in your domain classes.
6161

@@ -292,11 +292,11 @@ public class GeoSpatialAppConfig extends AbstractMongoConfiguration {
292292
----
293293
====
294294

295-
`AbstractMongoConfiguration` requires you to implement methods that define a `com.mongodb.Mongo` as well as provide a database name. `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.mongodb.core.mapping.Document` annotation.
295+
`AbstractMongoConfiguration` requires you to implement methods that define a `com.mongodb.Mongo` as well as provide a database name. `AbstractMongoConfiguration` also has a method you can override named `getMappingBasePackage(…)` which tells the converter where to scan for classes annotated with the `@Document` annotation.
296296

297-
You can add additional converters to the converter by overriding the method afterMappingMongoConverterCreation. Also shown in the above example is a `LoggingEventListener` which logs `MongoMappingEvent`s that are posted onto Spring's `ApplicationContextEvent` infrastructure.
297+
You can add additional converters to the converter by overriding the method afterMappingMongoConverterCreation. Also shown in the above example is a `LoggingEventListener` which logs `MongoMappingEvent` s that are posted onto Spring's `ApplicationContextEvent` infrastructure.
298298

299-
NOTE: AbstractMongoConfiguration will create a MongoTemplate instance and registered with the container under the name 'mongoTemplate'.
299+
NOTE: AbstractMongoConfiguration will create a MongoTemplate instance and registered with the container under the name `mongoTemplate`.
300300

301301
You can also override the method `UserCredentials getUserCredentials()` to provide the username and password information to connect to the database.
302302

@@ -349,7 +349,7 @@ The `base-package` property tells it where to scan for classes annotated with th
349349
[[mapping-usage]]
350350
== Metadata based Mapping
351351

352-
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.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 domain objects to extract the necessary metadata. If you don't use this annotation, your application will take a slight performance hit the first time you store a domain object because the mapping framework needs to build up its internal metadata model so it knows about the properties of your domain object and how to persist them.
352+
To take full advantage of the object mapping functionality inside the Spring Data/MongoDB support, you should annotate your mapped objects with the `@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 domain objects to extract the necessary metadata. If you don't use this annotation, your application will take a slight performance hit the first time you store a domain object because the mapping framework needs to build up its internal metadata model so it knows about the properties of your domain object and how to persist them.
353353

354354
.Example domain object
355355
====
@@ -599,7 +599,7 @@ Simply declaring these beans in your Spring ApplicationContext will cause them t
599599
[[mapping-explicit-converters]]
600600
=== Overriding Mapping with explicit Converters
601601

602-
When storing and querying your objects it is convenient to have a `MongoConverter` instance handle the mapping of all Java types to DBObjects. However, sometimes you may want the `MongoConverter`'s do most of the work but allow you to selectively handle the conversion for a particular type or to optimize performance.
602+
When storing and querying your objects it is convenient to have a `MongoConverter` instance handle the mapping of all Java types to DBObjects. However, sometimes you may want the `MongoConverter` s do most of the work but allow you to selectively handle the conversion for a particular type or to optimize performance.
603603

604604
To selectively handle the conversion yourself, register one or more one or more `org.springframework.core.convert.converter.Converter` instances with the MongoConverter.
605605

src/main/asciidoc/reference/mongo-repositories.adoc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public class Person {
2828
----
2929
====
3030

31-
We have a quite simple domain object here. Note that it has a property named `id` of type`ObjectId`. The default serialization mechanism used in `MongoTemplate` (which is backing the repository support) regards properties named id as document id. Currently we support`String`, `ObjectId` and `BigInteger` as id-types.
31+
We have a quite simple domain object here. Note that it has a property named `id` of type `ObjectId`. The default serialization mechanism used in `MongoTemplate` (which is backing the repository support) regards properties named id as document id. Currently we support `String`, `ObjectId` and `BigInteger` as id-types.
3232

3333
.Basic repository interface to persist Person entities
3434
====
@@ -99,7 +99,7 @@ class ApplicationConfig extends AbstractMongoConfiguration {
9999
----
100100
====
101101

102-
As our domain repository extends `PagingAndSortingRepository` it provides you with CRUD operations as well as methods for paginated and sorted access to the entities. Working with the repository instance is just a matter of dependency injecting it into a client. So accessing the second page of `Person`s at a page size of 10 would simply look something like this:
102+
As our domain repository extends `PagingAndSortingRepository` it provides you with CRUD operations as well as methods for paginated and sorted access to the entities. Working with the repository instance is just a matter of dependency injecting it into a client. So accessing the second page of `Person` s at a page size of 10 would simply look something like this:
103103

104104
.Paging access to Person entities
105105
====
@@ -139,17 +139,17 @@ public interface PersonRepository extends PagingAndSortingRepository<Person, Str
139139
Page<Person> findByFirstname(String firstname, Pageable pageable); <2>
140140
141141
Person findByShippingAddresses(Address address); <3>
142-
142+
143143
Stream<Person> findAllBy(); <4>
144144
}
145145
----
146146
<1> The method shows a query for all people with the given lastname. The query will be derived parsing the method name for constraints which can be concatenated with `And` and `Or`. Thus the method name will result in a query expression of `{"lastname" : lastname}`.
147147
<2> Applies pagination to a query. Just equip your method signature with a `Pageable` parameter and let the method return a `Page` instance and we will automatically page the query accordingly.
148-
<3> Shows that you can query based on properties which are not a primitive type.
148+
<3> Shows that you can query based on properties which are not a primitive type.
149149
<4> Uses a Java 8 `Stream` which reads and converts individual elements while iterating the stream.
150150
====
151151

152-
152+
153153

154154
NOTE: Note that for version 1.0 we currently don't support referring to parameters that are mapped as `DBRef` in the domain class.
155155

@@ -328,7 +328,7 @@ public interface PersonRepository extends MongoRepository<Person, String>
328328
// Metric: {'geoNear' : 'person', 'near' : [x, y], 'maxDistance' : distance,
329329
// 'distanceMultiplier' : metric.multiplier, 'spherical' : true }
330330
GeoResults<Person> findByLocationNear(Point location, Distance distance);
331-
331+
332332
// Metric: {'geoNear' : 'person', 'near' : [x, y], 'minDistance' : min,
333333
// 'maxDistance' : max, 'distanceMultiplier' : metric.multiplier,
334334
// 'spherical' : true }

0 commit comments

Comments
 (0)