Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package tech.ydb.yoj.repository.db.internal;
- import lombok.AccessLevel;
- import lombok.NoArgsConstructor;
- import lombok.NonNull;
- import lombok.RequiredArgsConstructor;
- import tech.ydb.yoj.ExperimentalApi;
- import tech.ydb.yoj.InternalApi;
- import tech.ydb.yoj.repository.db.IsolationLevel;
- import tech.ydb.yoj.repository.db.RepositoryTransaction;
- import tech.ydb.yoj.repository.db.bulk.BulkParams;
- import tech.ydb.yoj.repository.db.readtable.ReadTableParams;
- import javax.annotation.Nullable;
- /**
- * Describes a single request to the database performed by a {@link RepositoryTransaction},
- * typically in a transaction <em>but not always</em>.
- * <p>For ease of use, requests that don't take any arguments are available as constants:
- * <ul>
- * <li>{@link Commit#INSTANCE Commit.INSTANCE - commit()}</li>
- * <li>{@link Rollback#INSTANCE Rollback.INSTANCE - rollback()}</li>
- * <li>{@link GetSession#INSTANCE GetSession.INSTANCE - getSession()}</li>
- * </ul>
- */
- @InternalApi
- @ExperimentalApi(issue = "https://github.com/ydb-platform/yoj-project/issues/165")
- public sealed interface DbRequest permits
- DbRequest.Commit,
- DbRequest.Rollback,
- DbRequest.GetSession,
- DbRequest.DataQuery,
- DbRequest.ScanQuery,
- DbRequest.ReadTable,
- DbRequest.BulkUpsert
- {
- /**
- * Returns a human-readable representation of the database request.
- */
- String toLogString();
- /**
- * Commit the transaction.
- */
- @NoArgsConstructor(access = AccessLevel.PRIVATE)
- final class Commit implements DbRequest {
- public static final Commit INSTANCE = new Commit();
- @Override
- public String toLogString() {
- return ".commit()";
- }
- }
- /**
- * Rollback the transaction.
- */
- @NoArgsConstructor(access = AccessLevel.PRIVATE)
- final class Rollback implements DbRequest {
- public static final Rollback INSTANCE = new Rollback();
- @Override
- public String toLogString() {
- return ".rollback()";
- }
- }
- /**
- * Obtain a database session (connection), most likely from a pool.
- * Not all {@link RepositoryTransaction} implementations use this request type.
- */
- @NoArgsConstructor(access = AccessLevel.PRIVATE)
- final class GetSession implements DbRequest {
- public static final GetSession INSTANCE = new GetSession();
- @Override
- public String toLogString() {
- return ".getSession()";
- }
- }
- /**
- * Execute a single statement in ordinary query mode. Consistency and allowed operations (reads and writes,
- * or only reads) depend on the transaction's isolation level.
- */
- @RequiredArgsConstructor
- final class DataQuery implements DbRequest {
- @Nullable private final String log;
- @Override
- public String toLogString() {
- return ".dataQuery()" + log;
- }
- }
- /**
- * Execute a single statement in scan query mode. Not quite a transactional action, but users may consider
- * scan query isolation to be that of the {@link IsolationLevel#SNAPSHOT_READ_ONLY} isolation level.
- */
- @RequiredArgsConstructor
- final class ScanQuery implements DbRequest {
- @Nullable private final String log;
- @Override
- public String toLogString() {
- return ".scanQuery()" + log;
- }
- }
- /**
- * Stream the whole table or a range of it (non-transactional).
- */
- @RequiredArgsConstructor
- final class ReadTable implements DbRequest {
- @NonNull private final String tableName;
- @NonNull private final ReadTableParams<?> params;
- @Override
- public String toLogString() {
- return ".readTable()" + tableName + ", " + params;
- }
- }
- /**
- * Bulk upsert data (non-transactional).
- */
- @RequiredArgsConstructor
- final class BulkUpsert implements DbRequest {
- @NonNull private final String tableName;
- private final long size;
- @NonNull private final BulkParams bulkParams;
- @Override
- public String toLogString() {
- return ".bulkUpsert()" + tableName + ", [" + size + "], " + bulkParams;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment