Sunday, February 17, 2013

Possible ways to use MongoDB in next Servlet based project


Hibernate OGM
No JPQL query support,
must use raw Mongo query language directly and as a result
getting back Mongo Objects, not entities

To solve this the project integrates with Hibernate Search which uses
Lucene as a search engine.

When you insert/update an entity the data is also added to the search engine
This is pretty good for a full text search capabilities
and later can use JPQL against the Lucene instead of against MongoDB
This means that must install/configure and depend on Lucene

Upside: relatively easy to setup without upgrading anything on Application server
Can find entity by _id easily

Downside: either depend on Lucene OR use only native MongoDB queries

====================

EclipseLink NoSQL
Support for JPQL
Mongo document will be a normal entity
Can also use native MongoDB queries if JPQL just cannot do certain queries

Overall this is the most convenient way and pretty sweet
The downside is that Application Server may not include the latest version of the
EclipseLink jpa libriries and as a result must update the jar files directly in the
application server, which may not be possible in case of cloud hosting

===========

No dependencies on anything - just use MongoDB drivers
directly - no entities.
Get cursor back, iterate over results manually, add to collection,
then return collection
Write classes that know how to deal with BasicDBObject from mongo
For example when creating new Question a class QuestionParser will
take the request object, generate SubmittedQuestgionWWW, get all
data from it, put data into BasicObject
and then save BasicObject into DB

Must create indexes using "EnsureIndex" or something like that.

https://openshift.redhat.com/community/blogs/spatial-jee6-jax-rs-cdi-mongodb-on-paas
Something like this: (Requires CDI support)
@Named
@ApplicationScoped
public class DBConnection {

  private DB mongoDB;

  @PostConstruct
  public void afterCreate() {
    …
  }

  …
}

Most likely no JEE server is required, so Tomcat with CDI support
is all it takes

=========================

Mongo JEE
https://github.com/angelozerr/mongo-jee
Has good support for pagination
and integration with JAX RS
Also maps mongo cursor directly to
output stream json - no need to
create List from mongo cursor manually

Looks like will work on just about any server
that has CDI, most likely
inside tomcat container, no JEE application server
required.

============================



No comments:

Post a Comment