yInstancesIterator(getDBTransaction());
Number currentHeaderId = getHeaderId();
while ( fastIterator.hasNext() )
{
PurchaseOrderLineEOImpl cachedLine = (PurchaseOrderLineEOImpl)fastIterator.next();
Number cachedHeaderId = cachedLine.getHeaderId();
// If we find a match, we're done. Don't forget to look ONLY for lines
// for this header... The entity cache can include lines for other headers
// also.
If ((cachedHeaderId != null) && (cachedHeaderId.compareTo(currentHeaderId) == 0 ))
{
return;
}
}
// We haven't found any matches in the cache yet, so now we need to check
// the database...
// In this example, we're illustrating the use of the association between the
// header and its lines to iterate through all the shipments. This will
// check both the cache and the database, and will bring all the rows
// into the middle tier.
// Note that this looks only at lines for this
// header so we don't need to filter our results, so it is convenient.
RowIterator linesIterator = getPurchaseOrderLineEO();
if (!(linesIterator.hasNext()))
{
throw new OARowValException(OARowValException.TYP_ENTITY_OBJECT,
getEntityDef().getFullName(),
getPrimaryKey(),
"ICX", // Message product short name
"FWK_TBX_T_PO_NO_LINES"); // Message name
}
} // end checkLineExists()
实体状态
每一个实体对象都有一个关联的”实体状态”,它描述了关联了潜在的数据库数据和事务的状态。你可以在你的代码通过调用getEntityState()来测试这些状态。
小建议:BC4J可以自动从实体缓存移除实体对象,如果它的状态是STATUS_DEAD,因此你不需要在你的代码里担心手工排除对象如果你在查找”好”的对象。
l STATUS_NEW 在当前事务中实体对象是新建的。
l STATUS_DELETED 来自于数据库中的实体对象,并且已在当前事务中被删除了。
l STATUS_MODIFIED-来自于数据库中实体对象,并且在当前事务中已被修改了。
l STATUS_UNMODIFIED-来资源数据库中的实体对象,并且没有被修改过,或者被修改过并且这些修改已被提交。
l STATUS_DEAD-实体对象在当前事务是新建的,并且已经被删除了。
l STATUS_INITIALIZED-实体对象是”临时”状态并且不会被提交或者验证。