io.edurt.datacap.plugin.jdbc.tdengine.TDenginePlugin Maven / Gradle / Ivy
The newest version!
package io.edurt.datacap.plugin.jdbc.tdengine;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import io.edurt.datacap.spi.Plugin;
import io.edurt.datacap.spi.PluginType;
import io.edurt.datacap.spi.adapter.JdbcAdapter;
import io.edurt.datacap.spi.connection.JdbcConfigure;
import io.edurt.datacap.spi.connection.JdbcConnection;
import io.edurt.datacap.spi.model.Configure;
import io.edurt.datacap.spi.model.Response;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.lang3.ObjectUtils;
@Slf4j
@SuppressFBWarnings(value = {"EI_EXPOSE_REP"})
public class TDenginePlugin
implements Plugin
{
private JdbcConfigure jdbcConfigure;
private JdbcConnection connection;
private Response response;
@Override
public String name()
{
return "TDengine";
}
@Override
public String description()
{
return "Integrate TDengine data sources";
}
@Override
public PluginType type()
{
return PluginType.JDBC;
}
@Override
public void connect(Configure configure)
{
try {
this.response = new Response();
this.jdbcConfigure = new JdbcConfigure();
BeanUtils.copyProperties(this.jdbcConfigure, configure);
this.jdbcConfigure.setJdbcDriver("com.taosdata.jdbc.TSDBDriver");
this.jdbcConfigure.setJdbcType("TAOS-RS");
this.connection = new JdbcConnection(this.jdbcConfigure, this.response);
}
catch (Exception ex) {
this.response.setIsConnected(Boolean.FALSE);
this.response.setMessage(ex.getMessage());
}
}
@Override
public Response execute(String content)
{
if (ObjectUtils.isNotEmpty(this.connection)) {
log.info("Execute tdengine plugin logic started");
this.response = this.connection.getResponse();
JdbcAdapter processor = new TDengineAdapter(this.connection);
this.response = processor.handlerExecute(content);
log.info("Execute tdengine plugin logic end");
}
return this.response;
}
@Override
public void destroy()
{
if (ObjectUtils.isNotEmpty(this.connection)) {
this.connection.destroy();
}
}
}