All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.cassandraunit.utils.CqlOperations Maven / Gradle / Ivy

There is a newer version: 4.3.1.0
Show newest version
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");
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy