MongoEMF 0.3.2 Released

I have released MongoEMF 0.3.2.  This build adds support for storing OSGi log entries to MongoDB, and includes bug fixes for queries against dates and defaults values.

OSGi Logging in MongoDB

I’ve added a new bundle, org.eclispelabe.mongo.emf.log, that will convert an OSGi LogEntry into an EMF object and store it into MongoDB.  Storing your OSGi log entries into MongoDB is a simple matter of configuring the ILogService (declarative service) with the OSGI ConfigurationAdmin service.  I have created a LogServiceConfigurator helper class if you’d rather not deal with ConfigurationAdmin.  The log service requires two properties:

  • baseURI
  • logLevel

The baseURI must be a valid MongoEMF collection URI of the form mongo://host/database/collection/ – for example: mongo://localhost/data/logs/.  The logLevel is set to one of the logging levels defined in the OSGi LogService: LOG_ERROR, LOG_WARNING, LOG_INFO, and LOG_DEBUG.

Here is an example configuration using the LogServiceConfigurator for logging errors and warnings:

 
LogServiceConfigurator.configureLogService(URI.createURI("mongo://localhost/junit/logs/"), LogService.LOG_WARNING);

Querying Default Values

The standard EMF serializations: XML, XMI, and Binary do not store default values for attributes.  The Mongo EMF binding was written this way as well to maintain consistency, but has the side effect of not being able to query objects based on attributes set to their default value.  To solve this problem, we’ve added the option:

MongoDBURIHandlerImpl.OPTION_SERIALIZE_DEFAULT_ATTRIBUTE_VALUES

Setting this option to Boolean.TRUE when saving your object to MongoDB will force attributes with default values to be persisted to MongoDB.  Here is a simple example:

Resource resource = resourceSet.createResource(uri);
resource.getContents().add(object);
HashMap<String, Object> options = new HashMap<String, Object>(1);
options.put(MongoDBURIHandlerImpl.OPTION_SERIALIZE_DEFAULT_ATTRIBUTE_VALUES, Boolean.TRUE);

try
{
  resource.save(options);
}
catch(IOException w)
{
  e.printStackTrace();
}

Leave a comment