Last active
August 29, 2015 14:15
-
-
Save chbatey/c0d92981f92cd6feef5a to your computer and use it in GitHub Desktop.
Batch insert
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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