<para>As explained in <xreflinkend="why-Spring Data-Document"/>, Spring Data Document (SDDOC) provides integration
<para>As explained in <xreflinkend="why-Spring Data-Document"/>, Spring Data Document (DATADOC) provides integration
between Spring framework and document oriented data stores. Thus, it is important to become acquainted with both of these
between Spring framework and document oriented data stores. Thus, it is important to become acquainted with both of these
frameworks (storages or environments depending on how you want to name them). Throughout the SDDOC documentation,
frameworks (storages or environments depending on how you want to name them). Throughout the DATADOC documentation,
each section provides links to resources relevant however, it is best to become familiar with these topics beforehand.</para>
each section provides links to resources relevant however, it is best to become familiar with these topics beforehand.</para>
<sectionid="get-started:first-steps:spring">
<sectionid="get-started:first-steps:spring">
@ -34,14 +34,14 @@
<title>Knowing NoSQL and Document stores</title>
<title>Knowing NoSQL and Document stores</title>
<para>NoSQL stores have taken the storage world by storm. It is a vast domain with a plethora of solutions, terms and patterns (to make things worth even the
<para>NoSQL stores have taken the storage world by storm. It is a vast domain with a plethora of solutions, terms and patterns (to make things worth even the
term itself has multiple <ulinkurl="http://www.google.com/search?q=nosoql+acronym">meanings</ulink>).
term itself has multiple <ulinkurl="http://www.google.com/search?q=nosoql+acronym">meanings</ulink>).
While some of the principles are common, it is crucial that the user is familiar to some degree with the stores supported by SDDOC.
While some of the principles are common, it is crucial that the user is familiar to some degree with the stores supported by DATADOC.
The best way to get acquainted to this solutions is to read their documentation and follow their examples - it usually doesn't take more then 5-10 minutes
The best way to get acquainted to this solutions is to read their documentation and follow their examples - it usually doesn't take more then 5-10 minutes
to go through them and if you are coming from an RDMBS-only background many times these exercises can be an eye opener.
to go through them and if you are coming from an RDMBS-only background many times these exercises can be an eye opener.
</para>
</para>
</section>
</section>
<sectionid="get-started:first-steps:samples">
<sectionid="get-started:first-steps:samples">
<title>Trying Out The Samples</title>
<title>Trying Out The Samples</title>
<para>Unfortunately the SDDOC project is very young and there are no samples available yet. However we are working on them and plan to make them available
<para>Unfortunately the DATADOC project is very young and there are no samples available yet. However we are working on them and plan to make them available
as soon as possible. In the meantime however, one can use our test suite as a code example (assuming the documentation is not enough) - we provide extensive
as soon as possible. In the meantime however, one can use our test suite as a code example (assuming the documentation is not enough) - we provide extensive
<para>One of the document stores supported by SDDOC is <ulinkurl="http://www.mongodb.org/">MongoDB</ulink>.
<para>One of the document stores supported by DATADOC is <ulink
To quote the project home page:
url="http://www.mongodb.org/">MongoDB</ulink>. To quote the project home
<quote>
page: <quote> MongoDB (from "humongous") is a scalable, high-performance,
MongoDB (from "humongous") is a scalable, high-performance, open source, document-oriented database.
open source, document-oriented database. </quote><para>Spring Data Document
</quote>
provides easy configuration and access to MongoDB from a Spring application.
Offers both low-level and high-level abstraction for interacting with the
<para>Spring Data Document provides easy configuration and access to MongoDB from a Spring application. Offers both low-level and
store, freeing the user from infrastructural concerns.</para></para>
high-level abstraction for interacting with the store, freeing the user from infrastructural concerns.</para>
</para>
<sectionid="mongodb:requirements">
<sectionid="mongodb:requirements">
<title>MongoDB Requirements</title>
<title>MongoDB Requirements</title>
<para>SDDOC requires MongoDB 1.4 while 1.6 is recommended.
</para>
<para>DATADOC requires MongoDB 1.4 while 1.6 is recommended.</para>
</section>
</section>
<sectionid="mongodb:architecture">
<sectionid="mongodb:architecture">
<title>MongoDB Support High Level View</title>
<title>MongoDB Support High Level View</title>
<para>The MongoDB support provides several components:</para>
<para>The MongoDB support provides several components:</para>
<itemizedlist>
<itemizedlist>
<listitem><emphasis>Configuration Factory</emphasis> - for configuring and handling communication with MongoDB via its Java driver</listitem>
<listitem>
<listitem><emphasis>Template implemenattion</emphasis> - providing a generified, user friendly template classes for interacting with MongoDB.
<emphasis>Configuration Factory</emphasis>
<xreflinkend="mongodb:template"/> explains the abstraction builds on top of the low-level MongoDB Java API to handle the
storage and retrieval of documents plus mapping between documents and domain classes.</listitem>
- for configuring and handling communication with MongoDB via its Java driver
<listitem><emphasis>Support Classes</emphasis> - that offer reusable components such as mapping support and exception translation.</listitem>
</listitem>
<listitem>
<emphasis>Template implemenattion</emphasis>
- providing a generified, user friendly template classes for interacting with MongoDB.
<xreflinkend="mongodb:template"/>
explains the abstraction builds on top of the low-level MongoDB Java API to handle the storage and retrieval of documents plus mapping between documents and domain classes.
</listitem>
<listitem>
<emphasis>Support Classes</emphasis>
- that offer reusable components such as mapping support and exception translation.
</listitem>
</itemizedlist>
</itemizedlist>
<para>For most tasks, the higher-level abstractions and support services
are the best choice. Note that at any point, one can move between layers -
for example, it's very easy to get a hold of the low level connection
(org.mongo.DB) to communicate directly with MongoDB.</para>
</section>
<sectionid="mongodb:connectors">
<title>Connecting to MongoDB</title>
<para>One of the first tasks when using MongoDB and Spring is to connect
to the store through the IoC container. To do that</para>
<para>The easiest way to work with a
<interfacename>MongoFactoryBean</interfacename> is to configure a
<classname>MongoFactory</classname> bean. This has the added advantage of
also acting as an ExceptionTranslator that can be used to translate any
Mongo exceptions to exceptions in the
<classname>SpringDataAccessException</classname> hierarchy as long as your
data access classes are annotatded with @Repository and you are using an
<classname>PersistenceExceptionTranslationPostProcessor</classname> (see
<linklinkend="???">Spring API docs</link>).</para>
<para>You have two basic choices - use Java based configuration or XML
based configuration. An example fo a basic Java configuratopn style
is:</para>
<example>
<title>Java based Spring configuration for MongoDB</title>
<programlistinglanguage="java">@Configuration
public class AppConfig {
/*
* Factory bean that creates the Mongo instance
*/
public @Bean MongoFactoryBean mongo() {
MongoFactoryBean mongo = new MongoFactoryBean();
mongo.setHost("localhost");
return mongo;
}
<para>For most tasks, the higher-level abstractions and support services are the best choice. Note that at any point, one can move between layers - for example, it's very
/*
easy to get a hold of the low level connection (org.mongo.DB) to communicate directly with MongoDB.</para>
* A basic MongoTemplate instance
</section>
*/
public @Bean MongoTemplate mongoTemplate(Mongo mongo) {
<sectionid="mongodb:connectors">
MongoTemplate mongoTemplate = new MongoTemplate(mongo, "test", "HelloMongo");
<title>Connecting to MongoDB</title>
return mongoTemplate;
}
<para>One of the first tasks when using MongoDB and Spring is to connect to the store through the IoC container. To do that</para>
/*
<para>The easiest way to work with a <interfacename>MongoFactoryBean</interfacename> is to configure ...</para>
* Use this post processor to translate any MongoExceptions thrown in @Repository annotated classes
*/
</section>
public @Bean PersistenceExceptionTranslationPostProcessor persistenceExceptionTranslationPostProcessor() {
return new PersistenceExceptionTranslationPostProcessor();
<sectionid="mongodb:template">
}
<title>Working with Objects through <classname>MongoTemplate</classname></title>
}
<para>Most users are likely to use <classname>MongoTemplate</classname> and its corresponding package <literal>org.springframework.data.document.mongodb</literal> - the
</programlisting>
template is in fact the central class of the MongoDB module due to its rich feature set.
</example>
The template offers a high-level abstraction for MongoDB interaction.
</para>
<para>The following shows the same configuration using XML:</para>
<para>This namespace element will cause the base packages to be scanned
<para>This namespace element will cause the base packages to be scanned
@ -309,11 +424,15 @@ class PersonRepositoryTests {
</table></para>
</table></para>
</section>
</section>
</section>
</section>
<sectionid="mongodb:future">
<sectionid="mongodb:future">
<title>Roadmap ahead</title>
<title>Roadmap ahead</title>
<para>Spring Data MongoDB project is in its early stages. We are interested in feedback, knowing what your use cases are, what are the common patters you encounter so that the MongoDB module
<para>Spring Data MongoDB project is in its early stages. We are
better serves your needs. Do contact us using the channels <linklinkend="get-started:help:community">mentioned</link> above, we are interested in hearing from you!</para>
interested in feedback, knowing what your use cases are, what are the
</section>
common patters you encounter so that the MongoDB module better serves your
</chapter>
needs. Do contact us using the channels <link
linkend="get-started:help:community">mentioned</link> above, we are