MJORM (mongo-java-orm) - 一个MongoDB的Java ORM 框架
该项目旨在为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);
本文由用户 jopen 自行上传分享,仅供网友学习交流。所有权归原作者,若您的权利被侵害,请联系管理员。
转载本站原创文章,请注明出处,并保留原始链接、图片水印。
本站是一个以用户分享为主的开源技术平台,欢迎各类分享!