Skip to content

Instantly share code, notes, and snippets.

@chbatey
Last active August 29, 2015 14:15
Show Gist options
  • Select an option

  • Save chbatey/c0d92981f92cd6feef5a to your computer and use it in GitHub Desktop.

Select an option

Save chbatey/c0d92981f92cd6feef5a to your computer and use it in GitHub Desktop.
Batch insert
private final static String insertByCustomerIdCql = "INSERT INTO events.customer_events (customer_id, time , event_type , statff_id , store_type ) VALUES ( ?, ?, ?, ?, ?)";
private final static String insertByStaffIdCql = "INSERT INTO events.customer_events_by_staff_id (customer_id, time , event_type , statff_id , store_type ) VALUES ( ?, ?, ?, ?, ?)";
public CustomerEventDao() {
cluster = Cluster.builder().addContactPoint("localhost").build();
session = cluster.connect("events");
insertByCustomerId = session.prepare(insertByCustomerIdCql);
insertByStaffId = session.prepare(insertByStaffIdCql);
}
public void storeEventLogged(ConsistencyLevel consistencyLevel, CustomerEvent customerEvent) {
BoundStatement boundInsertForCustomerId = insertByCustomerId.bind(customerEvent.getCustomerId(), customerEvent.getTime(), customerEvent.getEventType(), customerEvent.getStaffId(), customerEvent.getStaffId());
BoundStatement boundInsertForStaffId= insertByStaffId.bind(customerEvent.getCustomerId(), customerEvent.getTime(), customerEvent.getEventType(), customerEvent.getStaffId(), customerEvent.getStaffId());
BatchStatement batchStatement = new BatchStatement(BatchStatement.Type.LOGGED);
batchStatement.setConsistencyLevel(consistencyLevel);
batchStatement.add(boundInsertForCustomerId);
batchStatement.add(boundInsertForStaffId);
ResultSet execute = session.execute(batchStatement);
logTraceInfo(execute.getExecutionInfo());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment