本文整理匯總了Java中com.datastax.driver.core.querybuilder.QueryBuilder.insertInto方法的典型用法代碼示例。如果您正苦於以下問題:Java QueryBuilder.insertInto方法的具體用法?Java QueryBuilder.insertInto怎麽用?Java QueryBuilder.insertInto使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.datastax.driver.core.querybuilder.QueryBuilder
的用法示例。
在下文中一共展示了QueryBuilder.insertInto方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: cqlBuilders
import com.datastax.driver.core.querybuilder.QueryBuilder; //導入方法依賴的package包/類
private static void cqlBuilders() {
FieldModel model = SampleModels.wrapper();
Create create = SchemaBuilder.createTable("Field").addClusteringColumn(LOGIN.name(), text())
.addPartitionKey("snapshot_id", timeuuid());
model.getFieldInfos().stream().filter(f -> f.id() != LOGIN)
.forEach(f -> create.addColumn(f.id().name(), cqlType(f)));
Create.Options createWithOptions = create.withOptions().clusteringOrder(LOGIN.name(), DESC);
System.out.println(createWithOptions);
Insert insert = QueryBuilder.insertInto("Field");
model.stream().forEach(e -> insert.value(e.getKey().name(), e.getValue()));
System.out.println(insert.getQueryString(codecRegistry()));
}
示例2: createInsertQuery
import com.datastax.driver.core.querybuilder.QueryBuilder; //導入方法依賴的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;
}
示例3: save
import com.datastax.driver.core.querybuilder.QueryBuilder; //導入方法依賴的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);
}
示例4: simpleCasandraInsert
import com.datastax.driver.core.querybuilder.QueryBuilder; //導入方法依賴的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.QueryBuilder; //導入方法依賴的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.QueryBuilder; //導入方法依賴的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.QueryBuilder; //導入方法依賴的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: createInsertStatement
import com.datastax.driver.core.querybuilder.QueryBuilder; //導入方法依賴的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;
}
示例9: save
import com.datastax.driver.core.querybuilder.QueryBuilder; //導入方法依賴的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);
}