congrats Icon
New! Announcing Tabnine Chat Beta
Learn More
Tabnine Logo
Cluster.getMetadata
Code IndexAdd Tabnine to your IDE (free)

How to use
getMetadata
method
in
com.datastax.driver.core.Cluster

Best Java code snippets using com.datastax.driver.core.Cluster.getMetadata (Showing top 20 results out of 972)

Refine searchRefine arrow

  • Metadata.getKeyspace
origin: prestodb/presto

private void checkSizeEstimatesTableExist()
{
  KeyspaceMetadata keyspaceMetadata = executeWithSession(session -> session.getCluster().getMetadata().getKeyspace(SYSTEM));
  checkState(keyspaceMetadata != null, "system keyspace metadata must not be null");
  TableMetadata table = keyspaceMetadata.getTable(SIZE_ESTIMATES);
  if (table == null) {
    throw new PrestoException(NOT_SUPPORTED, "Cassandra versions prior to 2.1.5 are not supported");
  }
}
origin: kaaproject/kaa

protected UserType getUserType(String userType) {
 return getSession().getCluster().getMetadata().getKeyspace(KAA).getUserType(userType);
}
origin: apache/usergrid

private void createTable(TableDefinition tableDefinition, boolean forceCheckSchema) throws Exception {
  boolean exists;
  if(!forceCheckSchema){
    exists = dataStaxCluster.getClusterSession().getCluster()
      .getMetadata()
      .getKeyspace(CQLUtils.quote( tableDefinition.getKeyspace() ) )
      .getTable( tableDefinition.getTableName() ) != null;
  }else{
    exists = dataStaxCluster.getClusterSession()
      .execute("select * from system.schema_columnfamilies where keyspace_name='"+tableDefinition.getKeyspace()
        +"' and columnfamily_name='"+CQLUtils.unquote(tableDefinition.getTableName())+"'").one() != null;
  }
  if( exists ){
    logger.info("Not creating table {}, it already exists.", tableDefinition.getTableName());
    return;
  }
  String CQL = tableDefinition.getTableCQL(cassandraFig, TableDefinition.ACTION.CREATE);
  if (logger.isDebugEnabled()) {
    logger.debug(CQL);
  }
  if ( tableDefinition.getKeyspace().equals( cassandraFig.getApplicationKeyspace() )) {
    dataStaxCluster.getApplicationSession().execute( CQL );
  } else {
    dataStaxCluster.getApplicationLocalSession().execute( CQL );
  }
  logger.info("Created table: {} in keyspace {}",
    tableDefinition.getTableName(), tableDefinition.getKeyspace());
}
origin: apache/usergrid

/**
 * Execute CQL that will create the keyspace if it doesn't exist and alter it if it does.
 * @throws Exception
 * @param forceCheck
 */
@Override
public synchronized void createApplicationKeyspace(boolean forceCheck) throws Exception {
  boolean exists;
  if(!forceCheck) {
    // this gets info from client's metadata
    exists = getClusterSession().getCluster().getMetadata()
      .getKeyspace(CQLUtils.quote(cassandraConfig.getApplicationKeyspace())) != null;
  }else{
    exists = getClusterSession()
      .execute("select * from system.schema_keyspaces where keyspace_name = '"+cassandraConfig.getApplicationKeyspace()+"'")
      .one() != null;
  }
  if(exists){
    logger.info("Not creating keyspace {}, it already exists.", cassandraConfig.getApplicationKeyspace());
    return;
  }
  final String createApplicationKeyspace = String.format(
    "CREATE KEYSPACE IF NOT EXISTS %s WITH replication = %s",
    CQLUtils.quote( cassandraConfig.getApplicationKeyspace()),
    CQLUtils.getFormattedReplication( cassandraConfig.getStrategy(), cassandraConfig.getStrategyOptions())
  );
  getClusterSession().execute(createApplicationKeyspace);
  waitForSchemaAgreement();
  logger.info("Created keyspace: {}", cassandraConfig.getApplicationKeyspace());
}
origin: apache/usergrid

if(!forceCheck) {
  exists = getClusterSession().getCluster().getMetadata()
    .getKeyspace(CQLUtils.quote(cassandraConfig.getApplicationLocalKeyspace())) != null;
}else{
  exists = getClusterSession()
origin: kaaproject/kaa

 @SuppressWarnings("unchecked")
 private UDTValue convertValue(Object value,
                CassandraEntityMapper<?> mapper,
                CassandraClient cassandraClient) {
  String keyspace = cassandraClient.getSession().getLoggedKeyspace();
  UserType userType = cassandraClient.getSession()
    .getCluster()
    .getMetadata()
    .getKeyspace(keyspace)
    .getUserType(mapper.getName());
  UDTValue udtValue = userType.newValue();
  for (String name : mapper.getNonKeyColumnNames()) {
   Object fieldValue = mapper.getColumnValueForName(name, value, cassandraClient);
   if (fieldValue != null) {
    udtValue.set(name, fieldValue, (Class<Object>) fieldValue.getClass());
   } else {
    udtValue.setToNull(name);
   }
  }
  return udtValue;
 }
}
origin: hugegraph/hugegraph

protected boolean existsKeyspace() {
  return this.cluster().getMetadata().getKeyspace(this.keyspace) != null;
}
origin: com.datastax.cassandra/cassandra-driver-core

 private void assertNotExists(String name) {
  assertNull(cluster().getMetadata().getKeyspace(name));
 }
}
origin: com.datastax.cassandra/cassandra-driver-core

private void assertExists(String fetchName, String realName) {
 KeyspaceMetadata km = cluster().getMetadata().getKeyspace(fetchName);
 assertNotNull(km);
 assertEquals(realName, km.getName());
}
origin: Impetus/Kundera

@Override
public void deleteByColumn(String schemaName, String tableName, String columnName, Object columnValue) {
  Session session = factory.getConnection();
  String rowKeyName = null;
  CQLTranslator translator = new CQLTranslator();
  try {
    List<ColumnMetadata> primaryKeys = session.getCluster().getMetadata().getKeyspace("\"" + schemaName + "\"")
      .getTable("\"" + tableName + "\"").getPrimaryKey();
    rowKeyName = primaryKeys.get(0).getName();
  } finally {
    // factory.releaseConnection(session);
  }
  List rowKeys =
    getColumnsById(schemaName, tableName, columnName, rowKeyName, columnValue, columnValue.getClass());
  for (Object rowKey : rowKeys) {
    if (rowKey != null) {
      String deleteQuery = CQLTranslator.DELETE_QUERY;
      deleteQuery = StringUtils.replace(deleteQuery, CQLTranslator.COLUMN_FAMILY,
        translator.ensureCase(new StringBuilder(), tableName, false).toString());
      StringBuilder deleteQueryBuilder = new StringBuilder(deleteQuery);
      deleteQueryBuilder.append(CQLTranslator.ADD_WHERE_CLAUSE);
      deleteQueryBuilder = translator.ensureCase(deleteQueryBuilder, rowKeyName, false);
      deleteQueryBuilder.append(CQLTranslator.EQ_CLAUSE);
      translator.appendValue(deleteQueryBuilder, rowKey.getClass(), rowKey, false, false);
      this.execute(deleteQueryBuilder.toString(), null);
    }
  }
}
origin: com.datastax.cassandra/cassandra-driver-core

 @Override
 public Boolean call() throws Exception {
  return cluster().getMetadata().getKeyspace(keyspace).getTable("user") != null;
 }
};
origin: com.datastax.cassandra/cassandra-driver-core

 private MaterializedViewMetadata getMaterializedView(String name) {
  return cluster().getMetadata().getKeyspace(keyspace).getMaterializedView(name);
 }
}
origin: com.datastax.cassandra/cassandra-driver-core

private TableMetadata getTable(String name) {
 return cluster().getMetadata().getKeyspace(keyspace).getTable(name);
}
origin: com.datastax.cassandra/cassandra-driver-core

