use of com.datastax.driver.core.BatchStatement in project aroma-data-operations by RedRoma.
the class CassandraUserRepository method createStatementToSaveUser.
private Statement createStatementToSaveUser(User user) {
BatchStatement batchStatement = new BatchStatement(BatchStatement.Type.LOGGED);
Statement insertIntoUsersTable = createInsertIntoUserTable(user);
batchStatement.add(insertIntoUsersTable);
Statement insertIntoUsersByEmailTable = createInsertIntoUsersByEmailTable(user);
batchStatement.add(insertIntoUsersByEmailTable);
if (!isNullOrEmpty(user.githubProfile)) {
Statement insertIntoUsersByGithubTable = createInsertIntoUsersByGithubTable(user);
batchStatement.add(insertIntoUsersByGithubTable);
}
Statement insertIntoRecentUsersTable = createInsertIntoRecentUsersTable(user);
batchStatement.add(insertIntoRecentUsersTable);
return batchStatement;
}
use of com.datastax.driver.core.BatchStatement in project pinpoint by naver.
the class CassandraDatastaxITBase method testBatchStatement_and_StatementWrapper.
@Test
public void testBatchStatement_and_StatementWrapper() throws Exception {
final String testId1 = "998";
final String testValue1 = "testValue998";
final String testId2 = "999";
final String testValue2 = "testValue999";
PluginTestVerifier verifier = PluginTestVerifierHolder.getInstance();
try (Session session = openSession(cluster)) {
// ===============================================
// Insert Data 2 x (PreparedStatement, BoundStatement)
PreparedStatement preparedStatement = session.prepare(CQL_INSERT);
BoundStatement boundStatement1 = new BoundStatement(preparedStatement);
boundStatement1.bind(testId1, testValue1);
BoundStatement boundStatement2 = new BoundStatement(preparedStatement);
boundStatement2.bind(testId2, testValue2);
BatchStatement batchStatement = new BatchStatement();
batchStatement.add(boundStatement1);
batchStatement.add(boundStatement2);
session.execute(batchStatement);
verifier.printCache();
// Cluster#connect(String)
Class<?> clusterClass = Class.forName("com.datastax.driver.core.Cluster");
Method connect = clusterClass.getDeclaredMethod("connect", String.class);
verifier.verifyTrace(event(CASSANDRA, connect, null, CASSANDRA_ADDRESS, TEST_KEYSPACE));
// SessionManager#prepare(String) OR AbstractSession#prepare(String)
Class<?> sessionClass;
try {
sessionClass = Class.forName("com.datastax.driver.core.AbstractSession");
} catch (ClassNotFoundException e) {
sessionClass = Class.forName("com.datastax.driver.core.SessionManager");
}
Method prepare = sessionClass.getDeclaredMethod("prepare", String.class);
verifier.verifyTrace(event(CASSANDRA, prepare, null, CASSANDRA_ADDRESS, TEST_KEYSPACE, sql(CQL_INSERT, null)));
// SessionManager#execute(Statement) OR AbstractSession#execute(Statement)
Method execute = sessionClass.getDeclaredMethod("execute", Statement.class);
verifier.verifyTrace(event(CASSANDRA_EXECUTE_QUERY, execute, null, CASSANDRA_ADDRESS, TEST_KEYSPACE));
// ====================
final String cqlDelete = String.format("DELETE FROM %s.%s WHERE %s IN (? , ?)", TEST_KEYSPACE, TEST_TABLE, TEST_COL_ID);
PreparedStatement deletePreparedStatement = session.prepare(cqlDelete);
BoundStatement deleteBoundStatement = new BoundStatement(deletePreparedStatement);
deleteBoundStatement.bind(testId1, testId2);
Statement wrappedDeleteStatement = new StatementWrapper(deleteBoundStatement) {
};
session.execute(wrappedDeleteStatement);
verifier.printCache();
// SessionManager#prepare(String) OR AbstractSession#prepare(String)
verifier.verifyTrace(event(CASSANDRA, prepare, null, CASSANDRA_ADDRESS, TEST_KEYSPACE, sql(cqlDelete, null)));
// SessionManager#execute(String, Object[]) OR AbstractSession#execute(String, Object[])
verifier.verifyTrace(event(CASSANDRA_EXECUTE_QUERY, execute, null, CASSANDRA_ADDRESS, TEST_KEYSPACE, sql(cqlDelete, null)));
}
}
Aggregations