Java Code Examples for com.datastax.driver.core.querybuilder.QueryBuilder#insertInto()

The following examples show how to use com.datastax.driver.core.querybuilder.QueryBuilder#insertInto() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CassandraEventRecorder.java    From eventapis with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 2
Source File: WordCountAndSourceMapper.java    From storm-cassandra-cql with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example 3
Source File: SaveToCassandraOperationsService.java    From Decision with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 4
Source File: CassandraTable.java    From ingestion with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 5
Source File: PutCassandraRecord.java    From nifi with Apache License 2.0 5 votes vote down vote up
private Statement generateInsert(String cassandraTable, RecordSchema schema, Map<String, Object> recordContentMap) {
    Insert insertQuery;
    if (cassandraTable.contains(".")) {
        String[] keyspaceAndTable = cassandraTable.split("\\.");
        insertQuery = QueryBuilder.insertInto(keyspaceAndTable[0], keyspaceAndTable[1]);
    } else {
        insertQuery = QueryBuilder.insertInto(cassandraTable);
    }
    for (String fieldName : schema.getFieldNames()) {
        insertQuery.value(fieldName, recordContentMap.get(fieldName));
    }
    return insertQuery;
}
 
Example 6
Source File: CassandraPersistWriter.java    From streams with Apache License 2.0 4 votes vote down vote up
private void createInsertStatement() {
  Insert insertBuilder = QueryBuilder.insertInto(config.getTable());
  insertBuilder.value(config.getPartitionKeyColumn(), new Object());
  insertBuilder.value(config.getColumn(), new Object());
  insertStatement = session.prepare(insertBuilder.getQueryString());
}
 
Example 7
Source File: CassandraOperations.java    From geowave with Apache License 2.0 4 votes vote down vote up
public Insert getInsert(final String table) {
  return QueryBuilder.insertInto(gwNamespace, getCassandraSafeName(table));
}