tech.ydb.jdbc.settings.YdbOperationProperties Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ydb-jdbc-driver Show documentation
Show all versions of ydb-jdbc-driver Show documentation
JDBC Driver over YDB Java SDK
package tech.ydb.jdbc.settings;
import java.sql.Connection;
import java.sql.SQLException;
import java.time.Duration;
import java.util.Properties;
public class YdbOperationProperties {
static final YdbProperty JOIN_DURATION = YdbProperty
.duration("joinDuration", "Default timeout for all YDB operations", "5m");
static final YdbProperty QUERY_TIMEOUT = YdbProperty
.duration("queryTimeout", "Default timeout for all YDB data queries, scheme and explain operations", "0s");
static final YdbProperty SCAN_QUERY_TIMEOUT = YdbProperty
.duration("scanQueryTimeout", "Default timeout for all YDB scan queries", "5m");
static final YdbProperty FAIL_ON_TRUNCATED_RESULT = YdbProperty
.bool("failOnTruncatedResult", "Throw an exception when received truncated result", false);
static final YdbProperty SESSION_TIMEOUT = YdbProperty
.duration("sessionTimeout", "Default timeout to create a session", "5s");
static final YdbProperty DEADLINE_TIMEOUT = YdbProperty
.duration("deadlineTimeout", "Deadline timeout for all operations", "0s");
static final YdbProperty AUTOCOMMIT = YdbProperty
.bool("autoCommit", "Auto commit all operations", true);
static final YdbProperty TRANSACTION_LEVEL = YdbProperty
.integer("transactionLevel", "Default transaction isolation level", Connection.TRANSACTION_SERIALIZABLE);
static final YdbProperty SCAN_QUERY_TX_MODE = YdbProperty.enums(
"scanQueryTxMode",
FakeTxMode.class,
"Mode of execution scan query inside transaction. Possible values - "
+ "ERROR(by default), FAKE_TX and SHADOW_COMMIT",
FakeTxMode.ERROR
);
static final YdbProperty SCHEME_QUERY_TX_MODE = YdbProperty.enums("schemeQueryTxMode",
FakeTxMode.class,
"Mode of execution scheme query inside transaction. Possible values - "
+ "ERROR(by default), FAKE_TX and SHADOW_COMMIT",
FakeTxMode.ERROR
);
private static final int MAX_ROWS = 1000; // TODO: how to figure out the max rows of current connection?
private final YdbValue joinDuration;
private final YdbValue queryTimeout;
private final YdbValue scanQueryTimeout;
private final YdbValue failOnTruncatedResult;
private final YdbValue sessionTimeout;
private final YdbValue deadlineTimeout;
private final YdbValue autoCommit;
private final YdbValue transactionLevel;
private final YdbValue scanQueryTxMode;
private final YdbValue schemeQueryTxMode;
public YdbOperationProperties(YdbConfig config) throws SQLException {
Properties props = config.getProperties();
this.joinDuration = JOIN_DURATION.readValue(props);
this.queryTimeout = QUERY_TIMEOUT.readValue(props);
this.scanQueryTimeout = SCAN_QUERY_TIMEOUT.readValue(props);
this.failOnTruncatedResult = FAIL_ON_TRUNCATED_RESULT.readValue(props);
this.sessionTimeout = SESSION_TIMEOUT.readValue(props);
this.deadlineTimeout = DEADLINE_TIMEOUT.readValue(props);
this.autoCommit = AUTOCOMMIT.readValue(props);
this.transactionLevel = TRANSACTION_LEVEL.readValue(props);
this.scanQueryTxMode = SCAN_QUERY_TX_MODE.readValue(props);
this.schemeQueryTxMode = SCHEME_QUERY_TX_MODE.readValue(props);
}
public Duration getJoinDuration() {
return joinDuration.getValue();
}
public Duration getQueryTimeout() {
return queryTimeout.getValue();
}
public Duration getScanQueryTimeout() {
return scanQueryTimeout.getValue();
}
public boolean isFailOnTruncatedResult() {
return failOnTruncatedResult.getValue();
}
public FakeTxMode getScanQueryTxMode() {
return scanQueryTxMode.getValue();
}
public FakeTxMode getSchemeQueryTxMode() {
return schemeQueryTxMode.getValue();
}
public Duration getSessionTimeout() {
return sessionTimeout.getValue();
}
public Duration getDeadlineTimeout() {
return deadlineTimeout.getValue();
}
public boolean isAutoCommit() {
return autoCommit.getValue();
}
public int getTransactionLevel() {
return transactionLevel.getValue();
}
public int getMaxRows() {
return MAX_ROWS;
}
}