All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.xxdb.streaming.client.cep.EventSender Maven / Gradle / Ivy

There is a newer version: 3.00.2.4
Show newest version
package com.xxdb.streaming.client.cep;

import com.xxdb.DBConnection;
import com.xxdb.data.BasicTable;
import com.xxdb.data.Entity;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class EventSender {

    private String insertScript;
    private EventHandler eventHandler;
    private DBConnection conn;

    public EventSender(DBConnection conn, String tableName, List eventSchemas, List eventTimeKeys, List commonKeys) throws IOException {
        this.eventHandler = new EventHandler(eventSchemas, eventTimeKeys, commonKeys);
        this.conn = conn;

        String sql = "select top 0 * from " + tableName;
        StringBuilder errMsg = new StringBuilder();
        BasicTable inputTable = (BasicTable) this.conn.run(sql);
        if (!this.eventHandler.checkInputTable(tableName, inputTable, errMsg))
            throw new RuntimeException(errMsg.toString());

        this.insertScript = "tableInsert{" + tableName + "}";
    }

    public void sendEvent(String eventType, List attributes) {
        List args = new ArrayList<>();
        StringBuilder errMsg = new StringBuilder();

        if (!eventHandler.serializeEvent(eventType, attributes, args, errMsg))
            throw new RuntimeException("serialize event Fail for " + errMsg);

        try {
            conn.run(insertScript, args);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy