Class ItemType

All Implemented Interfaces:
Cacheable, Artifactizable, Optionable<ItemType>, Identifiable<Integer>, Serializable, ColumnAccessByName, ObjectModel, Persistent

public class ItemType extends BaseItemType implements Artifactizable, Optionable<ItemType>, Identifiable<Integer>, Cacheable
아이템 유형(ItemType) OM. ItemType 의 AttributeGroup, ItemTypeAttribute, template 유형 등을 관리한다.
Version:
$id: ItemType.java $Revision$, 03-06-22 7:20:39 AM KST
Author:
YounghoCho
  • Field Details

    • TEMPLATE_NAME_SUFFIX

      public static final String TEMPLATE_NAME_SUFFIX
      ItemType 을 db 에 추가할 때, 항상 등록하는 것과 pair 로 Template 을 같이 저장하기 위해 동일 이름 + suffix 를 사용한다.
      See Also:
  • Constructor Details

    • ItemType

      public ItemType()
      새로운 ItemType 인스턴스를 생성한다.
  • Method Details

    • getId

      public Integer getId()
      Identifiable implements
      Specified by:
      getId in interface Identifiable<Integer>
      Returns:
      The Id of the entity.
    • setId

      public void setId(Integer id)
      Identifiable implementation
      Specified by:
      setId in interface Identifiable<Integer>
      Parameters:
      id - The new Id of the entity
    • save

      public void save() throws Exception
      Stores the object in the database. If the object is new, it inserts it; otherwise an update is performed.

      TODO (숙제) : Workflow 실패 시 DB 정합성 문제

      현황 : Torque 7 이 DataSource 를 직접 관리하고 Spring 트랜잭션(@Transactional)은 사용하지 않는다. connection 없이 호출하는 save() 는 Torque 내부에서 Transaction.begin() → save(con) → commit() 으로 호출마다 개별 커밋된다. 따라서 이 메서드의 super.save() (insert) 는 Workflow 진입 전에 이미 커밋되고, Workflow(OMWorkflow.add → ArtifactizableFactory.createArtifact → ActivitySetManager ...) 안에서 생성되는 Artifact Item / ActivitySet / AttributeValue 등도 각자 커밋된다. Workflow 가 중간에 실패하면 ItemType row 뿐 아니라 일부 생성된 Artifact 까지 DB 에 남는다. (실제 사례: TransactionContext 에 itemTypeId/activitySetTypeId 가 없어 실패했을 때 typeId=407 row 가 남았다)

      검토한 해결 방안

      1. 보상 삭제 : Workflow 예외 시 catch 에서 ItemTypePeer.doDelete(this) + ItemTypeManager 캐시 제거 후 rethrow. 간단하지만 Workflow 가 중간까지 만든 Artifact/ActivitySet 은 남고, FK 때문에 delete 가 실패할 수 있다 (부분 조치).
      2. 하나의 DB 트랜잭션으로 묶기 (근본 해결, 장기 권장) : Torque 7 의 Transaction.setTransactionManager(...) 로 ThreadLocal 기반 TransactionManager 를 등록한다. 작업 단위(UnitOfWork)가 열려 있는 동안 모든 Transaction.begin() 이 같은 connection 을 공유하고 내부 commit() 은 무시, 바깥에서 한 번만 commit/rollback 한다. 예) UnitOfWork.run(() -> ItemTypeFactory.getFactory().add(name, isDefault, parentId)); 기존 save() 호출 코드 수정 없이 Workflow 전체가 원자적으로 처리되고 Attribute/Option 등 다른 add 에도 적용된다. 주의 : (a) DB rollback 시 Torque/JCS 캐시는 되돌려지지 않으므로 rollback 시 관련 캐시 제거 필요 (b) synchronized static 메서드가 많아 트랜잭션이 길어지면 lock 대기 증가 가능 (c) IDBroker 는 자체 connection 을 사용하므로 rollback 되어도 id 는 소모된다 (문제 아님) (d) 추후 이 TransactionManager 를 Spring 기반으로 구현하면 @Transactional 과 연결 가능. 착수 전 Torque 7 의 TransactionManager 인터페이스와 BaseObject.save() 실제 구현을 먼저 확인할 것.
      3. 상태 플래그 2단계 처리 : removed=true (또는 active=false) 로 insert → Workflow 성공 시 활성화. 실패 row 는 화면에 노출되지 않고 배치로 정리 가능. 단 모든 조회/이름 중복 체크에서 플래그를 확실히 걸러야 한다.
      단기 보완 : super.save() 이전에 Workflow 에 필요한 TransactionContext 값(activitySetTypeId 등)을 사전 검증해서 실패가 예상되는 요청은 insert 자체를 하지 않도록 한다.

      Specified by:
      save in interface Persistent
      Overrides:
      save in class BaseItemType
      Throws:
      Exception - 저장 중 오류가 발생한 경우
    • isTemplateType

      public boolean isTemplateType()
      template 유형의 ItemType 인지 확인한다.
      Returns:
      true if parent itemType is active else false
    • getTemplateItemType

      public ItemType getTemplateItemType() throws TorqueException
      Gets the ItemType template for this ItemType. The template is a special type of ItemType.
      Returns:
      template ItemType
      Throws:
      TorqueException - 조회 중 오류가 발생한 경우
    • getItemTypeForTemplateType

      public ItemType getItemTypeForTemplateType() throws TorqueException
      Gets the implement ItemType for this template ItemType.
      Returns:
      template 이 구현하는 ItemType
      Throws:
      TorqueException - 조회 중 오류가 발생한 경우
    • getTemplateId

      public Integer getTemplateId() throws TorqueException
      Gets the id of the template that corresponds to the item type.
      Returns:
      template ItemType id
      Throws:
      TorqueException - 조회 중 오류가 발생한 경우
    • getDedupeSequence

      public int getDedupeSequence() throws Exception
      Gets the sequence where the dedupe screen fits between groups.
      Returns:
      dedupe 화면의 순서
      Throws:
      Exception - 조회 중 오류가 발생한 경우
    • hasItems

      public boolean hasItems() throws Exception
      Returns true if the item type has items associated with it.
      Returns:
      item 이 있으면 true
      Throws:
      Exception - 조회 중 오류가 발생한 경우
    • hasItems

      public boolean hasItems(Module module) throws Exception
      Returns true if the item type/module has items associated with it.
      Parameters:
      module - can be null
      Returns:
      item 이 있으면 true
      Throws:
      Exception - 조회 중 오류가 발생한 경우
    • getAttributeGroups

      public List<AttributeGroup> getAttributeGroups() throws TorqueException
      global itemType 의 attributeGroups 를 구한다. get all attribute groups including non active group
      Overrides:
      getAttributeGroups in class BaseItemType
      Returns:
      AttributeGroup 목록
      Throws:
      TorqueException - 조회 중 오류가 발생한 경우
    • getAttributeGroup

      public AttributeGroup getAttributeGroup(String name) throws TorqueException
      이름에 해당하는 AttributeGroup 을 구한다.
      Parameters:
      name - attributeGroupName
      Returns:
      AttributeGroup 없으면 null
      Throws:
      TorqueException - 조회 중 오류가 발생한 경우
    • getAttributeGroups

      public List<AttributeGroup> getAttributeGroups(boolean activeOnly) throws TorqueException
      get all active attribute groups by group order.
      Parameters:
      activeOnly - active 인 것만 구할지 여부
      Returns:
      attributeGroup list with ordered
      Throws:
      TorqueException - 조회 중 오류가 발생한 경우
    • getItemTypeAttributes

      public List<ItemTypeAttribute> getItemTypeAttributes()
      Gets associated all itemTypeAttributes including non active
      Overrides:
      getItemTypeAttributes in class BaseItemType
      Returns:
      itemTypeAttributes
    • getItemTypeAttributes

      public List<ItemTypeAttribute> getItemTypeAttributes(boolean activeOnly) throws Exception
      Gets associated attributes.
      Parameters:
      activeOnly - active 인 것만 구할지 여부
      Returns:
      ItemTypeAttribute 목록
      Throws:
      Exception - 조회 중 오류가 발생한 경우
    • getItemTypeAttributes

      public List<ItemTypeAttribute> getItemTypeAttributes(boolean activeOnly, String attributeType) throws TorqueException
      Gets associated attributes.
      Parameters:
      activeOnly - active 인 것만 구할지 여부
      attributeType - "all", "user", "nonUser" , "correlated", "typeid"
      Returns:
      ItemTypeAttribute 목록
      Throws:
      TorqueException - 조회 중 오류가 발생한 경우
    • getAttributes

      public List<Attribute> getAttributes(String attributeType) throws Exception
      Gets associated active attributes.
      Parameters:
      attributeType - "user", "nonUser", "correlated", "typeid", "all"
      Returns:
      Attribute 목록
      Throws:
      Exception - 조회 중 오류가 발생한 경우
      See Also:
    • getUserAttributes

      public List<Attribute> getUserAttributes() throws TorqueException
      gets a list of all of the active User Attributes in an item type.
      Returns:
      User Attribute 목록
      Throws:
      TorqueException - 조회 중 오류가 발생한 경우
    • getUserAttributes

      public List<Attribute> getUserAttributes(boolean activeOnly) throws TorqueException
      gets a list of all of the User Attributes in an item type.
      Parameters:
      activeOnly - active 인 것만 구할지 여부
      Returns:
      User Attribute 목록
      Throws:
      TorqueException - 조회 중 오류가 발생한 경우
    • has

      public boolean has(Attribute attribute)
      이 ItemType 에 attribute 가 등록되어 있는지 확인한다.
      Parameters:
      attribute - 확인할 Attribute
      Returns:
      true if this itemType has itemTypeAttribute
    • getItemTypeAttribute

      public ItemTypeAttribute getItemTypeAttribute(Attribute attribute) throws TorqueException
      ItemType 에 해당 Attribute 의 ItemTypeAttribute 정의가 되어있으면 해당 itemTypeAttribute 를 구하고 없으면 null 을 return
      Parameters:
      attribute - 대상 Attribute
      Returns:
      ItemTypeAttribute or null
      Throws:
      TorqueException - 조회 중 오류가 발생한 경우
    • getAvailableAttributes

      public List<Attribute> getAvailableAttributes(String attributeType) throws Exception
      Gets a list of all of the global Attributes that are not Associated with this item type
      Parameters:
      attributeType - attribute 유형
      Returns:
      Attribute 목록
      Throws:
      Exception - 조회 중 오류가 발생한 경우
    • has

      public boolean has(AttributeGroupType groupType) throws TorqueException
      이 ItemType 에 주어진 AttributeGroupType 과의 이름이 동일한 AttributeGroup 이 있는지 확인한다.
      Parameters:
      groupType - 확인할 AttributeGroupType
      Returns:
      있으면 true
      Throws:
      TorqueException - 조회 중 오류가 발생한 경우
    • createDefaultGroups

      public void createDefaultGroups() throws Exception
      Create default groups upon global item type creation.
      Throws:
      Exception - 처리 중 오류가 발생한 경우
    • getDefaultTextAttribute

      public Attribute getDefaultTextAttribute() throws Exception
      if an RMA is the chosen attribute for email subjects then return it. if not explicitly chosen, choose the highest ordered text attribute.
      Returns:
      the Attribute to use as the email subject, or null if no suitable Attribute could be found.
      Throws:
      Exception - 조회 중 오류가 발생한 경우
    • getRequiredAttributes

      public List<Attribute> getRequiredAttributes() throws TorqueException
      Array of Attributes which are active and required by this itemtype. Whose attribute group's are also active.
      Returns:
      an List of Attribute objects
      Throws:
      TorqueException - 조회 중 오류가 발생한 경우
    • getAttributeGroup

      public List<AttributeGroup> getAttributeGroup(Module module, Attribute attribute) throws TorqueException
      attribute 가 속한 AttributeGroup 목록을 구한다.
      Parameters:
      module - if null than get from global ItemType
      attribute - 대상 Attribute
      Returns:
      attributeGroup list
      Throws:
      TorqueException - 조회 중 오류가 발생한 경우
    • hasAncestor

      public boolean hasAncestor(String name)
      부모중에 이름이 있는지
      Parameters:
      name - 찾을 부모 ItemType 이름
      Returns:
      true/false
    • getChildren

      public List<ItemType> getChildren()
      children itemtype 들을 구한다.
      Returns:
      자식 ItemType 목록
      Throws:
      RuntimeException - 조회 중 오류가 발생한 경우
    • getProperty

      public ItemTypeProperty getProperty()
      Global ItemType 의 특성을 정의한다.
      Returns:
      ItemTypeProperty
    • populateProperty

      protected static final List<ItemTypeProperty> populateProperty()
      Loading system wide ItemType Display Properties
      Returns:
      ItemTypeProperty 목록
    • initialize

      public void initialize() throws Exception
      ItemType 이 db 에 등록이 되면, 추가로 Default AttributeGroup, Attribute 들을 등록한다.
      Throws:
      Exception - 등록 중 오류가 발생한 경우
    • isOptionable

      public boolean isOptionable() throws TorqueException
      이 ItemType 이 서술하는 대상이 itemable 인지 확인 itemable 이면 PrimaryKey attribute 를 가지고 있어야 한다.
      Returns:
      true/false
      Throws:
      TorqueException - 조회 중 오류가 발생한 경우
    • getOptionableClassName

      public Class<?> getOptionableClassName() throws TorqueException
      이 ItemType 이 서술하고 있는 Optionable class 를 구한다.
      Returns:
      Optionable class
      Throws:
      TorqueException - 조회 중 오류가 발생한 경우
    • isArtifactizable

      public boolean isArtifactizable() throws TorqueException
      이 ItemType 이 서술하는 대상이 itemable 인지 확인 itemable 이면 PrimaryKey attribute 를 가지고 있어야 한다.
      Returns:
      true/false
      Throws:
      TorqueException - 조회 중 오류가 발생한 경우
    • getArtifactizableClassName

      public Class<?> getArtifactizableClassName() throws TorqueException
      이 ItemType 이 서술하고 있는 Artifacatizable class 를 구한다.
      Returns:
      Artifactizable class
      Throws:
      TorqueException - 조회 중 오류가 발생한 경우
    • getArtifactType

      public ItemType getArtifactType() throws TorqueException
      System fixed
      Specified by:
      getArtifactType in interface Artifactizable
      Returns:
      ITEM_TYPE ItemType
      Throws:
      TorqueException - 조회 중 오류가 발생한 경우
    • getParent

      public ItemType getParent()
      same as getItemTypeRelatedByParentId() Optionable impelements
      Specified by:
      getParent in interface Optionable<ItemType>
      Returns:
      itemType which is parent itemType
    • setParent

      public void setParent(ItemType itemType)
      부모 ItemType 을 설정한다.
      Specified by:
      setParent in interface Optionable<ItemType>
      Parameters:
      itemType - 부모 ItemType
    • getAttribute

      public Attribute getAttribute() throws TorqueException
      Optionable implements
      Specified by:
      getAttribute in interface Optionable<ItemType>
      Returns:
      attribute
      Throws:
      TorqueException - 조회 중 오류가 발생한 경우
    • getAttributeOption

      public AttributeOption getAttributeOption() throws TorqueException
      이 itemType 이 해당하는 attributeOption 을 구한다.
      Specified by:
      getAttributeOption in interface Optionable<ItemType>
      Returns:
      attributeOption which is responding to this object
      Throws:
      TorqueException - 조회 중 오류가 발생한 경우
    • getMethodCache

      public MethodResultCache getMethodCache()
      Specified by:
      getMethodCache in interface Cacheable
      Returns:
      MethodResultCache
    • clear

      public void clear()
      Description copied from interface: Cacheable
      clear this Serializable instance cache
      Specified by:
      clear in interface Cacheable