ATG10 Transient 属性

在ATG中 ,经常需要使用一些临时属性,这些属性是不需要持久化到数据库的。这些属性就是Transient属性。

哪些情况会使用到transient属性呢?

  • 用户自定义属性
  • 衍生属性
  • 一般的临时属性,如用户是否是登陆等

首先在Repository 的 定义文件中 需要创建一个和表平级的property tag.

指定属性名,数据类型和属性的类型以及是否可写或者可查询。一般的话是可写但是不可查询。

有些时候时都不允许。看情况而定:

<property name="enterpriseSiteGroupId" data-type="string" property-type="com.ngp.commerce.repository.NGPRetrieveProfileSiteGroupIdPropertyDescriptor"
          writable="false" queryable="false">
	  <attribute name="uiwritable" value="false"/>
</property>

其中<attribute> tag可以制定一些需要用到的属性。通常以键值对(name/value)形式出现。

然后需要写一个Java Class 去处理临时属性相关的东西,包括临时属性的取值方式。

/**
 * Retrieve Profile enterpriseSiteGroupId
 * @author: Nicky Zhang
 * @version: Sep 4, 2013
 */
public class NGPRetrieveProfileSiteGroupIdPropertyDescriptor extends RepositoryPropertyDescriptor {

    private static final String REALM_ID = "realmId";

    @Override
    public Object getPropertyValue(RepositoryItemImpl pItem, Object pValue) {

        if (pValue != null) {
            return pValue;
        }

        String realmId = (String) pItem.getPropertyValue(REALM_ID);

        if (StringUtils.isBlank(realmId)) {
            return null;
        }

        RepositoryItem item = NGPSiteGroupManager.getInstance().getEnterpriseSiteGroupIdByRealmId(realmId);

        if (item == null) {
            return null;
        }

        String enterpriseSiteGroupId = item.getRepositoryId();

        return (StringUtils.isBlank(enterpriseSiteGroupId)) ? realmId : enterpriseSiteGroupId;
    }
}

 然后在使用的时候,直接用property 相关的Item 去处理。返回的值就是该属性的值。

有是有我们还需要使用一些衍生属性:

比如针对一个item-descriptor 有个属性 需要判断当前员工的消费额度,如果员工的消费额度为空就使用部门的消费额度。

<property name="spendingLimit" writable="false">
    <derivation>
        <expression>empSpendingLimit</expression>
        <expression>department.spendingLimit</expression>
    </derivation>
</property>

 expression 就是代表的就是相关的属性。这些属性是从相同item下其余property属性。

猜你喜欢

转载自nicky19870612.iteye.com/blog/1936532
今日推荐