Skip to content
Stephan Bösebeck edited this page Sep 28, 2020 · 10 revisions

What is Morphium?

We needed an Object-Mapping for MongoDB. Unfortunately most of the other project lack support for some things:

  • Possibility of Caching (High Load Applications) - see Caching
  • Thread Safety
  • possibility to run in clustered environment and cluster awareness
  • flexible mappings
  • life cycle method
  • validation support
  • references and lazy loading
  • support for the aggregation framework
  • polymorphism and inheritance

We needed especially support for caching, in order to reduce the load on our mongo db replica set. Especially complex queries which cannot be indexed. Mongo is highly dependent on the indexes, so caching boost performance a lot in those cases. In order to avoid problems in multithreadding and synchronized blocks, Morphium minimizes the use of synchronized blocks.

Morphium supports inheritance of morphium specific annotations.

I used my experience in the Caluga DB Modeller to build a 100% pure Java version of a Object Mapping Tool for MongoDB, that realizes all of those features mentioned above (and more).

Version: 4.x

Changed a lot again, especially when it comes to messaging and performance, InMemoryDriver and Aggregation.

  • since 4.2: a lot of helper methods for convenient aggregation support

Version: 3.x

Changed a lot in the architecture of the library. Especially reducing dependencies to other libs. And making it possible to use a different driver than the default java Driver. There are some example implementation (like an InMemoryDriver for mocking during tests) here: https://github.com/sboesebeck/morphium-drivers

Release: 2.2.x

Adds a lot of bugfixes and new features.

  • support for capped collections (new annotation @Capped)
  • storing timestamps of auto variables like @Created as String
  • bugfixes with list storage
  • replicaset improvements
  • bulk request support
  • bulk request interally used for bulk updates and inserts
  • support latest mongodb driver (2.12.2)
  • support latest mongodb version (2.6.3) minor improvements and API changes.

New Major Release 2.0

  • Reads and writes now support asynchronous mode. => AsyncApi
  • simpified API, making things a bit more legible
  • removed lot's of unneccessary stuff
  • lots of Bug fixes (thanks to jqzone)
  • new write Buffer implementation
  • async and buffered writes now possible (and even async buffered writes)

2.0.26 bugfix release

minor bugfix

2.0.21 bugfix release

includes minor bugfixes and removes the unwanted configmanager. If you still need it, feel free to use the code of ConfigManager in your project (drop-in-release). Contact me, if you have any questions

2.0.20 bugfix for querying subdocuments

in addition: some new unset-Operations were added

2.0.19 bugfix release

2.0.18 minor change

This adds a new feature for checking queries to sub object. Morphium would throw an exception, if you try to access e.g. "person.sister.nme" when the field actually is called "name"

2.0.16 minor change

added some code for conversion of ids

2.0.15 uses the new ability to read and write from JSon strings for the configuration

use MorphiumConfig.fromJson(jsonString) and cfg.toString(). As was requests by many, the configuration can now also be read from a property object: MorphiumConfig.fromProperties(p) or simply new MorphiumConfig(properties) and cfg.asProperties(). Examples: ` String cfg = MorphiumSingleton.get().getConfig().toString(); log.info("Config: " + cfg); MorphiumConfig c = MorphiumConfig.createFromJson(cfg);

    //from json String
    String json = "{ \"hosts\":\"mongo1:27018, mongo2:27099\", \"database\" : \"testdb\", \"safe_mode\" : true , \"global_fsync\" : false , \"globalJ\" : false , \"write_timeout\" : 9990 }";
    MorphiumConfig cfg = MorphiumConfig.createFromJson(json);

    ///////// from properties
     Properties p = MorphiumSingleton.get().getConfig().asProperties();
    for (Object k : p.keySet()) {
        log.info("Key: " + k + " Value: " + p.get(k));
    }
    p.store(System.out, "testproperties");

    MorphiumConfig cfg = MorphiumConfig.fromProperties(p);

    //////////////////
    p = new Properties();
    p.put("maximumRetriesAsyncWriter", "10");
    p.put("socketTimeout", "1000");
    p.put("database", "thingy");
    p.put("hosts", "localhost:27017");

    MorphiumConfig cfg = MorphiumConfig.fromProperties(p);

Warning: ConfigManager update makes db a bit less compatible. The_idfield now contains the config-key! please remember to migrate your data, e.g. with db.config_element.find().forEach(function(x) { db.config_element.remove({_id:x._id}); x._id=x.name; db.config_element.store(x); }) `

2.0.14: String mapping

adds the ability map from and to strings

2.0.13:Java Driver update

Upgrades to the new Mongo Java Driver 2.11.2 and fixes some major bugs regarding authentication and login.

2.0.11: minor bugfixes in Exception handling and MorphiumIterator.

Also with this version it's possible to set a retry-count for errors when accessing Mongo (like no master available, replicaset down, network error). We have a really sh.. network with lots of outages, so it was the logical way to solve the problem ;-)

morphium.getConfig().setRetriesOnNetworkError(10); morphium.getConfig().setSleepBetweenNetworkErrorRetries(500); Actually: the retry value is the total number of tries, hence you cannot set it to 0.

2.0.10: feature update

removes necessity for ID's being ObjectIDs - now you can use any type

2.0.6: text indices

contains rudimentary support for Mongodb 2.4's new text indices

2.0.4: support for Mongodb 2.4

unfortunately the change to MongoDB 2.4 brought some changes, that made Morphium incompatible up to this version. Especially some tests needed to be updated and the MessagingSystem system had to be adapted.

2.0.3: some bug fixes

new AsyncWrites annotation -> Annotations. CollectionName override possible. When storing, updating or reading, you can specify which collection to use if the default name, would not fit.Use case would be: store several objects to a temporary collection (like a op_log ;-)) and only if all runs good, copy those to the real collection.

2.0.2: some bugfixes, especially related to the MorphiumIterator

This feature is additional to the MaximumRetries*Writer settings, which are only used if heavy load affects the async write processes. retriesOnNetworkError affect all communication with mongo and also affect reads! see RetrySettings in wiki.

Attention If you use mongodb 2.4 you should consider upgrading to a release > 2.0.4!

Getting Morphium

GOOD NEWS Morphium is available in sonatype OSS Repository now, so you should soon be able to just put your dependency in your pom.xml: <dependency> <groupId>de.caluga</groupId> <artefactId>morphium</artefactiId> <version>2.0.x</version> </dependency>