Pacific-Design.com

    
Home Index

1. Cassandra

2. Scala

Cassandra / Scala /

Cassandra Increase Timeout


$ cqlsh --request-timeout 120 192.168.0.101

Cassandra SQL query with Scala

import com.datastax.driver.core.Cluster;
import com.datastax.driver.core.Session;

object Cassandra {

  val clusterBuilder = Cluster.builder()
  clusterBuilder.addContactPoint("127.0.0.1")
  clusterBuilder.withPort(9042)
  // clusterBuilder.withCredentials("admin", "password") // optional
  val cluster = clusterBuilder.build()
  val session = cluster.connect("kevin")

  def getQueryResult(): Cassandra.type = {

    println(session.getCluster().getClusterName + " connection successful\n")
    System.out.println("system.local: " + session.execute("select now() from system.local").one().getUUID(0));
    val list = session.execute("SELECT * FROM kevin.test").all()
    println(list)

    return this
  }

  def disconnect(str: String) {
    cluster.close()
    session.close()
    println("\n" +
      "" + str + " successfully closed")
  }
}


object App {

  def main(args: Array[String]) {

    try {
      Cassandra.getQueryResult().disconnect("method: getQueryResult")
    } catch {
      case e: Exception => println("exception caught: " + e);
    }

  }
}