本文整理汇总了Java中com.datastax.driver.core.querybuilder.Insert.value方法的典型用法代码示例。如果您正苦于以下问题:Java Insert.value方法的具体用法?Java Insert.value怎么用?Java Insert.value使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.datastax.driver.core.querybuilder.Insert
的用法示例。
在下文中一共展示了Insert.value方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createInsertQuery
import com.datastax.driver.core.querybuilder.Insert; //导入方法依赖的package包/类
private Insert createInsertQuery(EntityEvent entityEvent) {
Insert insert = QueryBuilder.insertInto(tableName);
insert.value(ENTITY_ID, entityEvent.getEventKey().getEntityId());
insert.value(VERSION, entityEvent.getEventKey().getVersion());
insert.value(OP_ID, entityEvent.getOpId());
insert.value(OP_DATE, entityEvent.getOpDate());
insert.value(EVENT_TYPE, entityEvent.getEventType());
insert.value(STATUS, entityEvent.getStatus().name());
insert.value(AUDIT_INFO, entityEvent.getAuditInfo());
insert.value(EVENT_DATA, entityEvent.getEventData());
insert.ifNotExists();
return insert;
}
示例2: save
import com.datastax.driver.core.querybuilder.Insert; //导入方法依赖的package包/类
public void save(List<Event> events) {
final BatchStatement batch = new BatchStatement();
for (final Event event : events) {
final Map<String, Object> parsedEvent = parse(event);
if (parsedEvent.isEmpty()) {
log.warn("Event {} could not be mapped", event);
continue;
}
if (!hasPrimaryKey(parsedEvent)) {
break;
}
final Insert insert = QueryBuilder.insertInto(table);
for (final Map.Entry<String, Object> entry : parsedEvent.entrySet()) {
insert.value(entry.getKey(), entry.getValue());
}
if (log.isTraceEnabled()) {
log.trace("Preparing insert for table {}: {}", table.getName(), insert.getQueryString());
}
batch.add(insert);
}
if (batch.getStatements().isEmpty()) {
log.warn("No event produced insert query for table {}", table.getName());
return;
}
batch.setConsistencyLevel(consistencyLevel);
session.execute(batch);
}
示例3: generateInsert
import com.datastax.driver.core.querybuilder.Insert; //导入方法依赖的package包/类
/**
* Generate Insert CQL.
*/
public static Insert generateInsert(String table, String[] columns, boolean ifNotExists, Integer ttl) {
Insert insert = insertInto(table);
for (String column : columns) {
insert = insert.value(column, bindMarker());
}
if (ifNotExists) {
insert = insert.ifNotExists();
}
if (ttl != null) {
insert.using(ttl(ttl));
}
return insert;
}
示例4: simpleCasandraInsert
import com.datastax.driver.core.querybuilder.Insert; //导入方法依赖的package包/类
@Test
public void simpleCasandraInsert() {
FieldModel model = SampleModels.wrapper();
Insert insertRequest = QueryBuilder.insertInto("fields_model");
insertRequest.value("snapshot_id", UUID.randomUUID());
insertRequest.values(
model.stream().map(e -> e.getKey().name()).collect(toList()),
model.stream().map(Entry::getValue).collect(toList()));
print(insertRequest.getQueryString(codecRegistry()));
}
示例5: map
import com.datastax.driver.core.querybuilder.Insert; //导入方法依赖的package包/类
@Override
public Statement map(List<String> keys, Number value) {
Insert statement = QueryBuilder.insertInto(KEYSPACE_NAME, TABLE_NAME);
statement.value(WORD_KEY_NAME, keys.get(0));
statement.value(SOURCE_KEY_NAME, keys.get(1));
statement.value(VALUE_NAME, value);
return statement;
}
示例6: migrate
import com.datastax.driver.core.querybuilder.Insert; //导入方法依赖的package包/类
@Override
public void migrate(Session session) throws Exception {
Insert insert = QueryBuilder.insertInto("test1");
insert.value("space", "web");
insert.value("key", "google");
insert.value("value", "google.com");
session.execute(insert);
}
示例7: migrate
import com.datastax.driver.core.querybuilder.Insert; //导入方法依赖的package包/类
@Override
public void migrate(Session session) throws Exception {
Insert insert = QueryBuilder.insertInto("test1");
insert.value("space", "web");
insert.value("key", "facebook");
insert.value("value", "facebook.com");
session.execute(insert);
}
示例8: toInsertStatementAsync
import com.datastax.driver.core.querybuilder.Insert; //导入方法依赖的package包/类
private static ListenableFuture<Statement> toInsertStatementAsync(WriteQueryData data, ExecutionSpec executionSpec, UDTValueMapper udtValueMapper, DBSession dbSession) {
final Insert insert = (data.getTablename().getKeyspacename() == null) ? insertInto(data.getTablename().getTablename())
: insertInto(data.getTablename().getKeyspacename(), data.getTablename().getTablename());
final List<Object> values = Lists.newArrayList();
for(Entry<String, Optional<Object>> entry : data.getValuesToMutate().entrySet()) {
insert.value(entry.getKey(), bindMarker());
values.add(udtValueMapper.toStatementValue(data.getTablename(), entry.getKey(), entry.getValue().orNull()));
}
if (data.getIfNotExits() != null) {
insert.ifNotExists();
if (executionSpec.getSerialConsistencyLevel() != null) {
insert.setSerialConsistencyLevel(executionSpec.getSerialConsistencyLevel());
}
}
if (executionSpec.getTtl() != null) {
insert.using(ttl(bindMarker()));
values.add((Integer) executionSpec.getTtl());
}
final ListenableFuture<PreparedStatement> preparedStatementFuture = dbSession.prepareAsync(insert);
return dbSession.bindAsync(preparedStatementFuture, values.toArray());
}
示例9: createInsertStatement
import com.datastax.driver.core.querybuilder.Insert; //导入方法依赖的package包/类
public Insert createInsertStatement(String streamName, List<ColumnNameTypeValue> columns, String timestampColumnName) {
Insert insert = QueryBuilder.insertInto(addQuotes(STREAMING.STREAMING_KEYSPACE_NAME), addQuotes(streamName));
for (ColumnNameTypeValue column : columns) {
insert.value(addQuotes(column.getColumn()), column.getValue());
}
insert.value(addQuotes(timestampColumnName), UUIDs.timeBased());
return insert;
}
示例10: save
import com.datastax.driver.core.querybuilder.Insert; //导入方法依赖的package包/类
public void save(final List<Event> events) {
final BatchStatement batch = new BatchStatement();
for (final Event event : events) {
final Map<String, Object> parsedEvent = parse(event);
if (parsedEvent.isEmpty()) {
log.warn("Event {} could not be mapped. Suggestion: Cassandra is case sensitive, so maybe you can check field names.", event);
continue;
}
if (!hasPrimaryKey(parsedEvent)) {
break;
}
final Insert insert = QueryBuilder.insertInto(table);
for (final Map.Entry<String, Object> entry : parsedEvent.entrySet()) {
insert.value(entry.getKey(), entry.getValue());
}
if (log.isTraceEnabled()) {
log.trace("Preparing insert for table {}: {}", table.getName(), insert.getQueryString());
}
batch.add(insert);
}
if (batch.getStatements().isEmpty()) {
log.warn("No event produced insert query for table {}", table.getName());
return;
}
batch.setConsistencyLevel(consistencyLevel);
session.execute(batch);
}
示例11: declarePartitionKey
import com.datastax.driver.core.querybuilder.Insert; //导入方法依赖的package包/类
@Override public Insert declarePartitionKey(Insert insert) {
return insert.value("service_span_name", QueryBuilder.bindMarker("service_span_name"));
}
示例12: create
import com.datastax.driver.core.querybuilder.Insert; //导入方法依赖的package包/类
@Override
public <T> T create(T object, ConsistencyLevel consistency) {
checkNotNull(object, "object argument");
checkNotNull(consistency, "consistency argument");
checkState(m_isOpen, format("%s is closed", getClass().getSimpleName()));
checkArgument(
object.getClass().isAnnotationPresent(ENTITY),
format("%s not annotated with @%s", getClass().getSimpleName(), ENTITY.getCanonicalName()));
Schema schema = getSchema(object);
checkArgument(
schema.getID().getValue(object) == null,
format("property annotated with @%s must be null", ID.getCanonicalName()));
// Object persistence (incl. indices)
UUID id = UUID.randomUUID();
Batch batch = batch();
Insert insertStatement = insertInto(schema.getTableName()).value(schema.getID().getName(), id);
for (ColumnSpec colSpec : schema.getColumns()) {
insertStatement.value(colSpec.getName(), colSpec.getValue(object));
if (colSpec.isIndexed()) {
String tableName = indexTableName(schema.getTableName(), colSpec.getName());
batch.add(
insertInto(tableName)
.value(colSpec.getName(), colSpec.getValue(object))
.value(joinColumnName(schema.getTableName()), id)
);
}
}
batch.add(insertStatement);
// One-to-Many relationship persistence
for (OneToManySpec relationSpec : schema.getOneToManys()) {
Schema s = relationSpec.getSchema();
Object relations = relationSpec.getValue(object);
if (relations == null) {
continue;
}
for (Object item : (Collection<?>) relations) {
UUID relationID = (UUID) s.getID().getValue(item);
if (relationID == null) {
throw new IllegalStateException(
"encountered relation with null ID property (entity not persisted?)");
}
String joinTable = joinTableName(schema.getTableName(), s.getTableName());
batch.add(
insertInto(joinTable)
.value(joinColumnName(schema.getTableName()), id)
.value(joinColumnName(s.getTableName()), relationID)
);
}
}
executeStatement(batch, consistency);
schema.getID().setValue(object, id);
cacheInstance(object);
return object;
}