All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.scalar.db.sql.springdata.ScalarDbDialect Maven / Gradle / Ivy

package com.scalar.db.sql.springdata;

import javax.annotation.Nonnull;
import org.springframework.data.relational.core.dialect.AbstractDialect;
import org.springframework.data.relational.core.dialect.LimitClause;
import org.springframework.data.relational.core.dialect.LockClause;
import org.springframework.data.relational.core.sql.IdentifierProcessing;
import org.springframework.data.relational.core.sql.IdentifierProcessing.LetterCasing;
import org.springframework.data.relational.core.sql.IdentifierProcessing.Quoting;
import org.springframework.data.relational.core.sql.LockOptions;

/**
 * A SQL dialect for ScalarDB. This class does nothing for pessimistic locking as ScalarDB doesn't
 * support the feature.
 */
public class ScalarDbDialect extends AbstractDialect {
  /** Singleton instance. */
  public static final ScalarDbDialect INSTANCE = new ScalarDbDialect();

  private static final LimitClause LIMIT_CLAUSE =
      new LimitClause() {

        @Override
        @Nonnull
        public String getLimit(long limit) {
          return "LIMIT " + limit;
        }

        @Override
        @Nonnull
        public String getOffset(long offset) {
          throw new UnsupportedOperationException("OFFSET isn't supported");
        }

        @Override
        @Nonnull
        public String getLimitOffset(long limit, long offset) {
          throw new UnsupportedOperationException("OFFSET isn't supported");
        }

        @Override
        @Nonnull
        public Position getClausePosition() {
          return Position.AFTER_ORDER_BY;
        }
      };

  private final LockClause LOCK_CLAUSE =
      new LockClause() {
        @Override
        @Nonnull
        public String getLock(@Nonnull LockOptions lockOptions) {
          // ScalarDB SQL doesn't support any pessimistic locking as ScalarDB uses OCC
          return "";
        }

        @Override
        @Nonnull
        public Position getClausePosition() {
          return Position.AFTER_ORDER_BY;
        }
      };

  @Override
  @Nonnull
  public LimitClause limit() {
    return LIMIT_CLAUSE;
  }

  @Override
  @Nonnull
  public LockClause lock() {
    return LOCK_CLAUSE;
  }

  @Override
  @Nonnull
  public IdentifierProcessing getIdentifierProcessing() {
    return IdentifierProcessing.create(Quoting.ANSI, LetterCasing.LOWER_CASE);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy