MongoDB對象映射框架 Morphia

jopen 12年前發布 | 17K 次閱讀 MongoDB 持久層框架

Morphia 是一個輕量級的類型安全的 Java 類庫,用來將在 MongoDB 和 Java 對象之間進行映射。

  • Easy to use, and very lightweight; reflection is used once per type and cached for good performance.
  • Datastore and DAO<T,V> access abstractions, or roll your own...
  • Type-safe, and Fluent Query support with (runtime) validation
  • Annotations based mapping behavior; there are no XML files.
  • Extensions: Validation (jsr303), and SLF4J Logging
@Entity("employees")
class Employee {
  @Id ObjectId id; // auto-generated, if not set (see ObjectId)
  String firstName, lastName; // value types are automatically persisted
  Long salary = null; // only non-null values are stored

@Embedded Address address;

@Reference Employee manager; // refs are stored*, and loaded automatically @Reference List<Employee> underlings; // interfaces are supported

@Serialized EncryptedReviews; // stored in one binary field

@Property("started") Date startDate; //fields can be renamed @Property("left")Date endDate;

@Indexed boolean active = false; //fields can be indexed for better performance @NotSaved string readButNotStored; //fields can read, but not saved @Transient int notStored; //fields can be ignored (load/save) transient boolean stored = true; //not @Transient, will be ignored by Serialization/GWT for example.

//Lifecycle methods -- Pre/PostLoad, Pre/PostSave... @PostLoad void postLoad(DBObject dbObj) { ... } }</pre>

項目主頁:http://www.baiduhome.net/lib/view/home/1328449682952

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!