org.cassandraunit.utils.CqlOperations Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cassandra-unit Show documentation
Show all versions of cassandra-unit Show documentation
Test framework to develop with Cassandra
package org.cassandraunit.utils;
import com.datastax.driver.core.Session;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.function.Consumer;
public class CqlOperations {
private static final Logger log = LoggerFactory.getLogger(CqlOperations.class);
public static Consumer execute(Session session) {
return query -> {
log.debug("executing : {}", query);
session.execute(query);
};
}
public static Consumer use(Session session) {
return keyspace -> session.execute("USE " + keyspace);
}
public static Consumer truncateTable(Session session) {
return fullyQualifiedTable -> session.execute("truncate table " + fullyQualifiedTable);
}
public static Consumer dropKeyspace(Session session) {
return keyspace -> execute(session).accept("DROP KEYSPACE IF EXISTS " + keyspace);
}
public static Consumer createKeyspace(Session session) {
return keyspace -> execute(session).accept("CREATE KEYSPACE IF NOT EXISTS " + keyspace + " WITH replication={'class' : 'SimpleStrategy', 'replication_factor':1} AND durable_writes = false");
}
}