Skip to content

Commit

Permalink
refactor: migrate auoCommit to dynamic props (#482)
Browse files Browse the repository at this point in the history
  • Loading branch information
mgabelle authored Jan 16, 2025
1 parent 2a0dc03 commit 1c510f5
Show file tree
Hide file tree
Showing 17 changed files with 40 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import io.kestra.core.models.annotations.Example;
import io.kestra.core.models.annotations.Plugin;
import io.kestra.core.models.property.Property;
import io.kestra.core.models.tasks.RunnableTask;
import io.kestra.core.runners.RunContext;
import io.kestra.plugin.jdbc.AbstractCellConverter;
Expand Down Expand Up @@ -37,7 +38,7 @@
code = """
id: as400_query
namespace: company.team
tasks:
- id: query
type: io.kestra.plugin.jdbc.as400.Query
Expand All @@ -51,7 +52,7 @@
}
)
public class Query extends AbstractJdbcQuery implements RunnableTask<AbstractJdbcQuery.Output>, AutoCommitInterface {
protected final Boolean autoCommit = true;
protected final Property<Boolean> autoCommit = Property.of(true);

@Override
protected AbstractCellConverter getCellConverter(ZoneId zoneId) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.kestra.plugin.jdbc.clickhouse;

import io.kestra.core.models.property.Property;
import io.kestra.plugin.jdbc.AutoCommitInterface;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.EqualsAndHashCode;
Expand Down Expand Up @@ -34,7 +35,7 @@
code = """
id: clickhouse_query
namespace: company.team
tasks:
- id: query
type: io.kestra.plugin.jdbc.clickhouse.Query
Expand All @@ -48,7 +49,7 @@
}
)
public class Query extends AbstractJdbcQuery implements RunnableTask<AbstractJdbcQuery.Output>, AutoCommitInterface {
protected final Boolean autoCommit = true;
protected final Property<Boolean> autoCommit = Property.of(true);

@Override
protected AbstractCellConverter getCellConverter(ZoneId zoneId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import io.kestra.core.models.annotations.Example;
import io.kestra.core.models.annotations.Plugin;
import io.kestra.core.models.property.Property;
import io.kestra.core.models.tasks.RunnableTask;
import io.kestra.core.runners.RunContext;
import io.kestra.plugin.jdbc.AbstractCellConverter;
Expand Down Expand Up @@ -48,7 +49,7 @@
}
)
public class Query extends AbstractJdbcQuery implements RunnableTask<AbstractJdbcQuery.Output>, AutoCommitInterface {
protected final Boolean autoCommit = true;
protected final Property<Boolean> autoCommit = Property.of(true);

@Override
protected AbstractCellConverter getCellConverter(ZoneId zoneId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
public class Query extends AbstractJdbcQuery implements RunnableTask<Query.Output>, AutoCommitInterface {
private static final String DEFAULT_URL = "jdbc:duckdb:";

protected final Boolean autoCommit = true;
protected final Property<Boolean> autoCommit = Property.of(true);

@Schema(
title = "Input files to be loaded from DuckDb.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
}
)
public class Query extends AbstractJdbcQuery implements RunnableTask<AbstractJdbcQuery.Output>, AutoCommitInterface {
protected final Boolean autoCommit = true;
protected final Property<Boolean> autoCommit = Property.of(true);

@Schema(
title = "Add input file to be loaded with `LOAD DATA LOCAL`.",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.kestra.plugin.jdbc.oracle;

import io.kestra.core.models.property.Property;
import io.kestra.plugin.jdbc.AutoCommitInterface;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.EqualsAndHashCode;
Expand Down Expand Up @@ -42,7 +43,7 @@
password: oracle_password
sql: select * from source
fetchType: FETCH
- id: generate_update
type: io.kestra.plugin.jdbc.oracle.Query
url: jdbc:oracle:thin:@localhost:49161:XE
Expand All @@ -54,7 +55,7 @@
}
)
public class Query extends AbstractJdbcQuery implements RunnableTask<AbstractJdbcQuery.Output>, AutoCommitInterface {
protected final Boolean autoCommit = true;
protected final Property<Boolean> autoCommit = Property.of(true);

@Override
protected AbstractCellConverter getCellConverter(ZoneId zoneId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
}
)
public class Query extends AbstractJdbcQuery implements RunnableTask<AbstractJdbcQuery.Output>, PostgresConnectionInterface, AutoCommitInterface {
protected final Boolean autoCommit = true;
protected final Property<Boolean> autoCommit = Property.of(true);
@Builder.Default
protected Property<Boolean> ssl = Property.of(false);
protected Property<SslMode> sslMode;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.kestra.plugin.jdbc.redshift;

import io.kestra.core.models.property.Property;
import io.kestra.plugin.jdbc.AutoCommitInterface;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.EqualsAndHashCode;
Expand Down Expand Up @@ -47,7 +48,7 @@
}
)
public class Query extends AbstractJdbcQuery implements RunnableTask<AbstractJdbcQuery.Output>, AutoCommitInterface {
protected final Boolean autoCommit = true;
protected final Property<Boolean> autoCommit = Property.of(true);

@Override
protected AbstractCellConverter getCellConverter(ZoneId zoneId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
}
)
public class Query extends AbstractJdbcQuery implements RunnableTask<AbstractJdbcQuery.Output>, SnowflakeInterface, AutoCommitInterface {
protected final Boolean autoCommit = true;
protected final Property<Boolean> autoCommit = Property.of(true);

private Property<String> privateKey;
private Property<String> privateKeyFile;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import io.kestra.core.models.annotations.Example;
import io.kestra.core.models.annotations.Plugin;
import io.kestra.core.models.annotations.PluginProperty;
import io.kestra.core.models.property.Property;
import io.kestra.core.models.tasks.RunnableTask;
import io.kestra.core.models.tasks.runners.PluginUtilsService;
import io.kestra.core.runners.RunContext;
Expand Down Expand Up @@ -39,14 +40,14 @@
code = """
id: sqlite_query
namespace: company.team
tasks:
- id: update
type: io.kestra.plugin.jdbc.sqlite.Query
url: jdbc:sqlite:myfile.db
sql: select concert_id, available, a, b, c, d, play_time, library_record, floatn_test, double_test, real_test, numeric_test, date_type, time_type, timez_type, timestamp_type, timestampz_type, interval_type, pay_by_quarter, schedule, json_type, blob_type from pgsql_types
fetchType: FETCH
- id: use_fetched_data
type: io.kestra.plugin.jdbc.sqlite.Query
url: jdbc:sqlite:myfile.db
Expand All @@ -59,15 +60,15 @@
code = """
id: sqlite_query_using_file
namespace: company.team
tasks:
- id: update
type: io.kestra.plugin.jdbc.sqlite.Query
url: jdbc:sqlite:myfile.db
sqliteFile: {{ outputs.get.outputFiles['myfile.sqlite'] }}
sql: select * from pgsql_types
fetchType: FETCH
- id: use_fetched_data
type: io.kestra.plugin.jdbc.sqlite.Query
url: jdbc:sqlite:myfile.db
Expand All @@ -78,7 +79,7 @@
}
)
public class Query extends AbstractJdbcQuery implements RunnableTask<AbstractJdbcQuery.Output>, AutoCommitInterface {
protected final Boolean autoCommit = true;
protected final Property<Boolean> autoCommit = Property.of(true);

@Schema(
title = "Add sqlite file.",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.kestra.plugin.jdbc.sqlserver;

import io.kestra.core.models.property.Property;
import io.kestra.plugin.jdbc.AutoCommitInterface;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.EqualsAndHashCode;
Expand Down Expand Up @@ -42,7 +43,7 @@
password: sql_server_password
sql: select * from source
fetchType: FETCH
- id: generate_update
type: io.kestra.plugin.jdbc.sqlserver.Query
url: jdbc:sqlserver://localhost:41433;trustServerCertificate=true
Expand All @@ -54,7 +55,7 @@
}
)
public class Query extends AbstractJdbcQuery implements RunnableTask<AbstractJdbcQuery.Output>, AutoCommitInterface {
protected final Boolean autoCommit = true;
protected final Property<Boolean> autoCommit = Property.of(true);

@Override
protected AbstractCellConverter getCellConverter(ZoneId zoneId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import io.kestra.core.models.annotations.Example;
import io.kestra.core.models.annotations.Plugin;
import io.kestra.core.models.property.Property;
import io.kestra.core.models.tasks.RunnableTask;
import io.kestra.core.runners.RunContext;
import io.kestra.plugin.jdbc.AbstractCellConverter;
Expand Down Expand Up @@ -34,7 +35,7 @@
full = true,
code = """
id: sybase_query
namespace: company.team
namespace: company.team
tasks:
- id: query
Expand All @@ -49,7 +50,7 @@
}
)
public class Query extends AbstractJdbcQuery implements RunnableTask<AbstractJdbcQuery.Output>, AutoCommitInterface {
protected final Boolean autoCommit = true;
protected final Property<Boolean> autoCommit = Property.of(true);

@Override
protected AbstractCellConverter getCellConverter(ZoneId zoneId) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.kestra.plugin.jdbc.trino;

import io.kestra.core.models.property.Property;
import io.kestra.plugin.jdbc.AutoCommitInterface;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.EqualsAndHashCode;
Expand Down Expand Up @@ -33,7 +34,7 @@
code = """
id: trino_query
namespace: company.team
tasks:
- id: analyze_orders
type: io.kestra.plugin.jdbc.trino.Query
Expand All @@ -47,7 +48,7 @@ select orderpriority as priority, sum(totalprice) as total
order by orderpriority
fetchType: FETCH
fetchType: STORE
- id: csv_report
type: io.kestra.plugin.serdes.csv.IonToCsv
from: "{{ outputs.analyze_orders.uri }}"
Expand All @@ -56,7 +57,7 @@ select orderpriority as priority, sum(totalprice) as total
}
)
public class Query extends AbstractJdbcQuery implements RunnableTask<AbstractJdbcQuery.Output>, AutoCommitInterface {
protected final Boolean autoCommit = true;
protected final Property<Boolean> autoCommit = Property.of(true);

@Override
protected AbstractCellConverter getCellConverter(ZoneId zoneId) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.kestra.plugin.jdbc.vectorwise;

import io.kestra.core.models.property.Property;
import io.kestra.plugin.jdbc.AutoCommitInterface;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.EqualsAndHashCode;
Expand Down Expand Up @@ -47,7 +48,7 @@
}
)
public class Query extends AbstractJdbcQuery implements RunnableTask<AbstractJdbcQuery.Output>, AutoCommitInterface {
protected final Boolean autoCommit = true;
protected final Property<Boolean> autoCommit = Property.of(true);

@Override
protected AbstractCellConverter getCellConverter(ZoneId zoneId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import io.kestra.core.models.annotations.Example;
import io.kestra.core.models.annotations.Plugin;
import io.kestra.core.models.property.Property;
import io.kestra.core.models.tasks.RunnableTask;
import io.kestra.core.runners.RunContext;
import io.kestra.plugin.jdbc.AbstractCellConverter;
Expand Down Expand Up @@ -48,7 +49,7 @@
}
)
public class Query extends AbstractJdbcQuery implements RunnableTask<AbstractJdbcQuery.Output>, AutoCommitInterface {
protected final Boolean autoCommit = true;
protected final Property<Boolean> autoCommit = Property.of(true);

@Override
protected AbstractCellConverter getCellConverter(ZoneId zoneId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public AbstractJdbcBaseQuery.Output run(RunContext runContext) throws Exception
if (this.renderFetchType(runContext).equals(FetchType.STORE)) {
conn.setAutoCommit(false);
} else {
conn.setAutoCommit(autoCommitClass.getAutoCommit());
conn.setAutoCommit(runContext.render(autoCommitClass.getAutoCommit()).as(Boolean.class).orElse(true));
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.kestra.plugin.jdbc;

import io.kestra.core.models.annotations.PluginProperty;
import io.kestra.core.models.property.Property;
import io.swagger.v3.oas.annotations.media.Schema;

public interface AutoCommitInterface {
Expand All @@ -12,6 +12,5 @@ public interface AutoCommitInterface {
"or the method rollback. By default, new connections are in auto-commit mode except when you are using " +
"`store` property in which case the auto-commit will be disabled."
)
@PluginProperty(dynamic = false)
Boolean getAutoCommit();
Property<Boolean> getAutoCommit();
}

0 comments on commit 1c510f5

Please sign in to comment.