EO的生命周期:
了解EO的生命周期需要从EO的几种操作动作来理解;
创建entity row:状态为NEW
查找entity row:状态为UNMODIFIES
更新entity row:状态为MODIFIES
删除entity row:状态为DEADED
事务提交:DEAD
1 有一种场景,有时我们需要控制EO中某些属性是只读的:
a:首先通过row拿到entity
b:然后通过entity拿到属性
c:设置属性为只读状态:
DepartmentImpl impl= (DepartmentImpl ) r.getEntity(0);
EntityDefImpl entityDefImpl = impl.getDefinitionObject();
String[] atts=impl.getAttributeNames();
for(String att:atts){
AttributeDefImpl attributeDefXm = entityDefImpl.getAttributeDefImpl(att);
attributeDefXm.setUpdateableFlag(AttributeDef.UPDATEABLE);
}
2 获取EO的状态:
public String getRowStatus(Row row) {
if (row != null) {
JobsViewRowImpl rwImpl = (JobsViewRowImpl)row;
String rwStatus = translateStatusToString(rwImpl.getEntity(0).getEntityState());
return rwStatus;
}
return null;
}
private String translateStatusToString(byte b) {
String ret = null;
switch (b) {
case Entity.STATUS_INITIALIZED:
{
ret = "Initialized";
break;
}
case Entity.STATUS_MODIFIED:
{
ret = "Modified";
break;
}
case Entity.STATUS_UNMODIFIED:
{
ret = "Unmodified";
break;
}
case Entity.STATUS_NEW:
{
ret = "New";
break;
}
}
return ret;
}
3 EO中获取属性原始值方法:
a 公共的方法:
EntityImpl::getAttribute(attrIndex,EntityImpl.ORIGINAL_VERSION)
b: 需要override的方法:
EntityImpl::getPostedAttribute(int index)