Skip to content

Commit e7d47c4

Browse files
author
Mark Pollack
committed
Merge remote branch 'origin/master'
2 parents d3a3809 + dfe7d16 commit e7d47c4

File tree

3 files changed

+238
-8
lines changed

3 files changed

+238
-8
lines changed

spring-data-document-parent/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<org.codehaus.jackson.version>1.6.1</org.codehaus.jackson.version>
1919
<org.springframework.version>3.0.5.RELEASE</org.springframework.version>
2020
<data.commons.version>1.0.0.BUILD-SNAPSHOT</data.commons.version>
21-
<aspectj.version>1.6.11.M2</aspectj.version>
21+
<aspectj.version>1.6.11.RELEASE</aspectj.version>
2222
</properties>
2323
<profiles>
2424
<profile>

src/docbkx/reference/cross-store.xml

Lines changed: 236 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,247 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN"
3-
"http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd">
3+
"http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd">
44
<chapter id="mongo.cross.store">
55
<title>Cross Store support</title>
66

7-
<para>Cross Store support introduction.
8-
</para>
7+
<para>Sometimes you need to store data in multiple data stores and these
8+
data stores can be of different types. One might be relational while the
9+
other a document store. For this use case we have created a separate module
10+
in the MongoDB support that handles what we call cross-store support. The
11+
current implemenatation is based on JPA as the driver for the relational
12+
database and we allow select fields in the Entities to be stored in a Mongo
13+
database. In addition to allowing you to store your data in two stores we
14+
also coordinate persistence operations for the non-transactional MongoDB
15+
store with the transaction life-cycle for the relational database.</para>
916

10-
<section id="mongodb:croos-store-configuration">
17+
<section id="mongodb_cross-store-configuration">
1118
<title>Cross Store Configuration</title>
1219

13-
<para>Cross Store...
14-
</para>
20+
<para>Assuming that you have a working JPA application and would like to
21+
add some cross-store persistence for MongoDB. What do you have to add to
22+
your configuration?</para>
1523