@Test(groups = "short")
public void remainingDeleteTests() throws Exception {
 Statement query;
 TableMetadata table = cluster().getMetadata().getKeyspace(keyspace).getTable(TABLE_TEXT);
 assertNotNull(table);
 String expected = String.format("DELETE k FROM %s.test_text;", keyspace);
 query = delete("k").from(table);
 assertEquals(query.toString(), expected);
 try {
  session().execute(query);
  fail();
 } catch (SyntaxError e) {
  // Missing WHERE clause
 }
}
origin: com.datastax.cassandra/cassandra-driver-core

@Test(groups = "short")
public void should_parse_user_defined_type_when_definition_in_old_user_types() {
 Metadata metadata = cluster().getMetadata();
 KeyspaceMetadata keyspaceMetadata = metadata.getKeyspace(this.keyspace);
 assertThat(parse("\"A\"", cluster(), keyspace, null, keyspaceMetadata.userTypes, false, false))
   .isUserType(keyspace, "A");
}
origin: com.datastax.cassandra/cassandra-driver-core

 /**
  * Ensures that if a table is configured with change data capture enabled that {@link
  * TableOptionsMetadata#isCDC()} returns true for that table.
  *
  * @test_category metadata
  * @jira_ticket JAVA-1287
  * @jira_ticket CASSANDRA-12041
  */
 @Test(groups = "short")
 public void should_parse_cdc_from_table_options() {
  // given
  // create a simple table with cdc as true.
  String cql =
    String.format(
      "CREATE TABLE %s.cdc_table (\n"
        + "    k text,\n"
        + "    c int,\n"
        + "    v timeuuid,\n"
        + "    PRIMARY KEY (k, c)\n"
        + ") WITH cdc=true;",
      keyspace);
  session().execute(cql);

  // when retrieving the table's metadata.
  TableMetadata table = cluster().getMetadata().getKeyspace(keyspace).getTable("cdc_table");
  // then the table's options should have cdc as true.
  assertThat(table.getOptions().isCDC()).isEqualTo(true);
  assertThat(table.asCQLQuery(true)).contains("cdc = true");
 }
}
origin: com.datastax.cassandra/cassandra-driver-core

@Test(groups = "short")
public void should_escape_single_quote_table_comment() {
 // given
 String cql =
   String.format(
     "CREATE TABLE %s.single_quote (\n"
       + "    c1 int PRIMARY KEY\n"
       + ") WITH  comment = 'comment with single quote '' should work'",
     keyspace);
 // when
 session().execute(cql);
 TableMetadata table = cluster().getMetadata().getKeyspace(keyspace).getTable("single_quote");
 // then
 assertThat(table.getOptions().getComment())
   .isEqualTo("comment with single quote ' should work");
 assertThat(table.asCQLQuery()).contains("comment = 'comment with single quote '' should work'");
}
origin: com.datastax.cassandra/cassandra-driver-core

@Test(groups = "short")
public void should_parse_user_defined_type_when_definition_in_current_user_types() {
 Metadata metadata = cluster().getMetadata();
 KeyspaceMetadata keyspaceMetadata = metadata.getKeyspace(this.keyspace);
 assertThat(
     parse(
       "frozen<\"A\">",
       cluster(),
       keyspace,
       keyspaceMetadata.userTypes,
       null,
       false,
       false))
   .isUserType(keyspace, "A");
}
origin: com.datastax.cassandra/cassandra-driver-core

@Test(groups = "short")
public void insertUdtTest() throws Exception {
 UserType udtType = cluster().getMetadata().getKeyspace(keyspace).getUserType("udt");
 UDTValue udtValue =
   udtType.newValue().setInt("i", 2).setInet("a", InetAddress.getByName("localhost"));
 Statement insert = insertInto("udtTest").value("k", 1).value("t", udtValue);
 assertEquals(insert.toString(), "INSERT INTO udtTest (k,t) VALUES (1,{i:2,a:'127.0.0.1'});");
 session().execute(insert);
 List<Row> rows = session().execute(select().from("udtTest").where(eq("k", 1))).all();
 assertEquals(rows.size(), 1);
 Row r1 = rows.get(0);
 assertEquals("127.0.0.1", r1.getUDTValue("t").getInet("a").getHostAddress());
}
origin: com.datastax.cassandra/cassandra-driver-core

