`
leonzhx
  • 浏览: 786829 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

Datastore

阅读更多

1.   The Datastore interface provides type-safe methods for accessing and storing your javobjects in MongoDB. It provides get/find/save/delete methods for working with your java objects.

 

2.   get methods return instance(s) of your entities by its @Id . It is really just a short-cut for using find(...) with a criteria of id values. get methods return instance(s) of your entities by its @Id :

Hotel hotel = ds.get(Hotel.class, hotelId);
 

 

 

3.   The find methods are a lightweight wrapper around using a Query (as with createQuery() ). As a wrapper it will return a Query , which also supports Iterable<T> and the QueryResults interface.

//use in a loop
for(Hotel hotel : ds.find(Hotel.class, "stars >", 3))
   print(hotel);

//get back as a list
List<Hotel> hotels = ds.find(Hotel.class, "stars >", 3).asList();

//sort the results
List<Hotel> hotels = ds.find(Hotel.class, "stars >", 3).sort("-stars").asList();

//get the first matching hotel, by querying with a limit(1)
Hotel gsHotel = ds.find(Hotel.class, "name", "Grand Sierra").get();

//same as
Hotel gsHotel = ds.find(Hotel.class, "name =", "Grand Sierra").get();
 

 

4.  The list of valid operators: ["=", "==","!=", "<>", ">", "<", ">=", "<=", "in", "nin", "all", "size", "exists"] . If no operator is used, "=" is assumed. "=" is the same as "==", "!=" is the same as "<>".

 

5.   @Id field is filled in for you (after the save ), if you didn't set it before you call save method.

 

6.   The delete method will delete items based on a Query , id, or an entity:

ds.delete(Hotel.class, "Grand Sierra Resort");
//use a query
ds.delete(ds.createQuery(Hotel.class).filter("pendingDelete", true));
 

 

7.   One of the underlying features in MongoDB is the ability to do some operations in an atomic fashion. The FindAndDelete method will find the first item, and delete it (while returning it).

Hotel grandSierra = ds.findAndDelete(ds.get(Hotel.class, "Grand Sierra Resort"));

 

8.   Updates are applied at the server and allow for complicated but very efficient (when compared to saving the whole entity again) update operations.

long now = System.currentTimeMillis();
UpdateOperations<User> ops = datastore.createUpdateOperations(User.class).set("lastLogin", now);

Query<User> query = datastore.createQuery(User.class).field(Mapper.ID_KEY).equal(id);

ds.update(query , ops);
     

9.   ensureIndexes and ensureCaps methods should be called after you have registered you entities with Morphia . It will then synchronously , by default, create your indexes, and capped collections. One option is call them each time you start your application, or via an administrative interface, or during a deployment script. It might be best to make sure indexes can be built in the background if there is already data . Doing this on an existing system, with existing indexes and capped collections, should take no time (and do nothing). If the collection isn't capped, or has different setting you will get an error in the logs, but nothing will be done to the existing collections.

ds.ensureIndexes(); //creates all defined with @Indexed
ds.ensureCaps(); //creates all collections for @Entity(cap=@CappedAt(...))
 

 

 

10.   If you have an index on a capped collection, then ensuring the index will create the collection uncapped if it did not already exist. So you need to call ensureCaps first.

分享到:
评论

相关推荐

    Android DataStore使用和封装

    在Android开发中,数据存储是不可或缺的一部分,DataStore是Google推出的一种新型持久化存储解决方案,旨在替代SharedPreferences。本文将深入探讨Android DataStore的使用方法及其封装技巧,旨在帮助开发者更好地...

    powerbulilder pb datastore实现步骤完整源码.docx

    在PowerBuilder(PB)开发中,DataStore是一个重要的对象,用于存储和操作数据库中的数据。在本示例中,我们详细探讨如何创建、查询、取值以及释放DataStore。 1. **创建DataStore**: 创建一个名为`ds_sale`的...

    PB虛擬datastore用法

    ### PB虚拟DataStore用法详解 #### 一、概述 PowerBuilder(PB)是一种用于开发企业级客户端/服务器应用程序的快速应用开发工具。在PB中,DataStore是一种强大的功能,可以用来存储临时数据或者作为数据窗口的数据...

    Android中DataStore替代SharedPreferences

    【Android中的DataStore替代SharedPreferences】 Android开发者们长期以来一直依赖SharedPreferences作为轻量级的数据存储解决方案,它的简单易用性使其在小规模数据存储方面受到了广泛欢迎。然而,随着应用程序...

    Laravel开发-laravel-datastore

    "Laravel Datastore"在此上下文中可能指的是Laravel与Google Cloud Datastore的集成,这是一个NoSQL数据库服务,用于存储非结构化数据。在这个主题中,我们将深入探讨Laravel框架与Datastore的结合使用,以及相关的...

    matlab开发-datastore

    在MATLAB中,`datastore`是一个非常重要的数据管理工具,尤其对于数据分析和处理工作流程。这个工具允许用户高效地组织和操作大量数据,而无需将所有数据加载到内存中,这极大地提升了处理大型数据集的能力。在...

    Google Datastore for Java 文档摘录(四)

    **Google Datastore for Java 文档摘录(四)** 在这一部分,我们将深入探讨Google Datastore,这是一个在Java环境中使用的云数据库服务。Google Datastore是一个NoSQL文档数据库,提供了高可用性和可扩展性,适用...

    前端开源库-datastore-fs

    `datastore-fs` 是一个专为前端设计的开源库,它提供了一个数据存储的解决方案,并且集成了文件系统(FS)作为其后端。这个库允许开发者在前端应用中持久化地存储和检索数据,就像操作本地文件系统一样方便。下面...

    上传 文件到Google app engine datastore的Demo

    本示例主要关注如何将文件上传到Google App Engine的数据存储(Datastore)。数据存储是GAE的一个核心组件,它是一个NoSQL的键值对数据库,用于存储应用程序的数据。 在"上传文件到Google app engine datastore的...

    前端开源库-interface-datastore

    "interface-datastore"就是一个专注于数据存储接口的前端开源库。它旨在为前端项目提供一个标准化的数据管理机制,方便地进行数据的存取、更新和管理。下面将详细介绍这个开源库的核心特点、使用场景、主要功能以及...

    Google Datastore的JAR

    Google Datastore的JAR

    grails-datastore-gorm-plugin-support-2.0.4.RELEASE.zip

    《Grails Datastore GORM Plugin Support 2.0.4.RELEASE:开源项目的代码生成与Android MVC模式解析》 在IT行业中,开发高效且可维护的软件系统是至关重要的。Grails Datastore GORM Plugin Support 2.0.4.RELEASE...

    DataCleaner-csv-datastore-wizard-3.5.6.zip

    DataCleaner-csv-datastore-wizard-3.5.6.zip这个压缩包文件是DataCleaner工具的一个版本,专注于CSV数据存储和向导功能。DataCleaner是一款强大的开源数据清理工具,它允许用户通过直观的界面来探索、清洗和验证...

    Service Reporting and DataStore Diagram

    在IT管理领域,服务报告(Service Reporting)与数据存储(DataStore)图示是关键概念,它们对于理解和优化系统性能、资源监控以及数据分析至关重要。以下是对这些知识点的深入解析: ### 服务报告(Service ...

    Google Datastore for Java 文档摘录(一)

    《Google Datastore for Java 文档摘录(一)》 Google Datastore 是 Google 提供的一种分布式、高可扩展性、持久化的数据存储服务,它属于 Google Cloud Platform (GCP) 的一部分。对于 Java 开发者而言,Google ...

    Python库 | gcloud-rest-datastore-5.4.1.tar.gz

    本文将深入探讨“gcloud-rest-datastore-5.4.1”这一特定Python库,它是Google Cloud Datastore的一个客户端库,用于通过REST API与Datastore进行交互。 **Google Cloud Datastore** 是Google提供的一个NoSQL数据库...

    PyPI 官网下载 | google-cloud-datastore-1.7.1.tar.gz

    《PyPI官网下载 | google-cloud-datastore-1.7.1.tar.gz》 在Python的世界里,PyPI(Python Package Index)是最重要的软件仓库之一,它提供了大量的第三方库供开发者使用。今天我们要讨论的是其中的一个特定包——...

    Go-(AE|Cloud)Datastore一个Go封装

    Go-(AE|Cloud)Datastore是一个专门为Go编程语言设计的库,用于与Google App Engine (AE)或Google Cloud Datastore (Cloud Datastore)进行交互。这个封装提供了方便、高效的接口,使得开发者能够轻松地在Go应用中存储...

    前端开源库-datastore-level

    **前端开源库-datastore-level详解** 在Web应用开发中,数据管理是不可或缺的一部分。随着前端技术的发展,越来越多的复杂业务逻辑被转移到客户端,这使得在前端进行数据存储的需求日益增加。`datastore-level`就是...

    TimesTen学习笔记3(Timesten DataStore属性的说明)

    《深入理解TimesTen DataStore属性》 TimesTen是一款高性能、内存中的关系数据库管理系统,由甲骨文公司开发,主要用于实时事务处理和分析。在TimesTen的学习过程中,DataStore属性是理解其工作原理和优化数据库...

Global site tag (gtag.js) - Google Analytics