Db4o的级联(Activation-Concept)概念
2012-01-16 13:47
162 查看
场景:在地球上任意找一个人然后让他找出他认识的任意五个人,这五个人成为初始条件……递归。
结果:通过这样的查询方式会把地球上的每个人都找出来。
假设:任何数据库执行这样的操作恐怕没有不崩溃的。
现实:Db4o数据库的默认查询方式就是这样的!查询一个对象的时候如果这个对象和其他对象有关联那么被关联的对象也一并查询出来。
Db4o通过 引入Activation-Concept理念 来解决上面的问题。解决问题的思路:限定级联的“级”数。
关键字:“级”,depth
Db4o已经使用了默认查询级联“级数”是 4 级——不包括自身在内。
改变级联“级数”的方法
db4o向数据库中存储未发现有“级数”限制
db4o级联更新要明确指定是否可级联更新,默认不能级联更新。
看看Db4o官方教程上是怎么说的 Db4o Reference book (java) Activation
Db4o的官方教程是一个“家谱”的例子
以上是不设置级联“级数”的场景
设置级联“级数”的场景
结果:通过这样的查询方式会把地球上的每个人都找出来。
假设:任何数据库执行这样的操作恐怕没有不崩溃的。
现实:Db4o数据库的默认查询方式就是这样的!查询一个对象的时候如果这个对象和其他对象有关联那么被关联的对象也一并查询出来。
Db4o通过 引入Activation-Concept理念 来解决上面的问题。解决问题的思路:限定级联的“级”数。
关键字:“级”,depth
Db4o已经使用了默认查询级联“级数”是 4 级——不包括自身在内。
改变级联“级数”的方法
private static void increaseActivationDepth() { // #example: Increase the activation depth to 10 EmbeddedConfiguration configuration = Db4oEmbedded.newConfiguration(); configuration.common().activationDepth(10); ObjectContainer container = Db4oEmbedded.openFile(configuration,DATABASE_FILE); // #end example try { Person joelle = queryForJoelle(container); Person julia = joelle.getMother().getMother().getMother().getMother().getMother(); boolean isActivated = container.ext().isActive(julia); System.out.println("Is activated? "+ isActivated); } finally { container.close(); } }
private static EmbeddedConfiguration moreActivationOptions() { // #example: More activation options EmbeddedConfiguration configuration = Db4oEmbedded.newConfiguration(); // At least activate persons to a depth of 10 configuration.common().objectClass(Person.class).minimumActivationDepth(10); // Or maybe we just want to activate all referenced objects configuration.common().objectClass(Person.class).cascadeOnActivate(true); // #end example return configuration; }
db4o向数据库中存储未发现有“级数”限制
db4o级联更新要明确指定是否可级联更新,默认不能级联更新。
//修改数据库配置对每个操作的级联更新级数设置为2 EmbeddedConfiguration configuration = Db4oEmbedded.newConfiguration(); configuration.common().updateDepth(2); //对“类”设置级联: EmbeddedConfiguration configuration = Db4oEmbedded.newConfiguration(); // Update all referenced objects for the Driver class configuration.common().objectClass(Driver.class).cascadeOnUpdate(true);
看看Db4o官方教程上是怎么说的 Db4o Reference book (java) Activation
Db4o的官方教程是一个“家谱”的例子
以上是不设置级联“级数”的场景
设置级联“级数”的场景
相关文章推荐
- 译:C#面向对象的基本概念 (Basic C# OOP Concept) 第三部分(多态,抽象类,虚方法,密封类,静态类,接口)
- Photon——Lite Lobby Concepts Lite Lobby概念
- c++ 概念及学习/c++ concept&learning(二)
- SQL 级联更新,级联删除的概念
- CSS样式权重的级联cascade的概念
- MyBatis级联探讨第一篇——概念和模型
- 高级插件概念——Advanced Plugin Concepts
- XBRL简介 - 1 - 概念 (Concept)
- Math concepts / 数学概念(转)
- 基本概念 Basic concepts
- 共享概念-面向概念编程 share semantic concept-oriented programming
- 译:C#面向对象的基本概念 (Basic C# OOP Concept) 第二部分(封装,抽象,继承)
- 概率论基础概念总结 Basic Concepts in Statistics
- 漂亮的桌面概念时钟-XinBSConceptClock
- Concept-算法-闰年平年概念简介
- concept_相关概念
- CSS样式权重的级联cascade的概念
- Oracle Concept 的一些笔记 -- extent的概念
- POC [Proof of Concept] 原型 / 概念证明
- Basic Orchard Concept Definitions—Orchard基础概念定义