Tabnine Logo
SchemaBuilder.createKeyspace
Code IndexAdd Tabnine to your IDE (free)

How to use
createKeyspace
method
in
com.datastax.driver.core.schemabuilder.SchemaBuilder

Best Java code snippets using com.datastax.driver.core.schemabuilder.SchemaBuilder.createKeyspace (Showing top 12 results out of 315)

origin: Netflix/conductor

private String getCreateKeyspaceStatement() {
  return SchemaBuilder.createKeyspace(config.getCassandraKeyspace())
      .ifNotExists()
      .with()
      .replication(ImmutableMap.of("class", config.getReplicationStrategy(), config.getReplicationFactorKey(), config.getReplicationFactorValue()))
      .durableWrites(true)
      .getQueryString();
}
origin: com.datastax.cassandra/cassandra-driver-core

 @Test(groups = "unit", expectedExceptions = IllegalArgumentException.class)
 public void incorrect_replication_options() throws Exception {
  Map<String, Object> replicationOptions = new HashMap<String, Object>();
  replicationOptions.put("class", 5);

  // When
  createKeyspace("test").with().replication(replicationOptions);
 }
}
origin: hugegraph/hugegraph

protected void initKeyspace() {
  // Replication strategy: SimpleStrategy or NetworkTopologyStrategy
  String strategy = this.conf.get(CassandraOptions.CASSANDRA_STRATEGY);
  // Replication factor
  int factor = this.conf.get(CassandraOptions.CASSANDRA_REPLICATION);
  Map<String, Object> replication = new HashMap<>();
  replication.putIfAbsent("class", strategy);
  replication.putIfAbsent("replication_factor", factor);
  Statement stmt = SchemaBuilder.createKeyspace(this.keyspace)
                 .ifNotExists().with()
                 .replication(replication);
  // Create keyspace with non-keyspace-session
  LOG.debug("Create keyspace: {}", stmt);
  Session session = this.cluster().connect();
  try {
    session.execute(stmt);
  } finally {
    if (!session.isClosed()) {
      session.close();
    }
  }
}
origin: com.datastax.cassandra/cassandra-driver-core

@Test(groups = "unit")
public void should_create_keyspace_with_options() throws Exception {
 Map<String, Object> replicationOptions = new HashMap<String, Object>();
 replicationOptions.put("class", "SimpleStrategy");
 replicationOptions.put("replication_factor", 1);
 // When
 SchemaStatement statement =
   createKeyspace("test").with().durableWrites(true).replication(replicationOptions);
 // Then
 assertThat(statement.getQueryString())
   .isEqualTo(
     "\n\tCREATE KEYSPACE test"
       + "\n\tWITH\n\t\t"
       + "REPLICATION = {'replication_factor': 1, 'class': 'SimpleStrategy'}\n\t\t"
       + "AND DURABLE_WRITES = true");
}
origin: com.datastax.cassandra/cassandra-driver-core

.execute(SchemaBuilder.createKeyspace(keyspace).with().replication(replicationOptions));
origin: locationtech/geowave

public void initKeyspace() {
 // TODO consider exposing important keyspace options through commandline
 // such as understanding how to properly enable cassandra in production
 // - with data centers and snitch, for now because this is only creating
 // a keyspace "if not exists" a user can create a keyspace matching
 // their geowave namespace with any settings they want manually
 session.execute(
   SchemaBuilder.createKeyspace(gwNamespace).ifNotExists().with().replication(
     ImmutableMap.of(
       "class",
       "SimpleStrategy",
       "replication_factor",
       options.getReplicationFactor())).durableWrites(options.isDurableWrites()));
}
origin: com.datastax.dse/dse-java-driver-core

 @Test(groups = "unit", expectedExceptions = IllegalArgumentException.class)
 public void incorrect_replication_options() throws Exception {
  Map<String, Object> replicationOptions = new HashMap<String, Object>();
  replicationOptions.put("class", 5);

  // When
  createKeyspace("test").with().replication(replicationOptions);
 }
}
origin: com.baidu.hugegraph/hugegraph-cassandra

protected void initKeyspace() {
  // Replication strategy: SimpleStrategy or NetworkTopologyStrategy
  String strategy = this.conf.get(CassandraOptions.CASSANDRA_STRATEGY);
  // Replication factor
  int factor = this.conf.get(CassandraOptions.CASSANDRA_REPLICATION);
  Map<String, Object> replication = new HashMap<>();
  replication.putIfAbsent("class", strategy);
  replication.putIfAbsent("replication_factor", factor);
  Statement stmt = SchemaBuilder.createKeyspace(this.keyspace)
                 .ifNotExists().with()
                 .replication(replication);
  // Create keyspace with non-keyspace-session
  LOG.debug("Create keyspace: {}", stmt);
  Session session = this.cluster().connect();
  try {
    session.execute(stmt);
  } finally {
    if (!session.isClosed()) {
      session.close();
    }
  }
}
origin: com.datastax.dse/dse-java-driver-core

@Test(groups = "unit")
public void should_create_keyspace_with_options() throws Exception {
 Map<String, Object> replicationOptions = new HashMap<String, Object>();
 replicationOptions.put("class", "SimpleStrategy");
 replicationOptions.put("replication_factor", 1);
 // When
 SchemaStatement statement =
   createKeyspace("test").with().durableWrites(true).replication(replicationOptions);
 // Then
 assertThat(statement.getQueryString())
   .isEqualTo(
     "\n\tCREATE KEYSPACE test"
       + "\n\tWITH\n\t\t"
       + "REPLICATION = {'replication_factor': 1, 'class': 'SimpleStrategy'}\n\t\t"
       + "AND DURABLE_WRITES = true");
}
origin: apache/streams

private void createKeyspaceAndTable() {
 Metadata metadata = client.cluster().getMetadata();
 if (Objects.isNull(metadata.getKeyspace(config.getKeyspace()))) {
  LOGGER.info("Keyspace {} does not exist. Creating Keyspace", config.getKeyspace());
  Map<String, Object> replication = new HashMap<>();
  replication.put("class", "SimpleStrategy");
  replication.put("replication_factor", 1);
  String createKeyspaceStmt = SchemaBuilder.createKeyspace(config.getKeyspace()).with()
    .replication(replication).getQueryString();
  client.cluster().connect().execute(createKeyspaceStmt);
 }
 session = client.cluster().connect(config.getKeyspace());
 KeyspaceMetadata ks = metadata.getKeyspace(config.getKeyspace());
 TableMetadata tableMetadata = ks.getTable(config.getTable());
 if (Objects.isNull(tableMetadata)) {
  LOGGER.info("Table {} does not exist in Keyspace {}. Creating Table", config.getTable(), config.getKeyspace());
  String createTableStmt = SchemaBuilder.createTable(config.getTable())
               .addPartitionKey(config.getPartitionKeyColumn(), DataType.varchar())
               .addColumn(config.getColumn(), DataType.blob()).getQueryString();
  session.execute(createTableStmt);
 }
}
origin: org.janusgraph/janusgraph-cql

Session initializeSession(final String keyspaceName) {
  final Session s = this.cluster.connect();
  // if the keyspace already exists, just return the session
  if (this.cluster.getMetadata().getKeyspace(keyspaceName) != null) {
    return s;
  }
  final Configuration configuration = getStorageConfig();
  // Setting replication strategy based on value reading from the configuration: either "SimpleStrategy" or "NetworkTopologyStrategy"
  final Map<String, Object> replication = Match(configuration.get(REPLICATION_STRATEGY)).of(
    Case($("SimpleStrategy"), strategy -> HashMap.<String, Object> of("class", strategy, "replication_factor", configuration.get(REPLICATION_FACTOR))),
    Case($("NetworkTopologyStrategy"),
      strategy -> HashMap.<String, Object> of("class", strategy)
        .merge(Array.of(configuration.get(REPLICATION_OPTIONS))
          .grouped(2)
          .toMap(array -> Tuple.of(array.get(0), Integer.parseInt(array.get(1)))))))
    .toJavaMap();
  s.execute(createKeyspace(keyspaceName)
      .ifNotExists()
      .with()
      .replication(replication));
  return s;
}
origin: com.datastax.dse/dse-java-driver-core

.execute(SchemaBuilder.createKeyspace(keyspace).with().replication(replicationOptions));
com.datastax.driver.core.schemabuilderSchemaBuildercreateKeyspace

Javadoc

Start building a new CREATE KEYSPACE statement.

Popular methods of SchemaBuilder

  • createTable
    Start building a new CREATE TABLE statement.
  • dropKeyspace
    Start building a new DROP KEYSPACE statement.
  • dropTable
    Start building a new DROP TABLE statement.
  • leveledStrategy
    Create options for the leveled compaction strategy, to use in a CREATE or ALTER TABLE statement.
  • lz4
    Create options for the LZ4 compression strategy, to use in a CREATE or ALTER TABLE statement.
  • sizedTieredStategy
    Create options for the size-tiered compaction strategy, for use in a CREATE or ALTER TABLE statement
  • createType
    Start building a new CREATE TYPE statement.
  • noSpeculativeRetry
    Create the speculative retry strategy that never retries reads, to use in a CREATE or ALTER TABLE st
  • createIndex
    Start building a new CREATE INDEX statement.
  • dateTieredStrategy
    Create options for the date-tiered compaction strategy, to use in a CREATE or ALTER TABLE statement.
  • deflate
    Create options for the Deflate compression strategy, to use in a CREATE or ALTER TABLE statement.
  • dropType
    Start building a new DROP TYPE statement.
  • deflate,
  • dropType,
  • noCompression,
  • snappy,
  • allRows,
  • alterKeyspace,
  • alterTable,
  • always,
  • dropIndex

Popular in Java

  • Creating JSON documents from java classes using gson
  • findViewById (Activity)
  • onCreateOptionsMenu (Activity)
  • scheduleAtFixedRate (ScheduledExecutorService)
  • HttpServer (com.sun.net.httpserver)
    This class implements a simple HTTP server. A HttpServer is bound to an IP address and port number a
  • BufferedWriter (java.io)
    Wraps an existing Writer and buffers the output. Expensive interaction with the underlying reader is
  • FileOutputStream (java.io)
    An output stream that writes bytes to a file. If the output file exists, it can be replaced or appen
  • DecimalFormat (java.text)
    A concrete subclass of NumberFormat that formats decimal numbers. It has a variety of features desig
  • JList (javax.swing)
  • Option (scala)
  • CodeWhisperer alternatives
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now