이벤트에서 엔티티 초기화

엔티티가 필요할 때는 이 엔티티를 참조하는 첫 번째 이벤트의 수신 시에 해당 엔티티를 초기화할 수 있습니다. 비즈니스 모델 규정 탭에서 비즈니스 규칙 언어를 사용하여 이벤트에서 엔티티 초기화를 선언할 수 있습니다.

규정에서는 초기화될 엔티티 및 이를 초기화하는 이벤트를 지정합니다.

엔티티 초기화의 화면 캡처.
  1. 바인드된 엔티티 유형.
  2. 처리되는 이벤트 유형.
  3. 바인드된 엔티티.
  4. 이벤트의 바인드된 엔티티에 대응되는 ID를 검색하는 표현식.
  5. 선택사항: 바인드된 엔티티의 속성의 초기화.
  6. 선택사항: 속성을 이벤트 유형에 맵핑.
구성의 조치 파트에서는 다양한 유형의 조치를 쓸 수 있습니다.
  • 바인드된 엔티티의 속성을 지정하십시오.
  • 바인드된 엔티티의 초기화의 결과로서 이벤트를 전송합니다.
마지막 조치가 정수로 끝나면 마침표 앞에 공백을 추가해야 합니다. 조치를 지정하지 않으려면 구성의 첫 번째 파트의 끝에 있는 콜론을 마침표로 대체하십시오.
제한사항: 이벤트 유형 및 이벤트 엔티티 관계의 각 조합에 대해 단 한 번만 엔티티의 초기화를 정의할 수 있습니다. 이벤트가 동일한 유형의 두 엔티티와 관련된 경우, 이러한 관련된 엔티티 각각은 자체 초기화 규정을 가질 수 있습니다.

Java™에 기반한 엔티티 초기화 확장기능을 사용하여 외부 데이터 소스에서 엔티티를 초기화할 수도 있습니다. 자세한 정보는 엔티티 초기화 확장기능 작성의 내용을 참조하십시오.

예

이 예에서는 고객이 은행 계정을 개설할 때 account 엔티티가 초기화됩니다. 이 계정의 고객 및 신용 한도는 규칙의 조치 파트에 정의됩니다. 또한 초기화된 account 엔티티는 customer 원격 엔티티의 엔티티에 추가됩니다. 여기서 customer 엔티티는 이름으로 식별되며 일부 계정과 관련된 비즈니스 엔티티로서 비즈니스 모델에 정의됩니다.

an account is initialized from an open account event, where this account comes from the account of this open account event:
    - set the credit limit of this account to the limit of this open account event
    - set the customer of this account to the customer of this open account event
    - add this account to the accounts of the customer of this open account event.

다음의 예에서 customer 엔티티는 new customer event가 발생할 때 초기화되며, 여기서 이 이벤트는 이름이 있는 비즈니스 이벤트로서 비즈니스 모델에 정의됩니다. 규칙의 조치 파트는 이 초기화가 고객 엔티티와 관련되며 신용 한도가 10,000인 new open account 이벤트를 트리거하도록 지정합니다.

a customer is initialized from a new customer event, where this customer comes from the name of this new customer event:
    - emit a new open account event where the customer is this customer, the limit is 10,000.

다음의 예에서 account 계정은 조치 없이 초기화됩니다.

an account is initialized from an open account event, where this account comes from the account of this open account event.

엔티티 및 이벤트 유형의 계층을 기반으로 엔티티 초기화

둘 이상의 초기자(initializer)가 엔티티 유형의 계층에서 선언되는 경우, 우선순위는 이 계층을 기반으로 합니다. 가장 일반적인 엔티티 유형이 우선됩니다.

예 1

다음 비즈니스 모델은 이동 수단, 자동차, 이동 활동, 및 자동차 활동을 정의합니다. car 엔티티 유형은 vehicle 엔티티 유형의 특수화이며 car activity 이벤트 유형은 vehicle activity 이벤트 유형의 특수화입니다.

a vehicle is a business entity identified by a vehicle id ( text ).

a car is a vehicle.
a car has a passenger capacity ( integer ).

a vehicle activity is a business event time-stamped by an event timestamp ( date & time ).
a vehicle activity is related to a vehicle. 
a car activity is a vehicle activity. 

다음 초기화는 비즈니스 모델 규정에서 선언될 수 있으며, 여기서 두 개의 서로 다른 이벤트 유형으로 동일한 엔티티 유형을 초기화할 수 있습니다. 여기서는 초기화를 트리거하는 vehicle activity 이벤트 유형이 car activity 이벤트 유형보다 일반적이므로 첫 번째 초기화 규정이 더 높은 우선순위를 가집니다.

a vehicle is initialized from a vehicle activity, where this vehicle comes from the vehicle of this vehicle activity.

a vehicle is initialized from a car activity, where this vehicle comes from the vehicle of this car activity. 

예 2

비즈니스 엔티티의 계층, 비즈니스 이벤트의 계층, 엔티티 유형의 두 초기자를 고려하십시오.

비즈니스 모델 정의:

a vehicle is a business entity identified by a vehicle id ( text ).

a car is a vehicle.
a car has a cost (numeric).

a leased car is a car.
a leased car has a monthly payment (numeric).

a car acquisition is a business event.
a car acquisition is related to a vehicle.
a car acquisition has an price (numeric).

a car leasing is a car acquisition.
a car leasing has a duration in months (numeric).
a car leasing has an initial payment (numeric).
a car leasing has a monthly payment (numeric).

비즈니스 모델 규정:

a car is initialized from a car acquisition , where this car comes from the vehicle of this car acquisition:
   - set the cost of this car to the price of this car acquisition.

a leased car is initialized from a car leasing , where this leased car comes from the vehicle of this car leasing:
   - set the monthly payment of this leased car to the monthly payment of this car leasing
   - set the cost of this leased car to the initial payment of this car leasing +
      the monthly payment of this car leasing * the duration in months of this car leasing.

첫 번째 초기자는 car acquisition 유형의 이벤트를 처리하고 car 유형의 엔티티를 초기화합니다. 두 번째 초기자는 car leasing 유형의 이벤트를 처리하고 leased car 유형의 엔티티를 초기화합니다.

car leasing 유형의 인스턴스이고 작성되지 않은 vehicle 엔티티와 관련된 이벤트 E1을 고려하십시오. leased car 초기자는 이 엔티티를 초기화할 수 있습니다. car leasing 유형은 car acquisition의 하위 유형이므로 이벤트는 car acquisition 유형의 인스턴스이기도 합니다. 결과적으로 car 초기자는 이벤트의 작성되지 않은 vehicle 엔티티도 초기화할 수 있습니다. 이 컨텍스트에서는 vehicle 엔티티가 leased car 유형의 인스턴스 및 car 유형의 인스턴스입니다. leased car 유형은 이러한 유형에 대해 가장 특정적입니다. 그러므로 런타임 시스템은 이벤트 E1의 vehicle 엔티티를 작성할 경우 leased car 유형을 인스턴스화합니다. 그런 다음 새로 작성된 이 엔티티는 이벤트 E1을 처리하는 leased car 초기자 및 car 초기자에 의해 초기화됩니다. 첫 번째 초기자는 엔티티의 비용 및 월별 지급금을 설정하고 두 번째 초기자는 임대 자동차의 비용을 이벤트의 가격으로 확장합니다.