io.kestra.plugin.jdbc.AbstractJdbcTrigger Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of plugin-jdbc Show documentation
Show all versions of plugin-jdbc Show documentation
Abstract JDBC plugin for Kestra
package io.kestra.plugin.jdbc;
import io.kestra.core.models.conditions.ConditionContext;
import io.kestra.core.models.executions.Execution;
import io.kestra.core.models.triggers.*;
import io.kestra.core.runners.RunContext;
import lombok.*;
import lombok.experimental.SuperBuilder;
import org.slf4j.Logger;
import java.time.Duration;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
@SuperBuilder
@ToString
@EqualsAndHashCode
@Getter
@NoArgsConstructor
public abstract class AbstractJdbcTrigger extends AbstractTrigger implements PollingTriggerInterface, TriggerOutput, JdbcQueryInterface {
@Builder.Default
private final Duration interval = Duration.ofSeconds(60);
private String url;
private String username;
private String password;
private String timeZoneId;
private String sql;
@Builder.Default
private boolean store = false;
@Builder.Default
private boolean fetchOne = false;
@Builder.Default
private boolean fetch = false;
@Builder.Default
protected Integer fetchSize = 10000;
@Builder.Default
@Getter(AccessLevel.NONE)
protected transient Map additionalVars = new HashMap<>();
@Override
public Optional evaluate(ConditionContext conditionContext, TriggerContext context) throws Exception {
RunContext runContext = conditionContext.getRunContext();
Logger logger = runContext.logger();
var run = runQuery(runContext);
logger.debug("Found '{}' rows from '{}'", run.getSize(), runContext.render(this.sql));
if (Optional.ofNullable(run.getSize()).orElse(0L) == 0) {
return Optional.empty();
}
Execution execution = TriggerService.generateExecution(this, conditionContext, context, run);
return Optional.of(execution);
}
protected abstract AbstractJdbcQuery.Output runQuery(RunContext runContext) throws Exception;
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy