-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCreateTableWithSchemaBuilder.java
More file actions
31 lines (29 loc) · 1.46 KB
/
CreateTableWithSchemaBuilder.java
File metadata and controls
31 lines (29 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/**
* @author Created by Madhavan Sridharan on Jan 18, 2021 9:08:07 PM.
*/
package com.madhavan.demos.schemabuilder;
import com.datastax.oss.driver.api.core.CqlSession;
import com.datastax.oss.driver.api.core.type.DataTypes;
import com.datastax.oss.driver.api.querybuilder.SchemaBuilder;
/**
* @see <a href="https://docs.datastax.com/en/developer/java-driver/latest/manual/query_builder/schema/">Java Driver Schema Builder</a>
* @see <a href="https://docs.datastax.com/en/developer/java-driver/latest/manual/core/dse/geotypes/">Java Driver Geospatial Documentation<a/>
*
* @author Madhavan Sridharan (@msmygit)
*
*/
public class CreateTableWithSchemaBuilder {
public static void main(String... args) {
try (CqlSession session = CqlSession.builder().build()) {
//CREATE KEYSPACE IF NOT EXISTS test WITH replication = {'class':'NetworkTopologyStrategy', 'dc1':1}
session.execute(SchemaBuilder.createKeyspace("test").ifNotExists()
.withNetworkTopologyStrategy(ImmutableMap.of("dc1", 1));
session.execute(SchemaBuilder.createTable("test", "create_table_with_schema_builder").ifNotExists()
.withPartitionKey("pk1", DataTypes.INT)
.withColumn("c1_pointtype", DataTypes.custom("org.apache.cassandra.db.marshal.PointType"))
.withColumn("c2_linestringtype", DataTypes.custom("org.apache.cassandra.db.marshal.LineStringType"))
.withColumn("c2_polygontype", DataTypes.custom("org.apache.cassandra.db.marshal.PolygonType"))
.build());
}
}
}