Database Reference
In-Depth Information
Disconnecting
To disconnect from the cluster, all you need to do is call
Shutdown
on the cluster
object.
Listing 9.10
shows how to do this.
Listing 9.10
Using C# to Disconnect from a Cluster
public void Close() {
cluster.Shutdown();
}
Schema Creation
Now that all of the connections have been created, we can create our schema.
When creating the schema, we can use the optional
IF NOT EXISTS
condition-
al, which will allow running the command multiple times without error. When this
conditional is not specified, additional executions of the schema creation code will
result in a
QueryExecutionException
. This conditional is available only in
Cassandra 2.0 and later.
Listing 9.11
shows how to create a keyspace and a sample
table.
Listing 9.11
Creating a Schema in C#
public void CreateSchema() {
session.Execute("CREATE KEYSPACE IF NOT EXISTS
portfolio_demo " +
"WITH REPLICATION = { 'class': 'Sim-
pleStrategy', " +
"'replication_factor': 1 };");
session.Execute("CREATE TABLE IF NOT EXISTS port-
folio_demo.portfolio (" +
"portfolio_id UUID, ticker TEXT, " +
"current_price DECIMAL, current_change
DECIMAL, " +
"current_change_percent FLOAT, " +
"PRIMARY KEY(portfolio_id, ticker));");
}