Morphium 4.0.0 in the works

published : 2018-07-17 changed: 2018-07-17

category: global


MongoDB released the long awaited V4.0 just recently. And of course there are a lot of new features, but the most exiting one was probably the support for multi document ACID transactions!

The mongo driver does support all those features since V3.8.0 - and morphium supports all of that with V4.0.0 - to match the mongodb version. The current BETA1 should be available via maven central or from github.com.

new Features in Morphium 4.0.0

Transaction Support

of course, this had to be added. But it is quite simple to use:

//start a transaction via
morphium.startTransaction();
//all calls in this thread use the transaction now

morphium.commitTransaction()//commit
morphium.abortTransaction()//abort

MorphiumTransactionContext ctx=morphium.getTransaction();

//to have other threads use the transaction, you need to pass on the transaction context
//Transactions are Threadlocal - so you need to set the context in threads accordingly

morphium.setTransaction(ctx);

Attention: if your mongodb does not support transactions, this will cause an exception

improved Messaging.

We put a lot of effort into messaging, simplified the API at some places and added some new features. Messaging now supports kind of "push" notifications, if connected to a replicaset.

Improved Cluster-Aware Caching

using the new watch functionality of mongod, which is nothing but another way to access the oplog, we could implement a feature to synchronize the cache via database push. It works similar as with the messaging, just that the messaging is not used. The notification about changes comes directly from database. the @Cache annotation is used to determine how to delete / update the cache.

we introduced a new cache synchronizer for that:

WatchingCacheSynchronizer sync = new WatchingCacheSynchronizer(morphium);
sync.start();

inMemoryDriver

We re-included and improved the In-Memory-Driver into morphium. So you can more easy Mock access to mongo, which is very important when testing.

MorphiumConfig cfg = new MorphiumConfig();
        cfg.addHostToSeed("inMem");
        cfg.setDatabase("test");
        cfg.setDriverClass(InMemoryDriver.class.getName());
        cfg.setReplicasetMonitoring(false);

Transactions are not working (yet) and aggregation might come in some later version of the driver. All other, more basic functionality is working.

created Stephan Bösebeck (stephan)