MongoDB with Sculptor - Introduction
MongoDB bridges the gap between key-value stores (which are fast and highly scalable) and traditional RDBMS systems (which provide rich queries and deep functionality).
Would you like to?
- Use a rich persistent domain model à la DDD with automatic mapping to MongoDB data structures.
- Use associations even though the underlaying data store is not relational.
- Express queries in refactoring safe terms of the domain model.
- Get CRUD operations, and GUI, for free.
Then you should try Sculptor with the brand new MongoDB target implementation.
In the next few days I will describe the features one-by-one, but first an brief overview of what Sculptor provides for efficient development of a typical enterprise or web application with MongoDB as persistent store.
Sculptor is a productivity tool that let you express your design intent in a textual DSL, from which Sculptor generates high quality Java code and configuration. Read more in What is Sculptor?
Sculptor generates data mapper classes that converts domain objects to/from MongoDB data structures, DBObjects.
Sculptor provides generic repository operations for use with MongoDB. This includes operations such as save, delete, findById, findByKey, findByCondition, and some more.
Queries can be expressed with a slick fluent api that support code completion and refactoring.
Rich support for associations. Aggregates are stored as a embedded documents. Other associations are stored with referring ids. In the domain objects there are generated getters that lazily fetch associated objects from the ids. This means that you don’t have to work with the ids yourself, you can follow associations as usual.
A sample blog application may look like this when defined in Sculptor textual DSL:
Visualization, generated by Sculptor, of the above model looks like this:
Read the other posts that describes the features in more detail:
The source code of examples on using MongoDB (like the aforementioned blog sample or a modified version of the library sample) on using MongoDB can be found here: https://github.com/sculptor/sculptor/tree/master/sculptor-examples/mongodb-samples