package com.huazheng.project.greenplum.richsink;

import java.io.Serializable;

import org.apache.flink.streaming.api.functions.sink.RichSinkFunction;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Service;

import com.huazheng.project.greenplum.service.impl.GPServiceImpl;

import cn.hutool.core.util.ReflectUtil;

@Service
public class GreenPlumRichSinkFunction<T> extends RichSinkFunction<T> implements ApplicationContextAware, Serializable {

	private static final long serialVersionUID = 1L;
	
	private static GPServiceImpl gpserviceImpl;

	@Override
	public void invoke(T value) throws Exception {
		String simpleName = value.getClass().getSimpleName();
		ReflectUtil.invoke(gpserviceImpl, "sink" + simpleName, value);
	}

	@Override
	public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
		gpserviceImpl = (GPServiceImpl) applicationContext.getBean("GPServiceImpl");
	}

}
