【第一章 Design】 2 Cayenne 持久化对象生存期

来源:互联网 发布:中国对印尼的报复 知乎 编辑:程序博客网 时间:2024/04/28 06:36

持久化对象的生存期可以描述为可以相互转化的几种状态,并且预定义了整数型的常量值,定义在org.apache.cayenne.PersistenceState 类中。在应用程序和持久化对象或者Cayenne上下文交互时,状态发生变化。无论什么时候状态发生了变化,Cayenne会调用setPersistenceState()方法,自动更新所有受到影响的对象的persistenceState的属性值。

 

 

新建对象的状态变化:

自动获取或者提交对象状态变化:

预定义的几种状态:

状态 值描述TRANSIENT1The object is not registered in a DataContext and will not persist.NEW2The object is freshly registered in a DataContext, but has not been persisted to the database (there is no matching database record).COMMITTED3The object is registered in a DataContext and has been persisted to the database (there is a matching database record).MODIFIED4The object is registered in a DataContext and there is a matching database record and the object has been modified in memory, but the changes have not yet been persisted back to the database.HOLLOW5The object is registered in a DataContext and has a corresponding database row, but the values have not yet been fetched from the database. The values will be fetched/faulted from the database automatically by Cayenne if any fields are requested from the object.DELETED6The object is registered in a DataContext and will be deleted from the database upon commit.


 

原文:

http://cayenne.apache.org/doc30/persistent-object-lifecycle.html