com.datastax.driver.core.RegularStatement类的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(13.8k)|赞(0)|评价(0)|浏览(88)

本文整理了Java中com.datastax.driver.core.RegularStatement类的一些代码示例,展示了RegularStatement类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。RegularStatement类的具体详情如下:
包路径:com.datastax.driver.core.RegularStatement
类名称:RegularStatement

RegularStatement介绍

[英]A regular (non-prepared and non batched) CQL statement.

This class represents a query string along with query options (and optionally binary values, see getValues). It can be extended but SimpleStatementis provided as a simple implementation to build a RegularStatement directly from its query string.
[中]一种常规的(非准备和非批处理的)CQL语句。
此类表示一个查询字符串以及查询选项(以及可选的二进制值,请参见getValues)。它可以扩展,但SimpleStatement是一个简单的实现,可以直接从查询字符串构建正则语句。

代码示例

代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core

IdAndValues getIdAndValues(ProtocolVersion protocolVersion, CodecRegistry codecRegistry) {
 IdAndValues idAndVals = new IdAndValues(statements.size());
 for (Statement statement : statements) {
  if (statement instanceof StatementWrapper)
   statement = ((StatementWrapper) statement).getWrappedStatement();
  if (statement instanceof RegularStatement) {
   RegularStatement st = (RegularStatement) statement;
   ByteBuffer[] vals = st.getValues(protocolVersion, codecRegistry);
   String query = st.getQueryString(codecRegistry);
   idAndVals.ids.add(query);
   idAndVals.values.add(
     vals == null ? Collections.<ByteBuffer>emptyList() : Arrays.asList(vals));
  } else {
   // We handle BatchStatement in add() so ...
   assert statement instanceof BoundStatement;
   BoundStatement st = (BoundStatement) statement;
   idAndVals.ids.add(st.statement.getPreparedId().boundValuesMetadata.id);
   idAndVals.values.add(Arrays.asList(st.wrapper.values));
  }
 }
 return idAndVals;
}

代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core

/**
 * Returns the keyspace of the first statement in this batch.
 *
 * @return the keyspace of the first statement in this batch.
 */
@Override
public String getKeyspace() {
 return statements.isEmpty() ? null : statements.get(0).getKeyspace();
}

代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core

@Override
 public PreparedStatement apply(PreparedStatement prepared) {
  ProtocolVersion protocolVersion =
    getCluster().getConfiguration().getProtocolOptions().getProtocolVersion();
  ByteBuffer routingKey = statement.getRoutingKey(protocolVersion, codecRegistry);
  if (routingKey != null) prepared.setRoutingKey(routingKey);
  if (statement.getConsistencyLevel() != null)
   prepared.setConsistencyLevel(statement.getConsistencyLevel());
  if (statement.getSerialConsistencyLevel() != null)
   prepared.setSerialConsistencyLevel(statement.getSerialConsistencyLevel());
  if (statement.isTracing()) prepared.enableTracing();
  prepared.setRetryPolicy(statement.getRetryPolicy());
  prepared.setOutgoingPayload(statement.getOutgoingPayload());
  prepared.setIdempotent(statement.isIdempotent());
  return prepared;
 }
});

代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core

&& ((RegularStatement) statement).usesNamedValues()) {
throw new IllegalArgumentException(
  "Batch statement cannot contain regular statements with named values ("
    + ((RegularStatement) statement).getQueryString()
    + ")");

代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core

/**
  * Returns this statement as a CQL query string.
  *
  * <p>It is important to note that the query string is merely a CQL representation of this
  * statement, but it does <em>not</em> convey all the information stored in {@link Statement}
  * objects.
  *
  * <p>See the javadocs of {@link #getQueryString()} for more information.
  *
  * @return this statement as a CQL query string.
  * @see #getQueryString()
  */
 @Override
 public String toString() {
  return getQueryString();
 }
}

代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core

int size = Header.lengthFor(protocolVersion);
try {
 size += CBUtil.sizeOfLongString(getQueryString(codecRegistry));
 switch (protocolVersion) {
  case V1:
   size += CBUtil.sizeOfConsistencyLevel(getConsistencyLevel());
   break;
  case V2:
  case V4:
  case V5:
   size += CBUtil.sizeOfConsistencyLevel(getConsistencyLevel());
   size += QueryFlag.serializedSize(protocolVersion);
   if (hasValues()) {
    if (usesNamedValues()) {
     size += CBUtil.sizeOfNamedValueList(getNamedValues(protocolVersion, codecRegistry));
    } else {
     size +=
       CBUtil.sizeOfValueList(Arrays.asList(getValues(protocolVersion, codecRegistry)));
   if (getPagingState() != null) {
    size += CBUtil.sizeOfValue(getPagingState());
   size += CBUtil.sizeOfConsistencyLevel(getSerialConsistencyLevel());
   if (ProtocolFeature.CLIENT_TIMESTAMPS.isSupportedBy(protocolVersion)) {
    size += 8; // timestamp
     && getOutgoingPayload() != null) {
    size += CBUtil.sizeOfBytesMap(getOutgoingPayload());

代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core

((com.datastax.driver.core.querybuilder.BuiltStatement) rs).setForceNoValues(true);
ByteBuffer[] rawPositionalValues = rs.getValues(protocolVersion, codecRegistry);
Map<String, ByteBuffer> rawNamedValues = rs.getNamedValues(protocolVersion, codecRegistry);
  rawNamedValues == null ? Collections.<String, ByteBuffer>emptyMap() : rawNamedValues;
String qString = rs.getQueryString(codecRegistry);

代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core

/** {@inheritDoc} */
@Override
public ListenableFuture<PreparedStatement> prepareAsync(final RegularStatement statement) {
 if (statement.hasValues())
  throw new IllegalArgumentException("A statement to prepare should not have values");
 final CodecRegistry codecRegistry = getCluster().getConfiguration().getCodecRegistry();
 ListenableFuture<PreparedStatement> prepared =
   prepareAsync(statement.getQueryString(codecRegistry), statement.getOutgoingPayload());
 return GuavaCompatibility.INSTANCE.transform(
   prepared,
   new Function<PreparedStatement, PreparedStatement>() {
    @Override
    public PreparedStatement apply(PreparedStatement prepared) {
     ProtocolVersion protocolVersion =
       getCluster().getConfiguration().getProtocolOptions().getProtocolVersion();
     ByteBuffer routingKey = statement.getRoutingKey(protocolVersion, codecRegistry);
     if (routingKey != null) prepared.setRoutingKey(routingKey);
     if (statement.getConsistencyLevel() != null)
      prepared.setConsistencyLevel(statement.getConsistencyLevel());
     if (statement.getSerialConsistencyLevel() != null)
      prepared.setSerialConsistencyLevel(statement.getSerialConsistencyLevel());
     if (statement.isTracing()) prepared.enableTracing();
     prepared.setRetryPolicy(statement.getRetryPolicy());
     prepared.setOutgoingPayload(statement.getOutgoingPayload());
     prepared.setIdempotent(statement.isIdempotent());
     return prepared;
    }
   });
}

代码示例来源:origin: com.stratio.cassandra/cassandra-driver-core

@Override
  public PreparedStatement apply(PreparedStatement prepared) {
    ByteBuffer routingKey = statement.getRoutingKey();
    if (routingKey != null)
      prepared.setRoutingKey(routingKey);
    prepared.setConsistencyLevel(statement.getConsistencyLevel());
    if (statement.isTracing())
      prepared.enableTracing();
    prepared.setRetryPolicy(statement.getRetryPolicy());
    return prepared;
  }
});

代码示例来源:origin: org.caffinitas.mapper/caffinitas-mapper-core

queryKeyspace = rstmt.getKeyspace();
queryString = rstmt.getQueryString();
    q = ((BoundStatement)st).preparedStatement().getQueryString();
  else if (st instanceof RegularStatement)
    q = ((RegularStatement)st).getQueryString();
  else
    continue;

代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core

@Override
public ByteBuffer[] getValues(ProtocolVersion protocolVersion, CodecRegistry codecRegistry) {
 // If there is some non-BuiltStatement inside the batch with values, we shouldn't
 // use super.getValues() since it will ignore the values of said non-BuiltStatement.
 // If that's the case, we just collects all those values (and we know
 // super.getValues() == null in that case since we've explicitely set this.hasBindMarker
 // to true). Otherwise, we simply call super.getValues().
 if (nonBuiltStatementValues == 0) return super.getValues(protocolVersion, codecRegistry);
 ByteBuffer[] values = new ByteBuffer[nonBuiltStatementValues];
 int i = 0;
 for (RegularStatement statement : statements) {
  if (statement instanceof BuiltStatement) continue;
  ByteBuffer[] statementValues = statement.getValues(protocolVersion, codecRegistry);
  System.arraycopy(statementValues, 0, values, i, statementValues.length);
  i += statementValues.length;
 }
 return values;
}

代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core

private RegularStatement statementWithIdempotency(Boolean idempotency) {
  RegularStatement statement = new SimpleStatement("fake statement");
  if (idempotency != null) {
   statement.setIdempotent(idempotency);
   assertThat(statement.isIdempotent()).isEqualTo(idempotency);
  } else {
   assertThat(statement.isIdempotent()).isNull();
  }
  return statement;
 }
}

代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core

/**
 * Returns the first non-null routing key of the statements in this batch or null otherwise.
 *
 * @return the routing key for this batch statement.
 */
@Override
public ByteBuffer getRoutingKey(ProtocolVersion protocolVersion, CodecRegistry codecRegistry) {
 for (RegularStatement statement : statements) {
  ByteBuffer routingKey = statement.getRoutingKey(protocolVersion, codecRegistry);
  if (routingKey != null) {
   return routingKey;
  }
 }
 return null;
}

代码示例来源:origin: com.stratio.cassandra/cassandra-driver-core

/**
 * {@inheritDoc}
 */
@Override
public ListenableFuture<PreparedStatement> prepareAsync(final RegularStatement statement) {
  if (statement.getValues() != null)
    throw new IllegalArgumentException("A statement to prepare should not have values");
  ListenableFuture<PreparedStatement> prepared = prepareAsync(statement.toString());
  return Futures.transform(prepared, new Function<PreparedStatement, PreparedStatement>() {
    @Override
    public PreparedStatement apply(PreparedStatement prepared) {
      ByteBuffer routingKey = statement.getRoutingKey();
      if (routingKey != null)
        prepared.setRoutingKey(routingKey);
      prepared.setConsistencyLevel(statement.getConsistencyLevel());
      if (statement.isTracing())
        prepared.enableTracing();
      prepared.setRetryPolicy(statement.getRetryPolicy());
      return prepared;
    }
  });
}

代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core

/**
 * Returns the query string for this statement.
 *
 * <p>This method calls {@link #getQueryString(CodecRegistry)} with {@link
 * CodecRegistry#DEFAULT_INSTANCE}. Whether you should use this or the other variant depends on
 * the type of statement this is called on:
 *
 * <ul>
 *   <li>for a {@link SimpleStatement} or {@link SchemaStatement}, the codec registry isn't
 *       actually needed, so it's always safe to use this method;
 *   <li>for a {@link BuiltStatement} you can use this method if you use no custom codecs, or if
 *       your custom codecs are registered with the default registry. Otherwise, use the other
 *       method and provide the registry that contains your codecs (see {@link BuiltStatement} for
 *       more explanations on why this is so);
 *   <li>for a {@link BatchStatement}, use the first rule if it contains no built statements, or
 *       the second rule otherwise.
 * </ul>
 *
 * @return a valid CQL query string.
 */
public String getQueryString() {
 return getQueryString(CodecRegistry.DEFAULT_INSTANCE);
}

代码示例来源:origin: com.yugabyte/cassandra-driver-core

((com.datastax.driver.core.querybuilder.BuiltStatement) rs).setForceNoValues(true);
ByteBuffer[] rawPositionalValues = rs.getValues(protocolVersion, codecRegistry);
Map<String, ByteBuffer> rawNamedValues = rs.getNamedValues(protocolVersion, codecRegistry);
Map<String, ByteBuffer> namedValues = rawNamedValues == null ? Collections.<String, ByteBuffer>emptyMap() : rawNamedValues;
String qString = rs.getQueryString(codecRegistry);

代码示例来源:origin: com.yugabyte/cassandra-driver-core

/**
 * {@inheritDoc}
 */
@Override
public ListenableFuture<PreparedStatement> prepareAsync(final RegularStatement statement) {
  if (statement.hasValues())
    throw new IllegalArgumentException("A statement to prepare should not have values");
  final CodecRegistry codecRegistry = getCluster().getConfiguration().getCodecRegistry();
  ListenableFuture<PreparedStatement> prepared = prepareAsync(statement.getQueryString(codecRegistry), statement.getOutgoingPayload());
  return Futures.transform(prepared, new Function<PreparedStatement, PreparedStatement>() {
    @Override
    public PreparedStatement apply(PreparedStatement prepared) {
      ProtocolVersion protocolVersion = getCluster().getConfiguration().getProtocolOptions().getProtocolVersion();
      ByteBuffer routingKey = statement.getRoutingKey(protocolVersion, codecRegistry);
      if (routingKey != null)
        prepared.setRoutingKey(routingKey);
      if (statement.getConsistencyLevel() != null)
        prepared.setConsistencyLevel(statement.getConsistencyLevel());
      if (statement.getSerialConsistencyLevel() != null)
        prepared.setSerialConsistencyLevel(statement.getSerialConsistencyLevel());
      if (statement.isTracing())
        prepared.enableTracing();
      prepared.setRetryPolicy(statement.getRetryPolicy());
      prepared.setOutgoingPayload(statement.getOutgoingPayload());
      prepared.setIdempotent(statement.isIdempotent());
      return prepared;
    }
  });
}

代码示例来源:origin: io.prestosql.cassandra/cassandra-driver

statement = ((StatementWrapper) statement).getWrappedStatement();
if ((statement instanceof RegularStatement) && ((RegularStatement) statement).usesNamedValues()) {
  throw new IllegalArgumentException("Batch statement cannot contain regular statements with named values ("
      + ((RegularStatement) statement).getQueryString() + ")");

代码示例来源:origin: com.yugabyte/cassandra-driver-core

@Override
public ByteBuffer[] getValues(ProtocolVersion protocolVersion, CodecRegistry codecRegistry) {
  // If there is some non-BuiltStatement inside the batch with values, we shouldn't
  // use super.getValues() since it will ignore the values of said non-BuiltStatement.
  // If that's the case, we just collects all those values (and we know
  // super.getValues() == null in that case since we've explicitely set this.hasBindMarker
  // to true). Otherwise, we simply call super.getValues().
  if (nonBuiltStatementValues == 0)
    return super.getValues(protocolVersion, codecRegistry);
  ByteBuffer[] values = new ByteBuffer[nonBuiltStatementValues];
  int i = 0;
  for (RegularStatement statement : statements) {
    if (statement instanceof BuiltStatement)
      continue;
    ByteBuffer[] statementValues = statement.getValues(protocolVersion, codecRegistry);
    System.arraycopy(statementValues, 0, values, i, statementValues.length);
    i += statementValues.length;
  }
  return values;
}

代码示例来源:origin: com.datastax.dse/dse-java-driver-core

private RegularStatement statementWithIdempotency(Boolean idempotency) {
  RegularStatement statement = new SimpleStatement("fake statement");
  if (idempotency != null) {
   statement.setIdempotent(idempotency);
   assertThat(statement.isIdempotent()).isEqualTo(idempotency);
  } else {
   assertThat(statement.isIdempotent()).isNull();
  }
  return statement;
 }
}

相关文章