精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2010-04-19
最后修改:2010-04-19
这是一个真实案例,本周在工作中发现的,案例情况比较极端,因此显得很滑稽很搞笑。但是深入一下,还是有些东西值得思考。
//
1. get pk as method parameter
public TrafficProfile createTrafficProfile( long serviceCapabilityPrimaryKey, String serviceProviderId, String applicationId) throws NotFoundException { // 2. do database query to get serviceCapabilityProfile by pk ServiceCapabilityProfile serviceCapabilityProfile = new ServiceCapabilityProfilePreLoadFullSerializableImpl(getContext(), serviceCapabilityPrimaryKey); // 3. generate key using obj serviceCapabilityProfile String key = buildTrafficProfileCacheKey(serviceProviderId, applicationId, serviceCapabilityProfile); TrafficProfile trafficProfile = (TrafficProfile) trafficProfileCache.get(key); // 5. found in cache and return if ((trafficProfile != null )) { return trafficProfile; } trafficProfile = new TrafficProfilePreLoadFullSerializableImpl(getContext(), serviceCapabilityProfile, serviceProviderId, applicationId); trafficProfileCache.put(key, trafficProfile); return trafficProfile; } // 4. notice: in fact only pk is used private String buildTrafficProfileCacheKey(String serviceProviderId, String applicationId, ServiceCapabilityProfile serviceCapabilityProfile) { return serviceCapabilityProfile.getServiceCapabilityPrimaryKey() + " , " + serviceProviderId + " , " + applicationId; }
pk
---->
get serviceCapabilityProfile from database by pk
--->
get pk by serviceCapabilityProfile.getServiceCapabilityPrimaryKey();
//
parameter is serviceCapabilityProfile obj
public TrafficProfile createTrafficProfile( ServiceCapabilityProfile serviceCapabilityProfile, String serviceProviderId, String applicationId) throws NotFoundException { // pass to buildTrafficProfileCacheKey() is obj, not pk String key = buildTrafficProfileCacheKey(serviceProviderId, applicationId, serviceCapabilityProfile);
声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |
浏览 1432 次