MJORM (mongo-java-orm) - 一个MongoDB的Java ORM 框架

jopen 11年前

该项目旨在为MongoDB和Java提供强大的查询API和ORM框架。这个项目的目标是:

  • 实现MongoDB驱动的DBObjects与POJOs之间的对象关系映射
  • 使其更容易编写可测试MongoDB的数据访问代码
  • 提供更高级别的MongoDB API来实现一些常见任务
  • 易于Spring框架集成
  • 提供一个基于XML的ORM框架
  • 提供一个基于注释的ORM框架

特性包括:

  • XML and annotation based mapping configuration for POJOs
  • Automatic DBObject to POJO (and vica verca) conversion
  • XML and JavaScript based Map\Reduce configuration and helper classes
  • High level query API via the MongoDao
  • Lower level criteria query API via DaoQuery and DaoModifier
  • MQL (MJORM query language. aka "Michael") a DSL for querying mongo similar to SQL
  • Easy integration with the Spring Framework

package com.googlecode.mjorm;    @Entity  public class Person {          private String id;          private String firstName;          private String lastName;          private Address address;            @Id          @Property          public String getId() { return id; }          public void setId(String id) { this.id = id; }            @Property          public String getFirstName() { return firstName; }          public void setFirstName(String firstName) { this.firstName = firstName; }            @Property          public String getLastName() { return lastName; }          public void setLastName(String lastName) { this.lastName = lastName; }            @Property          public Address getAddress() { return address; }          public void setAddress(Address address) { this.address = address; }            }    @Entity  public class Address {          private String street;          private String city;          private String state;          private String zipCode;            @Property          public String getStreet() { return street; }          public void setStreet(String street) { this.street = street; }            @Property          public String getCity() { return city; }          public void setCity(String city) { this.city = city; }            @Property          public String getState() { return state; }          public void setState(String state) { this.state = state; }            @Property          public String getZipCode() { return zipCode; }          public void setZipCode(String zipCode) { this.zipCode = zipCode; }  }
// connect to mongo  Mongo mongo = new Mongo(new MongoURI(uri)); // 10gen driver    // create object mapper and add classes  AnnotationsDescriptorObjectMapper objectMapper = new AnnotationsDescriptorObjectMapper();  mapper.addClass(Person.class);  mapper.addClass(Address.class);    // create MongoDao  MongoDao dao = new MongoDaoImpl(mongo.getDB("dbName"), objectMapper);

项目主页:http://www.open-open.com/lib/view/home/1372746902675