1. 程式人生 > >Esper事件處理引擎_17_EPL 語法_9_Schema 宣告資料型別

Esper事件處理引擎_17_EPL 語法_9_Schema 宣告資料型別

package com.framework_technology.esper.epl;

import com.java.annotation.document.Keyword;
import com.java.annotation.document.Undigested;

/**
 * API - 5.16. Declaring an Event Type: Create Schema
 *
 * @author wei.Li by 14-8-21.
 */
public class EPL_9_Schema {

    /**
     * 宣告一個提供事件型別的名稱和資料型別
     * <p>
     * 語法:
     * <p>
     * create [map | objectarray] schema schema_name [as]
     * (property_name property_type [,property_name property_type [,...])
     * [inherits inherited_event_type[, inherited_event_type] [,...]]
     * [starttimestamp timestamp_property_name]
     * [endtimestamp timestamp_property_name]
     * [copyfrom copy_type_name [, copy_type_name] [,...]]
     * <p>
     * 1.任何Java類名,完全合格或引入簡單的類名配置。
     * 2.新增左右方括號[]到任何型別來表示一個數組型別的事件屬性。
     * 3.使用事件型別名稱作為屬性型別。
     * <p>
     *
     * @return epl[]
     */
    protected static String declareSchema() {
        // Declare type SecurityEvent
        String epl1 = "create schema SecurityEvent as (ipAddress string, userId String, numAttempts int)";

        // 宣告指定欄位名稱和資料型別 與 POJO[hostinfo]
        String epl2 = "create schema AuthorizationEvent(group String, roles String[], hostinfo com.mycompany.HostNameInfo)";

        // 宣告一個有其他 schema 陣列型別的欄位innerEvents
        String epl3 = "create schema CompositeEvent(group String, innerEvents SecurityEvent[])";

        // 宣告型別WebPageVisitEvent繼承自PageHitEvent所有屬性
        @Keyword(keyWord = "inherits", Description = "繼承")
        String epl4 = "create schema WebPageVisitEvent(userId String) inherits PageHitEvent";

        // 宣告一個型別的起始和結束時間戳(即事件與持續時間)(i.e. event with duration)
        String epl5 = "create schema RoboticArmMovement (robotId string, startts long, endts long)" +
                "starttimestamp startts endtimestamp endts";

        //建立具有SecurityEvent的所有屬性加一個使用者名稱屬性型別
        @Keyword(keyWord = "copyfrom", Description = "複製")
        String epl6 = "create schema ExtendedSecurityEvent (userName string) copyfrom SecurityEvent";

        //建立具有SecurityEvent的所有屬性型別
        String epl7 = "create schema SimilarSecurityEvent () copyfrom SecurityEvent";

        //建立具有SecurityEvent和WebPageVisitEvent的所有屬性加一個使用者名稱屬性型別
        String epl8 = "create schema WebSecurityEvent (userName string) copyfrom SecurityEvent, WebPageVisitEvent";

        // 顯示完整的包名 LoginEvent event type
        String epl9 = "create schema LoginEvent as com.mycompany.LoginValue";

        // 當把包名配置後,無需加包名
        String epl10 = "create schema LogoutEvent as SignoffValue";

        return epl1;
    }

    /**
     * 使用例項
     *
     * @return epl
     */
    protected static String useSchema() {
        String epl1 = "create schema SecurityData (name String, roles String[])";
        String epl2 = "create window SecurityEvent.win:time(30 sec) " +
                " (ipAddress string, userId String, secData SecurityData, historySecData SecurityData[])";

        return epl1;
    }

}