noSQL数据库中的数据/对象一致性

时间:2018-02-04 05:11:54

标签: java google-app-engine nosql google-cloud-datastore consistency

当我开发一个非常大的项目时,我遇到了一个问题。假设我在no-sql db中存储了一个对象,比如Google Cloud Datastore,但后来我在这个类中添加了一个新字段,然后一旦我进行查询并得到这个对象,新字段的价值是多少?它取决于序列化程序或数据库或编程语言吗? 例如,在java:

public class Car{
    private int numOfDoors;
    private Set<String> tags;
    private boolean condition;
    public Car(int nod, Set<String> tags, boolean cod){
         numOfDoors = nod;
         this.tags = tags;
         condition = cod;
    }
    public Set<String> getTags(){
         return tags;
    }
}

然后我将对象car1保存到数据存储区,但之后我更新了我的代码。

getTags()

当我刚刚更新代码并调用get to刚刚从Datastore获取的对象时,如果我调用private Set<String> tags = new HashSet<>(); 会发生什么? 如果标签和条件不在构造函数中会怎样?像:

import UIKit

class ProtocolDescriptionViewController: UIViewController {

    @IBOutlet weak var protocolTitle: UILabel!
    @IBOutlet weak var protocolDescription: UILabel!

    var proto = ""
    var isScrollEnable = true

    override func viewDidLoad() {
        super.viewDidLoad()

        protocolTitle.text = proto
/* ["Atrial Fibrillation with RVR","Bradycardia/AV Blocks","Cardiac
    Arrest AED","Cardiac Arrest Asystole/PEA","Chest Pain/ACS","ICD 
    Deactivation","LVAD","PVC's with Chest Pain","PSVT","Stemi 
    Alert","Tor Medical","V-Fib/Pulseless V-Tach","Wide Complex 
    Tachycardia"]
*/

        if  proto == "Atrial Fibrillation with RVR" {
            protocolDescription.text = """
Pt must have ONE OR MORE of the following:
    ►chest pain
    ►dyspnea
    ►altered mental status
    ►hypotension
    ►ischemic changes
->Provide oxygen via nasal cannula or non-rebreather to maintain oxygen
  saturation of 93-95%, unless COPD (89-92%)
->IV NS
    ->Treat any acute underlying problems
    - ASA, NTG for chest pain—refer to Chest Pain protocol
    - NTG for pulmonary edema—refer to CHF/Pulmonary Edema protocol
    - Assess for low volume state and, if suspected, administer IV NS
    500 ml bolus
If patient remains symptomatic and rate above 120, CONTACT MEDICAL
CONTROL to discuss and give if directed:
->Magnesium Sulfate 2 gm in NS 100 ml IV infused over 2-10 minutes
"""
    }
        if proto == "Bradycardia/AV Blocks" {
        protocolDescription.text = """
Patients must have one or more of the following:
        ► Chest pain ► Hypotension ► Altered mental status
        ► Dyspnea ► Ischemic changes
->Provide oxygen via nasal cannula or non-rebreather to maintain oxygen
 saturation of 93-95%, unless COPD (89-92%)
->IV NS KVO
    -If patient is believed to be hypovolemic, administer 250ml fluid
 bolus, then re-evaluate

"""
}

删除字段怎么样? 谢谢!

1 个答案:

答案 0 :(得分:0)

在Google云端文档的Defining Data Classes with JDO中,特别是对象Fields and Entity Properties部分,解释说:

  

如果数据存储区实体已加载到对象中但没有   对象的一个​​字段的属性和字段的类型是a   可空的单值类型,该字段设置为null。当对象   保存回数据存储区,null属性设置在   数据存储区为空值。如果该字段不是可以为空的值   类型,加载没有相应属性的实体抛出   例外....

因此,基本上修改后的类中新添加的属性将设置为null,因为保存的实体没有它们。