Skip to content

Instantly share code, notes, and snippets.

@nobusue
Created May 4, 2015 03:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nobusue/1c9d51a6675d7aa5359d to your computer and use it in GitHub Desktop.
Save nobusue/1c9d51a6675d7aa5359d to your computer and use it in GitHub Desktop.
Cassandra Java Driverでデータのinsertとselectを行う
@Grapes(
@Grab(group='com.datastax.cassandra', module='cassandra-driver-core', version='2.1.5')
)
import com.datastax.driver.core.*
def cluster = Cluster.builder().addContactPoint('127.0.0.1').build()
def session = cluster.connect()
session.execute("INSERT INTO first_keyspace.first_table (name, value) VALUES ('foo', 'bar');");
session.execute("INSERT INTO first_keyspace.first_table (name, value) VALUES ('gee', 'baz');");
def resultSet = session.execute("select * from first_keyspace.first_table where name = 'gee';")
resultSet.each {
println it.getColumnDefinitions()
println it
}
session.close()
cluster.close()
@hrdmtr
Copy link

hrdmtr commented May 4, 2015

コンテステンシーレベルを指定する場合は、
Session#prepare(String)
PreparedStatement#setConsistencyLevel(ConsistencyLevel)
を使う感じでしょうか。

@hrdmtr
Copy link

hrdmtr commented May 4, 2015

def statement = session.prepare("INSERT INTO first_keyspace.first_table (name, value) VALUES ('foo', 'bar');")
statement.setConsistencyLevel(ConsistencyLevel.QUORUM)
session.execute(statement)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment