MetaModel 3 provides type safe queries for ANY data


News: MetaModel 3 provides type safe queries for ANY data

  1. I would like to inform you of MetaModel version 3.0, an open source data access framework for Java which was released this Monday (the 9th of July). It is developed and maintained by Human Inference (NL) and Xebia India, and used in a number of projects already.

    MetaModel is different than other data access frameworks in that:

    • It spans many different kinds of datastores: Relational databases, NoSQL stores, text file formats, Excel spreadsheets, MS Access and other data formats.
    • MetaModel is heavily inspired by SQL and LINQ. It offers a type safe way of querying and updating your data.
    • It is not an ORM. With MetaModel you’re not doing any domain model mapping. You’re given the full power of the physical data model, but without having to deal with the physical data exchange intricacies.
    • MetaModel includes it’s own query engine which supports SQL-like queries for all of the datastore technologies mentioned above. When possible, the queries will be executed in the datastores themselves (eg. relational and NoSQL databases), but when not possible, MetaModel provides a streaming framework for filtering and postprocessing raw data in the queried format.
    • These features makes MetaModel ideal for tools that need to work on multiple models and multiple datastores. For instance Data Management tools, code/model generation tools and more.
    • Multiple optimizations and safe-guarding principles has been added to allow all datastores to work well. For instance:
      • Software Transactional Memory (STM) principles have been added to prevent race conditions when updating non-transactional datastores (like CSV files and Excel spreadsheets)
      • Optimal use of Prepared Statements and batch processing has been applied in the JDBC module.
      • An optimal fetch size (to minimize buffering) for JDBC databases is calculated based on metadata about the queried column data types.
      • The concept of “composite? datastores allow you to compose queries that span multiple datastores, eg. a database and a spreadsheet, or multiple files/databases in combination.

    As of version 3, MetaModel supports the full set of CRUD operations, whereas it was previously a read-only framework. Another big item in version 3 is the support for Java Collections and POJOs. These are a great help for eg. unittesting and user-driven tests of workflows etc.

    There’s a full overview of the changes in v. 3 here:

    The lead developer of the project, Kasper Sørensen, also posted a nice blog entry as an introduction to everyone new to MetaModel:

    We hope you will mention this significant release in the TSS news stream. On behalf of all developers involved in the release, we thank you in advance.

  2. // Batch #2: Update and delete a record
    .executeUpdate(new UpdateScript() {
    public void run(UpdateCallback cb) {
    .update("muppets").value("profession","Theatre host")
    .where("name").equals("Kermit the frog").execute();

    And you call that 'typesafe'? I don't think that this word means what you think it means.

    How does Metamodel compare with QueryDSL?

  3. As the blog also states:

    "We can do so either generically by traversing the graph of schemas, tables and columns - or by names if we already know what we are looking for..:"

    And what you're quoting is an example of the latter (by-name references, which are not type safe).

    But nevertheless such by-name references makes it easier to show an example in a few lines of code.

    In reality, the type safety of MetaModel is provided by the runtime discovery of the schema structure. So you will have table and column objects which you use for querying, and which are fetched by terms of object traversal, rather than just providing a name. This is essential when working on applications that span multiple data models.

    Simple usage scenario: Show all the tables to the user. He selects a table. Let the user select which columns/fields are of interest to him. Execute a query of those columns. This (and much more advanced scenarios) can all be done in a type safe way in MetaModel and without managing any string references building SQL strings. That's the point of this library.

    That brings me to QueryDSL - it is yet another tool for fixed-model querying. Basically an enrichment of existing ORMs. And that is exactly what MetaModel is not trying to be.