对象序列化和持久化内容摘要:
ses) 2020/11/4 Institute of Computer Software Nanjing University 40 Approaches to manipulate persistent objects Persistence mechanisms from programming languages Relational databases Objectoriented databases 2020/11/4 Institute of Computer Software Nanjing University 41 Persistence from programming languages Mechanisms for storing objects in files and retrieving them Simple objects: . integers, characters conventional methods usable Composite objects: contain references to other objects Persistence Closure principle: Any storage and retrieval mechanism must handle the object and all its dependents. otherwise: dangling references 2020/11/4 Institute of Computer Software Nanjing University 42 对象结构的存储与提取 对象持久化的难点之一: 对象之间的引用 2020/11/4 Institute of Computer Software Nanjing University 43 对象结构的存储与提取 需持久化整个对象引用闭包 Persistence closure Java的 serialization规则 缺省规则:非 static 非 transient 的数据成员 用户定义 class List implements Serializable { List next。 private static final ObjectStreamField[] serialPersistentFields = {new ObjectStreamField(next, )}。 } 2020/11/4 Institute of Computer Software Nanjing University 44 对象结构的存储与提取 闭包可能太大 小对象引用(共享的)大对象 2020/11/4 Institute of Computer Software Nanjing University 45 对象结构的存储与提取 Java 的 transient 修饰子 Transient fields 不被序列化 Static fields 也不被序列化 开发者负责维护 2020/11/4 Institute of Computer Software Nanjing University 46 Schema evolution Fact: Classes change Problem: Objects are stored of which class descriptions have changed Schema evolution: At least one class used by the retrieving system differs from its counterpart stored by the storing system. Object retrieval mismatch (Object mismatch): The retrieving system retrieves a particular object whose own generating class was different in the storing system. No fully satisfactory solution 2020/11/4 Institute of Computer Software Nanjing University 47 Different approaches Naive, extreme approaches: Forsake previously stored objects Over a migration path from old format to new a onetime, en masse conversion of old objects not applicable to a large persistent store or to one that must be available continuously Most general solution: Onthefly conversion Note: We cover only the retrieval part. Whether to write back the converted object is a separate issue. 2020/11/4 Institute of Computer Software Nanjing University 48 Onthefly object conversion Three separate issues: Detection: Catch object mismatch Notification: Make retrieving system aware of object mismatch Correction: Bring mismatched object to a consistent state Make it a correct instance of the new class version 2020/11/4 Institute of Computer Software Nanjing University 49 Detection Detect a mismatch between two versions of an object‟s generating class Two categories of detection policy: Nominal approach: Each class version has a version name Central registration mechanism necessary Structural approach: Deduce class descriptor from actual class structure Store class descriptor Simple detection: pare class descriptors of retrieved object with new class descriptor 2020/11/4 Institute of Computer Software Nanjing University 50 Detection: Structural Approach What does the class descriptor need to contain? Tradeoff between efficiency and reliability Two extreme approaches: C1: class name C2: entire class text (. abstract syntax tree) Reasonable approaches: C3: class name, list of attributes (name and type) C4: in addition to C3: class invariant 2020/11/4 Institute of Computer Software Nanjing University 51 Notification What happens when the detection mechanism has caught an object mismatch? Language level mechanism Class ANY could include a procedure: correct_mismatch is Handle object retrieval mismatch. local exception: EXCEPTIONS do create exception („„[ Routine failure: Object mismatch during retrieval ]‟‟) end 2020/11/4 Institute of Computer Software Nanjing University 52 Correction How do we correct an object that caused a mismatch? Current situation: Retrieval mechanism has created a new object (deduced from a stored object with same generating class) A mismatch has been detected new object is in temporary (maybe inconsistent) state 2020/11/4 Institute of Computer Software Nanjing University 53 Correction 增加 attribute 删除 attribute 2020/11/4 Institute of Computer Software Nanjing University 54 Attribute was not in stored version. Field is initialized to default value of attribute type Stored version had a field. New version has removed attribute. Attributes have not changed. Correction correct_mismatch is Handle object retrieval mismatch by correctly setting up balance. do balance := ensure consistent: balance = end 2020/11/4 Institute of Computer Software Nanjing University 55 deposits withdrawals balance 900 100 200 240 300 new field (initialized to default value) old fields Wrong! 维护不变式 自动对象转换: Java serialVersionUID 自动定义 (根据类文件生成) 1. Class name 2. The class modifiers 3. The name of each interface 4. For each field of the class (except private static and private transient fields): The name of the field The modifiers of the field The。对象序列化和持久化
相关推荐
切相关,取得的自主知识产权为主业生产经营所必需。 三、成功申办高新技术企业资格的关键点 (三年一个周期) 三、成功申办高新技术企业资格的关键点 (三年一个周期) (二)具备持续研发能力是成功申办、维持高新技术企业资格的基石。 持续技术创新 —— 研发成果、新产品、新技术。 持续研发投入 —— 研发项目、研发立项、研发过程; 研发成果 —— 核心自主知识产权与主业密切相关, 且为主业经营所需;
资料来源:招商研究 东软股份 强烈推荐 A 重点公司 软件及系统集成国内市场规模第一,国际知名度较高。 国内规模最大的软件及系统集成企业 , 在联通 、 社保 、 烟草 、 电子政务等领域市场占有率领先 独特外资股东背景,为外包业务扩展提供先天优势 阿尔派( Alpine)、东芝、飞利浦 已经形成了稳定的客户群,成为长期发展的可靠保证 东软在嵌入式
取能源 (能源 ) 中國 工業奇蹟 (工業發展 ) 日本 富與貧 (發展與互相依賴 ) —— 初中地理課程 —— 優點 內容生活化 提高學習興趣 較易培養共通能力與價值觀 初中地理課程 —— 不足 個案研習和議題結構在一定程度上影響課程的學科知識完整性 2020高中地理課程 主題部分 議題部分 氣候 氣候異常 地貌與內營力作用 糧食與饑荒 地貌與外營力作用 自然災害 農業
调节手段可以采用 在回水管上设调节阀(手动), 方便每组立管的流量分配。 建筑物热力入口部分 八、热力入口的其它要求 1)温度计采用 双金属表盘温度计 ,并且安装时应注意其安装深度满足要求。 2)温度计、压力表的 量程合适 ,安装位置应便于观察。 3)供、回水管均设 泄水阀门 ,建议采用 DN25球阀。 4) Y型过滤器应水平安装。
的存在。 瓶子被压扁表明力可以改变物体的。 答案是“大气压”,“形状”。 普遍的错误答案有“空气”、“压强”、 “力”等;“外形”、“体型”、“体积”、“原形”、“扁度”等。 例 6.(海南 2020年物理中考卷 12题)(电磁起重机)工作的时候是利用了 效应,手机通话是利用 传递信息。 答案是 “ 电流的磁 ” , “ 电磁波 ”。 普遍的错误答案有 “ 磁 ” 、“ 磁化 ” 、 “ 磁力