/** * Quote a keyspace, table or column identifier to make it case sensitive. * * <p>CQL identifiers, including keyspace, table and column ones, are case insensitive by default. * Case sensitive identifiers can however be provided by enclosing the identifier in double quotes * (see the <a href="http://cassandra.apache.org/doc/cql3/CQL.html#identifiers">CQL * documentation</a> for details). If you are using case sensitive identifiers, this method can be * used to enclose such identifiers in double quotes, making them case sensitive. * * <p>Note that <a * href="https://docs.datastax.com/en/cql/3.0/cql/cql_reference/keywords_r.html">reserved CQL * keywords</a> should also be quoted. You can check if a given identifier is a reserved keyword * by calling {@link #isReservedCqlKeyword(String)}. * * @param id the keyspace or table identifier. * @return {@code id} enclosed in double-quotes, for use in methods like {@link #getReplicas}, * {@link #getKeyspace}, {@link KeyspaceMetadata#getTable} or even {@link * Cluster#connect(String)}. */ public static String quote(String id) { return ParseUtils.doubleQuote(id); }
@Test(groups = "unit") public void testDoubleQuote() { assertThat(ParseUtils.doubleQuote(null)).isEqualTo("\"\""); assertThat(ParseUtils.doubleQuote("")).isEqualTo("\"\""); assertThat(ParseUtils.doubleQuote(" ")).isEqualTo("\" \""); assertThat(ParseUtils.doubleQuote("foo")).isEqualTo("\"foo\""); assertThat(ParseUtils.doubleQuote(" \"foo\" ")).isEqualTo("\" \"\"foo\"\" \""); }
/** * Quote a keyspace, table or column identifier to make it case sensitive. * <p/> * CQL identifiers, including keyspace, table and column ones, are case insensitive * by default. Case sensitive identifiers can however be provided by enclosing * the identifier in double quotes (see the * <a href="http://cassandra.apache.org/doc/cql3/CQL.html#identifiers">CQL documentation</a> * for details). If you are using case sensitive identifiers, this method * can be used to enclose such identifiers in double quotes, making them case * sensitive. * <p/> * Note that * <a href="https://docs.datastax.com/en/cql/3.0/cql/cql_reference/keywords_r.html">reserved CQL keywords</a> * should also be quoted. You can check if a given identifier is a reserved keyword * by calling {@link #isReservedCqlKeyword(String)}. * * @param id the keyspace or table identifier. * @return {@code id} enclosed in double-quotes, for use in methods like * {@link #getReplicas}, {@link #getKeyspace}, {@link KeyspaceMetadata#getTable} * or even {@link Cluster#connect(String)}. */ public static String quote(String id) { return ParseUtils.doubleQuote(id); }
/** * Quote a keyspace, table or column identifier to make it case sensitive. * <p/> * CQL identifiers, including keyspace, table and column ones, are case insensitive * by default. Case sensitive identifiers can however be provided by enclosing * the identifier in double quotes (see the * <a href="http://cassandra.apache.org/doc/cql3/CQL.html#identifiers">CQL documentation</a> * for details). If you are using case sensitive identifiers, this method * can be used to enclose such identifiers in double quotes, making them case * sensitive. * <p/> * Note that * <a href="https://docs.datastax.com/en/cql/3.0/cql/cql_reference/keywords_r.html">reserved CQL keywords</a> * should also be quoted. You can check if a given identifier is a reserved keyword * by calling {@link #isReservedCqlKeyword(String)}. * * @param id the keyspace or table identifier. * @return {@code id} enclosed in double-quotes, for use in methods like * {@link #getReplicas}, {@link #getKeyspace}, {@link KeyspaceMetadata#getTable} * or even {@link Cluster#connect(String)}. */ public static String quote(String id) { return ParseUtils.doubleQuote(id); }
/** * Quote a keyspace, table or column identifier to make it case sensitive. * <p/> * CQL identifiers, including keyspace, table and column ones, are case insensitive * by default. Case sensitive identifiers can however be provided by enclosing * the identifier in double quotes (see the * <a href="http://cassandra.apache.org/doc/cql3/CQL.html#identifiers">CQL documentation</a> * for details). If you are using case sensitive identifiers, this method * can be used to enclose such identifiers in double quotes, making them case * sensitive. * <p/> * Note that * <a href="https://docs.datastax.com/en/cql/3.0/cql/cql_reference/keywords_r.html">reserved CQL keywords</a> * should also be quoted. You can check if a given identifier is a reserved keyword * by calling {@link #isReservedCqlKeyword(String)}. * * @param id the keyspace or table identifier. * @return {@code id} enclosed in double-quotes, for use in methods like * {@link #getReplicas}, {@link #getKeyspace}, {@link KeyspaceMetadata#getTable} * or even {@link Cluster#connect(String)}. */ public static String quote(String id) { return ParseUtils.doubleQuote(id); }
@Test(groups = "unit") public void testDoubleQuote() { assertThat(ParseUtils.doubleQuote(null)).isEqualTo("\"\""); assertThat(ParseUtils.doubleQuote("")).isEqualTo("\"\""); assertThat(ParseUtils.doubleQuote(" ")).isEqualTo("\" \""); assertThat(ParseUtils.doubleQuote("foo")).isEqualTo("\"foo\""); assertThat(ParseUtils.doubleQuote(" \"foo\" ")).isEqualTo("\" \"\"foo\"\" \""); }