OSSJ Entity RI 활용 100%
(100%라고 이름붙여놓기는 쑥수럽네요~ 차차 업데이트하면서 100% 만들죠...^^;)
- 구현하는 entity에 맞는 상위 implementation을 extend 한다.(예:ossj.common.cbe.EntityValueImpl) : RI에서 이미 구현되어 있는 유용한 기능을 활용할수 있게됩니다.
- 구현하고자 하는 entity 의 interface를 implement 한다.(예:javax.oss.cbe.product.ProductSpecificationValue) : OSSJ규격에 맞는 entity가 됩니다. 하지만 OSSJ API만으로는 부족하기 때문에 확장할 필요가 있습니다.
- 예: public class ProductSpecificationValueImpl extends ossj.common.cbe.EntitySpecificationValueImpl implements ProductSpecificationValue{}
- private static final String[] attributeNames와 private static final String[] settableAttributeNames를 정의합니다. 각 인터페이스에는 기본적인 attribute의 name들이 정의되어 있습니다. 필요에 따라 추가하여 정의하면 됩니다.
- 예: private static final String[] attributeNames = {
ProductSpecificationValue.BRAND,
ProductSpecificationValue.DESCRIPTION,
ProductSpecificationValue.LIFE_CYCLE_STATE,
- set method 안에 setDirtyAttribute(setting되는 attribute이름)를 추가합니다.(예:setDirtyAttribute(ProductSpecificationValue.NAME);)
- 이와 같이 하면 최상위 구현체인 AttributeAccessImpl의 기능들을 사용할수 있게 됩니다. 예: setting이 된 모든 attribute 들의 Map을 return하는 getAllPopulated method등.
- 다른방법: 또는 각 entity의 RI를 직접 상속하고 필요에 따라 method를 overide하는 방법도 있습니다. 예 : public class ProductSpecificationValueImpl extends ossj.common.cbe.product.ProductSpecificationValueImpl{}
Hibernate 기반 RI 구현시 추가 참고사항
- OSSJ Entity Value는 모두 EntityKey를 갖게 됩니다. Hibernate은 일반적인 경우 key를 자동생성하기 때문에... 자동으로 EntityKey 객체로 생성해서 설정하면 best인데 아직 그방법을 터득하지 못했습니다.. (가능은 하것 같은데 study가 더 필요할듯...)
- 따라서 편법으로 아래와 같이 Hibernate이 primary key를 설정할때 EntityKey가 생성되도록 하면 되겠습니다. 여기서는 id 가 primary key 입니다.
public void setId(Long value) {
setDirtyAttribute("id");
ManagedEntityKey key = new ProductSpecificationKeyImpl(); // 해당 key 구현체
key.setPrimaryKey(value);
setManagedEntityKey(key);
this.id = value;
}
공통 Entity 처리 method 활용방법
위에 설명된 것과 같이 OSSJ RI를 활용하고 Hibernate 기반으로 구현된 entity의 경우 아래와 같이 공통 method들을 활용할수 있습니다.
JVTSessionPojo jvtsession = new JVTSessionPojo();
ProductOfferingPriceValueImpl price = (ProductOfferingPriceValueImpl) inventory.makeEntityValue(ProductOfferingPriceValue.VALUE_TYPE);
price.setDescription("testest");
jvtsession.createEntityByValue(price);
마찬가지로 getEntityValuesByTemplate도 사용할수 있습니다.
makeEntityValue는 아래와 같이 구현되어 있으므로 entity 추가시 if/else 문에 추가를 해줘야 합니다.
public EntityValue makeEntityValue(String valueType) {
EntityValue value = null;
if(ProductValue.VALUE_TYPE.equals(valueType)){
}if(ProductOfferingValue.VALUE_TYPE.equals(valueType)){
}if(ProductOfferingPriceValue.VALUE_TYPE.equals(valueType)){
value = new ProductOfferingPriceValueImpl();
}
return value;
}
이외에 JVTSession쪽에 변경없에 entity에 대한 처리가 가능해지며 이부분도 Spring과 같은 IoC Container를 쓰게 되면 변경없이 사용할 수 있게 됩니다.
Comments (0)
You don't have permission to comment on this page.