@Test(groups = "short")
public void should_handle_UDT_with_many_fields() throws Exception {
 int MAX_TEST_LENGTH = 1024;
 // create the seed udt
 StringBuilder sb = new StringBuilder();
 for (int i = 0; i < MAX_TEST_LENGTH; ++i) {
  sb.append(String.format("v_%s int", i));
  if (i + 1 < MAX_TEST_LENGTH) sb.append(",");
 }
 session().execute(String.format("CREATE TYPE lengthy_udt (%s)", sb.toString()));
 // create a table with multiple sizes of udts
 session().execute("CREATE TABLE lengthy_udt_table (k int PRIMARY KEY, v frozen<lengthy_udt>)");
 // hold onto the UserType for future use
 UserType udtDef = cluster().getMetadata().getKeyspace(keyspace).getUserType("lengthy_udt");
 // verify inserts and reads
 for (int i : Arrays.asList(0, 1, 2, 3, MAX_TEST_LENGTH)) {
  // create udt
  UDTValue createdUDT = udtDef.newValue();
  for (int j = 0; j < i; ++j) {
   createdUDT.setInt(j, j);
  }
  // write udt
  session().execute("INSERT INTO lengthy_udt_table (k, v) VALUES (0, ?)", createdUDT);
  // verify udt was written and read correctly
  UDTValue r =
    session().execute("SELECT v FROM lengthy_udt_table WHERE k=0").one().getUDTValue("v");
  assertThat(r.toString()).isEqualTo(createdUDT.toString());
 }
}
com.datastax.driver.coreClustergetMetadata

Javadoc

Returns read-only metadata on the connected cluster.

This includes the known nodes with their status as seen by the driver, as well as the schema definitions. Since this return metadata on the connected cluster, this method may trigger the creation of a connection if none has been established yet (neither init() nor connect()has been called yet).

Popular methods of Cluster

  • connect
    Creates a new session on this cluster, initialize it and sets the keyspace to the provided one. Note
  • builder
    Creates a new Cluster.Builder instance. This is a convenience method for new Cluster.Builder().
  • close
    Initiates a shutdown of this cluster instance and blocks until that shutdown completes. This method
  • getConfiguration
    The cluster configuration.
  • isClosed
    Whether this Cluster instance has been closed. Note that this method returns true as soon as one of
  • getClusterName
    The name of this cluster object. Note that this is not the Cassandra cluster name, but rather a name
  • closeAsync
    Initiates a shutdown of this cluster instance. This method is asynchronous and return a future on th
  • register
    Registers the provided listener to be updated with schema change events. Registering the same liste
  • newSession
    Creates a new session on this cluster but does not initialize it. Because this method does not perfo
  • getMetrics
    The cluster metrics.
  • init
    Initialize this Cluster instance. This method creates an initial connection to one of the contact po
  • connectAsync
    Creates a new session on this cluster, and initializes it to the given keyspace asynchronously. This
  • init,
  • connectAsync,
  • unregister,
  • <init>,
  • buildFrom,
  • checkNotEmpty,
  • timeSince,
  • checkNotClosed,
  • getDriverVersion

Popular in Java

  • Finding current android device location
  • onRequestPermissionsResult (Fragment)
  • getContentResolver (Context)
  • getSharedPreferences (Context)
  • FileInputStream (java.io)
    An input stream that reads bytes from a file. File file = ...finally if (in != null) in.clos
  • TimeZone (java.util)
    TimeZone represents a time zone offset, and also figures out daylight savings. Typically, you get a
  • TimerTask (java.util)
    The TimerTask class represents a task to run at a specified time. The task may be run once or repeat
  • Collectors (java.util.stream)
  • JComboBox (javax.swing)
  • JTable (javax.swing)
  • Top plugins for WebStorm
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