24+
<para>First of all you need to add a dependency on the
25+
<filename>spring-data-mongodb-cross-store</filename> module. Using Maven
26+
this is done by adding a dependency to your pom:</para>
27+
28+
<example>
29+
<title>Example Maven pom.xml with spring-data-mongodb-cross-store
30+
dependency</title>
31+
32+
<programlisting language="xml">&lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
33+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"&gt;
34+
&lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
35+
36+
...
37+
38+
&lt;!-- Spring Data --&gt;
39+
&lt;dependency&gt;
40+
&lt;groupId&gt;org.springframework.data&lt;/groupId&gt;
41+
&lt;artifactId&gt;spring-data-mongodb-cross-store&lt;/artifactId&gt;
42+
&lt;version&gt;${spring.data.mongo.version}&lt;/version&gt;
43+
&lt;/dependency&gt;
44+
45+
46+
...
47+
48+
&lt;/project&gt;
49+
</programlisting>
50+
</example>
51+
52+
<para>Once this is done we need to enable AspectJ for the project. The
53+
cross-store support is implemented using AspectJ aspects so by enabling
54+
compile time AspectJ support the cross-store features will become
55+
available to your project. In Maven you would add an additional plugin to
56+
the &lt;build&gt; section of the pom:</para>
57+
58+
<example>
59+
<title>Example Maven pom.xml with AspectJ plugin enabled</title>
60+
61+
<programlisting language="xml">&lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
62+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"&gt;
63+
&lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
64+
65+
...
66+
67+
&lt;build&gt;
68+
&lt;plugins&gt;
69+
70+
...
71+
72+
&lt;plugin&gt;
73+
&lt;groupId&gt;org.codehaus.mojo&lt;/groupId&gt;
74+
&lt;artifactId&gt;aspectj-maven-plugin&lt;/artifactId&gt;
75+
&lt;version&gt;1.0&lt;/version&gt;
76+
&lt;dependencies&gt;
77+
&lt;!-- NB: You must use Maven 2.0.9 or above or these are ignored (see MNG-2972) --&gt;
78+
&lt;dependency&gt;
79+
&lt;groupId&gt;org.aspectj&lt;/groupId&gt;
80+
&lt;artifactId&gt;aspectjrt&lt;/artifactId&gt;
81+
&lt;version&gt;${aspectj.version}&lt;/version&gt;
82+
&lt;/dependency&gt;
83+
&lt;dependency&gt;
84+
&lt;groupId&gt;org.aspectj&lt;/groupId&gt;
85+
&lt;artifactId&gt;aspectjtools&lt;/artifactId&gt;
86+
&lt;version&gt;${aspectj.version}&lt;/version&gt;
87+
&lt;/dependency&gt;
88+
&lt;/dependencies&gt;
89+
&lt;executions&gt;
90+
&lt;execution&gt;
91+
&lt;goals&gt;
92+
&lt;goal&gt;compile&lt;/goal&gt;
93+
&lt;goal&gt;test-compile&lt;/goal&gt;
94+
&lt;/goals&gt;
95+
&lt;/execution&gt;
96+
&lt;/executions&gt;
97+
&lt;configuration&gt;
98+
&lt;outxml&gt;true&lt;/outxml&gt;
99+
&lt;aspectLibraries&gt;
100+
&lt;aspectLibrary&gt;
101+
&lt;groupId&gt;org.springframework&lt;/groupId&gt;
102+
&lt;artifactId&gt;spring-aspects&lt;/artifactId&gt;
103+
&lt;/aspectLibrary&gt;
104+
&lt;aspectLibrary&gt;
105+
&lt;groupId&gt;org.springframework.data&lt;/groupId&gt;
106+
&lt;artifactId&gt;spring-data-mongodb-cross-store&lt;/artifactId&gt;
107+
&lt;/aspectLibrary&gt;
108+
&lt;/aspectLibraries&gt;
109+
&lt;source&gt;1.6&lt;/source&gt;
110+
&lt;target&gt;1.6&lt;/target&gt;
111+
&lt;/configuration&gt;
112+
&lt;/plugin&gt;
113+
114+
...
115+
116+
&lt;/plugins&gt;
117+
&lt;/build&gt;
118+
119+
...
120+
121+
&lt;/project&gt;
122+
</programlisting>
123+
</example>
124+
125+
<para>Finally, you need to configure your project to use MomgoDB and also
126+
configure the aspects that are used. The following XML snippet should be
127+
added to your application context:</para>
128+
129+
<example>
130+
<title>Example application context with MongoDB and cross-store aspect
131+
support</title>
132+
133+
<programlisting language="xml">&lt;?xml version="1.0" encoding="UTF-8"?&gt;
134+
&lt;beans xmlns="http://www.springframework.org/schema/beans"
135+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
136+
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
137+
xmlns:jpa="http://www.springframework.org/schema/data/jpa"
138+
xmlns:mongo="http://www.springframework.org/schema/data/mongo"
139+
xsi:schemaLocation="http://www.springframework.org/schema/data/mongo
140+
http://www.springframework.org/schema/data/mongo/spring-mongo.xsd
141+
http://www.springframework.org/schema/jdbc
142+
http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd
143+
http://www.springframework.org/schema/beans
144+
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
145+
http://www.springframework.org/schema/data/jpa
146+
http://www.springframework.org/schema/data/jpa/spring-jpa-1.0.xsd"&gt;
147+
148+
...
149+
150+
&lt;!-- Mongo config --&gt;
151+
&lt;mongo:mongo host="localhost" port="27017"/&gt;
152+
153+
&lt;bean id="mongoTemplate" class="org.springframework.data.document.mongodb.MongoTemplate"&gt;
154+
&lt;constructor-arg name="mongo" ref="mongo"/&gt;
155+
&lt;constructor-arg name="databaseName" value="test"/&gt;
156+
&lt;constructor-arg name="defaultCollectionName" value="cross-store"/&gt;
157+
&lt;/bean&gt;
158+
159+
&lt;bean class="org.springframework.data.document.mongodb.MongoExceptionTranslator"/&gt;
160+
161+
&lt;!-- Mongo cross-store aspect config --&gt;
162+
&lt;bean class="org.springframework.data.persistence.document.mongo.MongoDocumentBacking"
163+
factory-method="aspectOf"&gt;
164+
&lt;property name="changeSetPersister" ref="mongoChangeSetPersister"/&gt;
165+
&lt;/bean&gt;
166+
&lt;bean id="mongoChangeSetPersister"
167+
class="org.springframework.data.persistence.document.mongo.MongoChangeSetPersister"&gt;
168+
&lt;property name="mongoTemplate" ref="mongoTemplate"/&gt;
169+
&lt;property name="entityManagerFactory" ref="entityManagerFactory"/&gt;
170+
&lt;/bean&gt;
171+
172+
...
173+
174+
&lt;/beans&gt;
175+
</programlisting>
176+
</example>
177+
178+
<para></para>
179+
180+
<para> </para>
181+
</section>
182+
183+
<section id="mongodb_cross-store-application">
184+
<title>Writing the Cross Store Application</title>
185+
186+
<para>We are assuming that you have a working JPA application so we will
187+
only cover the additional steps needed to persist part of your Entity in
188+
your Mongo database. First you need to identify the field you want
189+
persited. It should be a domain class and follow the general rules for the
190+
Mongo mapping support covered in previous chapters. The filed you want
191+
persisted in MongoDB should be annotated using the
192+
<classname>@RelatedDocument</classname> annotation. Well, that is really
193+
all you need to do. The cross-store aspects take care of the rest. This
194+
include marking the field with @Transient so it won't be persisted using
195+
JPA, keeping track of any changes and flushing them on succesfull
196+
transaction completion, loading teh document for MongoDB when the values
197+
is used in your application. Here is an example of a simple Entity that
198+
has a field annotated with @RelatedEntity.</para>
199+
200+
<example>
201+
<title>Example of Entity with @RelatedDocument</title>
202+
203+
<programlisting language="java">@Entity
204+
public class Customer {
205+
206+
@Id
207+
@GeneratedValue(strategy = GenerationType.IDENTITY)
208+
private Long id;
209+
210+
private String firstName;
211+
212+
private String lastName;
213+
214+
@RelatedDocument
215+
private SurveyInfo surveyInfo;
216+
217+
// getters and setters omitted
218+
219+
} </programlisting>
220+
</example>
221+
222+
<example>
223+
<title>Example of domain class to be stored as document</title>
224+
225+
<programlisting language="java">public class SurveyInfo {
226+
227+
private Map&lt;String, String&gt; questionsAndAnswers;
228+
229+
public Map&lt;String, String&gt; getQuestionsAndAnswers() {
230+
return questionsAndAnswers;
231+
}
232+
233+
public void setQuestionsAndAnswers(Map&lt;String, String&gt; questionsAndAnswers) {
234+
this.questionsAndAnswers = questionsAndAnswers;
235+
}
236+
} </programlisting>
237+
</example>
238+
239+
<para>Once t...</para>
240+
241+
<para></para>
242+
243+
<para></para>
244+
245+
<para></para>
16246
</section>
17247
</chapter>

src/docbkx/resources/xsl/fopdf.xsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@
106106
<xsl:param name="gentext-key" select="''"/>
107107
<xsl:variable name="Version">
108108
<xsl:if test="//releaseinfo">
109-
<xsl:text>Spring Data Redis (</xsl:text><xsl:value-of select="//releaseinfo" /><xsl:text>)</xsl:text>
109+
<xsl:text>Spring Data Document (</xsl:text><xsl:value-of select="//releaseinfo" /><xsl:text>)</xsl:text>
110110
</xsl:if>
111111
</xsl:variable>
112112
<xsl:choose>

0 commit comments

Comments
 (0)