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

com.scalar.db.common.ResultImpl Maven / Gradle / Ivy

Go to download

A universal transaction manager that achieves database-agnostic transactions and distributed transactions that span multiple databases

The newest version!
package com.scalar.db.common;

import com.google.common.collect.ImmutableMap;
import com.scalar.db.api.TableMetadata;
import com.scalar.db.io.Column;
import com.scalar.db.io.Key;
import com.scalar.db.util.ScalarDbUtils;
import java.nio.ByteBuffer;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import javax.annotation.Nullable;
import javax.annotation.concurrent.Immutable;

@Immutable
public class ResultImpl extends AbstractResult {

  private final ImmutableMap> columns;
  private final TableMetadata metadata;

  public ResultImpl(Map> columns, TableMetadata metadata) {
    this.columns = ImmutableMap.copyOf(Objects.requireNonNull(columns));
    this.metadata = Objects.requireNonNull(metadata);
  }

  /** @deprecated As of release 3.8.0. Will be removed in release 5.0.0 */
  @Deprecated
  @Override
  public Optional getPartitionKey() {
    return Optional.of(ScalarDbUtils.getPartitionKey(this, metadata));
  }

  /** @deprecated As of release 3.8.0. Will be removed in release 5.0.0 */
  @Deprecated
  @Override
  public Optional getClusteringKey() {
    return ScalarDbUtils.getClusteringKey(this, metadata);
  }

  @Override
  public boolean isNull(String columnName) {
    checkIfExists(columnName);
    Column column = columns.get(columnName);
    assert column != null;
    return column.hasNullValue();
  }

  @Override
  public boolean getBoolean(String columnName) {
    checkIfExists(columnName);
    Column column = columns.get(columnName);
    assert column != null;
    return column.getBooleanValue();
  }

  @Override
  public int getInt(String columnName) {
    checkIfExists(columnName);
    Column column = columns.get(columnName);
    assert column != null;
    return column.getIntValue();
  }

  @Override
  public long getBigInt(String columnName) {
    checkIfExists(columnName);
    Column column = columns.get(columnName);
    assert column != null;
    return column.getBigIntValue();
  }

  @Override
  public float getFloat(String columnName) {
    checkIfExists(columnName);
    Column column = columns.get(columnName);
    assert column != null;
    return column.getFloatValue();
  }

  @Override
  public double getDouble(String columnName) {
    checkIfExists(columnName);
    Column column = columns.get(columnName);
    assert column != null;
    return column.getDoubleValue();
  }

  @Nullable
  @Override
  public String getText(String columnName) {
    checkIfExists(columnName);
    Column column = columns.get(columnName);
    assert column != null;
    return column.getTextValue();
  }

  @Nullable
  @Override
  public ByteBuffer getBlobAsByteBuffer(String columnName) {
    checkIfExists(columnName);
    Column column = columns.get(columnName);
    assert column != null;
    return column.getBlobValueAsByteBuffer();
  }

  @Nullable
  @Override
  public byte[] getBlobAsBytes(String columnName) {
    checkIfExists(columnName);
    Column column = columns.get(columnName);
    assert column != null;
    return column.getBlobValueAsBytes();
  }

  @Nullable
  @Override
  public Object getAsObject(String columnName) {
    checkIfExists(columnName);
    Column column = columns.get(columnName);
    assert column != null;
    return column.getValueAsObject();
  }

  @Override
  public boolean contains(String columnName) {
    return columns.containsKey(columnName);
  }

  @Override
  public Set getContainedColumnNames() {
    return columns.keySet();
  }

  @Override
  public Map> getColumns() {
    return columns;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy