com.datastax.driver.core.querybuilder.Update.where()方法的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(9.9k)|赞(0)|评价(0)|浏览(103)

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

Update.where介绍

[英]Returns a Where statement for this query without adding clause.
[中]返回此查询的Where语句,但不添加子句。

代码示例

代码示例来源:origin: brianfrankcooper/YCSB

updateStmt.where(QueryBuilder.eq(YCSB_KEY, QueryBuilder.bindMarker()));

代码示例来源:origin: apache/usergrid

private void decrementCounterInStorage( String queueName, DatabaseQueueMessage.Type type, long decrement ) {
  Statement update = QueryBuilder.update( TABLE_MESSAGE_COUNTERS )
    .where( QueryBuilder.eq(   COLUMN_QUEUE_NAME, queueName ) )
    .and(   QueryBuilder.eq(   COLUMN_MESSAGE_TYPE, type.toString() ) )
    .with(  QueryBuilder.decr( COLUMN_COUNTER_VALUE, decrement ) );
  cassandraClient.getQueueMessageSession().execute( update );
}

代码示例来源:origin: apache/usergrid

private void incrementCounterInStorage( String queueName, DatabaseQueueMessage.Type type, long increment ) {
  Statement update = QueryBuilder.update( TABLE_MESSAGE_COUNTERS )
      .where( QueryBuilder.eq(   COLUMN_QUEUE_NAME, queueName ) )
      .and(   QueryBuilder.eq(   COLUMN_MESSAGE_TYPE, type.toString() ) )
      .with(  QueryBuilder.incr( COLUMN_COUNTER_VALUE, increment ) );
  cassandraClient.getQueueMessageSession().execute( update );
}

代码示例来源:origin: apache/usergrid

void incrementCounterInStorage( String queueName, Shard.Type type, long shardId, long increment ) {
  Statement update = QueryBuilder.update( TABLE_COUNTERS )
      .where( QueryBuilder.eq(   COLUMN_QUEUE_NAME, queueName ) )
      .and(   QueryBuilder.eq(   COLUMN_SHARD_TYPE, type.toString() ) )
      .and(   QueryBuilder.eq(   COLUMN_SHARD_ID, shardId ) )
      .with(  QueryBuilder.incr( COLUMN_COUNTER_VALUE, increment ) );
  cassandraClient.getQueueMessageSession().execute( update );
}

代码示例来源:origin: kaaproject/kaa

@Override
public Optional<CassandraCredentials> updateStatus(String applicationId,
                          String credentialsId,
                          CredentialsStatus status) {
 LOG.debug("Updating credentials status with applicationID[{}] "
     + "and credentialsID[{}] to STATUS[{}]",
   applicationId, credentialsId, status.toString());
 Update.Assignments query = update(getColumnFamilyName())
   .where(eq(CREDENTIALS_ID_PROPERTY, credentialsId))
   .and(eq(CREDENTIALS_APPLICATION_ID_PROPERTY, applicationId))
   .with(set(CREDENTIALS_STATUS_PROPERTY, status.toString()));
 execute(query);
 return find(applicationId, credentialsId);
}

代码示例来源:origin: apache/usergrid

@Override
public void resetCounter(String queueName, DatabaseQueueMessage.Type type) {
  // this sucks: "You cannot index, delete, or re-add a counter column"
  // https://docs.datastax.com/en/cql/3.1/cql/cql_using/use_counter_t.html
  // so instead we decrement or increment the counter to zero
  // get value first, before resetting in memory counter
  long value = getCounterValue( queueName, type );
  String key = buildKey( queueName, type );
  InMemoryCount inMemoryCount = inMemoryCounters.get( key );
  if ( inMemoryCount != null ) {
    inMemoryCount.reset();
  }
  if ( value < 0 ) {
    Statement update = QueryBuilder.update( TABLE_MESSAGE_COUNTERS )
      .where( QueryBuilder.eq(   COLUMN_QUEUE_NAME, queueName ) )
      .and(   QueryBuilder.eq(   COLUMN_MESSAGE_TYPE, type.toString() ) )
      .with(  QueryBuilder.incr( COLUMN_COUNTER_VALUE, -1 * value ) ); // incr must be positive
    cassandraClient.getQueueMessageSession().execute( update );
  } else {
    Statement update = QueryBuilder.update( TABLE_MESSAGE_COUNTERS )
      .where( QueryBuilder.eq(   COLUMN_QUEUE_NAME, queueName ) )
      .and(   QueryBuilder.eq(   COLUMN_MESSAGE_TYPE, type.toString() ) )
      .with(  QueryBuilder.decr( COLUMN_COUNTER_VALUE, value ) );
    cassandraClient.getQueueMessageSession().execute( update );
  }
}

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

/**
 * Adds a where clause to the UPDATE statement these options are part of.
 *
 * @param clause clause to add.
 * @return the WHERE clause of the UPDATE statement these options are part of.
 */
public Where where(Clause clause) {
 return statement.where(clause);
}

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

/**
 * Adds a where clause to the UPDATE statement these conditions are part of.
 *
 * @param clause clause to add.
 * @return the WHERE clause of the UPDATE statement these conditions are part of.
 */
public Where where(Clause clause) {
 return statement.where(clause);
}

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

/**
 * Adds a where clause to the UPDATE statement those assignments are part of.
 *
 * @param clause the clause to add.
 * @return the where clause of the UPDATE statement those assignments are part of.
 */
public Where where(Clause clause) {
 return statement.where(clause);
}

代码示例来源:origin: apache/usergrid

.where( QueryBuilder.eq(   COLUMN_QUEUE_NAME, queueName ) )
.and(   QueryBuilder.eq(   COLUMN_SHARD_TYPE, type.toString() ) )
.and(   QueryBuilder.eq(   COLUMN_SHARD_ID, shardId ) )
.where( QueryBuilder.eq(   COLUMN_QUEUE_NAME, queueName ) )
.and(   QueryBuilder.eq(   COLUMN_SHARD_TYPE, type.toString() ) )
.and(   QueryBuilder.eq(   COLUMN_SHARD_ID, shardId ) )

代码示例来源:origin: hugegraph/hugegraph

@Override
  public void insert(CassandraSessionPool.Session session,
            CassandraBackendEntry.Row entry) {
    Map<HugeKeys, Object> columns = entry.columns();
    assert columns.containsKey(HugeKeys.ID);
    Object id = columns.get(HugeKeys.ID);
    Object label = columns.get(HugeKeys.LABEL);
    E.checkState(label != null,
           "The label of inserting vertex can't be null");
    Map<?, ?> properties = (Map<?, ?>) columns.get(HugeKeys.PROPERTIES);
    E.checkState(properties != null,
           "The properties of inserting vertex can't be null");
    Update update = QueryBuilder.update(table());
    update.with(QueryBuilder.set(formatKey(HugeKeys.LABEL), label));
    update.with(QueryBuilder.putAll(formatKey(HugeKeys.PROPERTIES),
                    properties));
    update.where(formatEQ(HugeKeys.ID, id));
    session.add(update);
  }
}

代码示例来源:origin: pulsarIO/realtime-analytics

Update update = QueryBuilder.update(columnFamilyName);
update.with(QueryBuilder.incr("value", entry.getCount()));
update.where(QueryBuilder.eq("metricname", metricName))
    .and(QueryBuilder.eq("groupid", entry.getGroupId()))
    .and(QueryBuilder.eq("metrictime",
  update.where(QueryBuilder.eq(entryInTag.getKey(),
      entryInTag.getValue()));

代码示例来源:origin: hugegraph/hugegraph

public void increaseCounter(CassandraSessionPool.Session session,
                HugeType type, long increment) {
    Update update = QueryBuilder.update(TABLE);
    update.with(QueryBuilder.incr(formatKey(HugeKeys.ID), increment));
    update.where(formatEQ(HugeKeys.SCHEMA_TYPE, type.name()));
    session.execute(update);
  }
}

代码示例来源:origin: hugegraph/hugegraph

public void insert(CassandraSessionPool.Session session,
          CassandraBackendEntry.Row entry) {
  Update update = QueryBuilder.update(this.table);
  update.with(QueryBuilder.add(ELEMENT_IDS, entry.id().asLong()));
  update.where(CassandraTable.formatEQ(HugeKeys.NAME,
                     entry.column(HugeKeys.NAME)));
  session.add(update);
}

代码示例来源:origin: hugegraph/hugegraph

/**
 * Append several elements to the collection column of a row
 */
@Override
public void append(CassandraSessionPool.Session session,
          CassandraBackendEntry.Row entry) {
  List<HugeKeys> idNames = this.idColumnName();
  List<HugeKeys> colNames = this.modifiableColumnName();
  Map<HugeKeys, Object> columns = entry.columns();
  Update update = QueryBuilder.update(table());
  for (HugeKeys key : colNames) {
    if (!columns.containsKey(key)) {
      continue;
    }
    String name = formatKey(key);
    Object value = columns.get(key);
    if (value instanceof Map) {
      update.with(QueryBuilder.putAll(name, (Map<?, ?>) value));
    } else if (value instanceof List) {
      update.with(QueryBuilder.appendAll(name, (List<?>) value));
    } else {
      update.with(QueryBuilder.append(name, value));
    }
  }
  for (HugeKeys idName : idNames) {
    assert columns.containsKey(idName);
    update.where(formatEQ(idName, columns.get(idName)));
  }
  session.add(update);
}

代码示例来源:origin: hugegraph/hugegraph

/**
 * Remove data from label index table
 */
private static void removeLabelIndex(CassandraSessionPool.Session session,
                   String table,
                   CassandraBackendEntry.Row entry) {
  Update update = QueryBuilder.update(table);
  Object label = entry.column(HugeKeys.LABEL);
  if (label == null) {
    // Maybe delete edges by edge label(passed by id)
    assert entry.id().asString().indexOf(':') < 0 : entry;
    return;
  }
  update.with(QueryBuilder.remove(ELEMENT_IDS,
                  IdUtil.writeString(entry.id())));
  update.where(CassandraTable.formatEQ(HugeKeys.LABEL, label));
  session.add(update);
}

代码示例来源:origin: hugegraph/hugegraph

update.where(formatEQ(idName, columns.get(idName)));

代码示例来源:origin: hugegraph/hugegraph

/**
 * Append data to label index table
 */
private static void appendLabelIndex(CassandraSessionPool.Session session,
                   String table,
                   CassandraBackendEntry.Row entry) {
  Update update = QueryBuilder.update(table);
  update.with(QueryBuilder.append(ELEMENT_IDS,
                  IdUtil.writeString(entry.id())));
  update.where(CassandraTable.formatEQ(HugeKeys.LABEL,
                     entry.column(HugeKeys.LABEL)));
  session.add(update);
}

代码示例来源:origin: hugegraph/hugegraph

public void delete(CassandraSessionPool.Session session,
          CassandraBackendEntry.Row entry,
          String mainTable) {
  // Get name from main table by id
  Select select = QueryBuilder.select().from(mainTable);
  select.where(CassandraTable.formatEQ(HugeKeys.ID,
                     entry.id().asLong()));
  ResultSet resultSet = session.execute(select);
  List<Row> rows = resultSet.all();
  if (rows.size() == 0) {
    return;
  }
  String name = rows.get(0).getString(HugeKeys.NAME.string());
  Update update = QueryBuilder.update(this.table);
  update.with(QueryBuilder.remove(ELEMENT_IDS, entry.id().asLong()));
  update.where(CassandraTable.formatEQ(HugeKeys.NAME, name));
  session.add(update);
}

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

@Test(groups = "unit")
public void updateInjectionTest() throws Exception {
 String query;
 Statement update;
 query = "UPDATE foo.bar USING TIMESTAMP 42 SET a=12 WHERE k='2 OR 1=1';";
 update =
   update("foo", "bar").using(timestamp(42)).with(set("a", 12)).where(eq("k", "2 OR 1=1"));
 assertEquals(update.toString(), query);
 query = "UPDATE foo SET b='null WHERE k=1; --comment' WHERE k=2;";
 update = update("foo").where().and(eq("k", 2)).with(set("b", "null WHERE k=1; --comment"));
 assertEquals(update.toString(), query);
 query =
   "UPDATE foo USING TIMESTAMP 42 SET \"b WHERE k=1; --comment\"=[3,2,1]+\"b WHERE k=1; --comment\" WHERE k=2;";
 update =
   update("foo")
     .where()
     .and(eq("k", 2))
     .with(prependAll("b WHERE k=1; --comment", Arrays.asList(3, 2, 1)))
     .using(timestamp(42));
 assertEquals(update.toString(), query);
}

相关文章