本文整理了Java中com.datastax.driver.core.Metadata.quote()
方法的一些代码示例,展示了Metadata.quote()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Metadata.quote()
方法的具体详情如下:
包路径:com.datastax.driver.core.Metadata
类名称:Metadata
方法名:quote
[英]Quote a keyspace, table or column identifier to make it case sensitive.
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 CQL documentation 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.
Note that reserved CQL keywords should also be quoted. You can check if a given identifier is a reserved keyword by calling #isReservedCqlKeyword(String).
[中]引用键空间、表或列标识符以区分大小写。
默认情况下,CQL标识符(包括键空间、表和列标识符)不区分大小写。但是,可以通过将标识符括在双引号中来提供区分大小写的标识符(有关详细信息,请参见CQL documentation)。如果使用区分大小写的标识符,可以使用此方法将此类标识符括在双引号中,使其区分大小写。
注意reserved CQL keywords也应该被引用。您可以通过调用#isReservedCqlKeyword(字符串)来检查给定标识符是否为保留关键字。
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
/**
* Quotes a column name to make it case sensitive.
*
* @param columnName the column name to quote.
* @return the quoted column name.
* @see Metadata#quote(String)
*/
public static String quote(String columnName) {
return Metadata.quote(columnName);
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
/**
* Quotes a CQL identifier if necessary.
*
* <p>This is similar to {@link #quote(String)}, except that it won't quote the input string if it
* can safely be used as-is. For example:
*
* <ul>
* <li>{@code quoteIfNecessary("foo").equals("foo")} (no need to quote).
* <li>{@code quoteIfNecessary("Foo").equals("\"Foo\"")} (identifier is mixed case so case
* sensitivity is required)
* <li>{@code quoteIfNecessary("foo bar").equals("\"foo bar\"")} (identifier contains special
* characters)
* <li>{@code quoteIfNecessary("table").equals("\"table\"")} (identifier is a reserved CQL
* keyword)
* </ul>
*
* @param id the "internal" form of the identifier. That is, the identifier as it would appear in
* Cassandra system tables (such as {@code system_schema.tables}, {@code
* system_schema.columns}, etc.)
* @return the identifier as it would appear in a CQL query string. This is also how you need to
* pass it to public driver methods, such as {@link #getKeyspace(String)}.
*/
public static String quoteIfNecessary(String id) {
return needsQuote(id) ? quote(id) : id;
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
public TableMetadataAssert hasMaterializedView(MaterializedViewMetadata expected) {
assertThat(actual.getView(Metadata.quote(expected.getName()))).isNotNull().isEqualTo(expected);
return this;
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
private static int[] computePkIndices(Metadata clusterMetadata, ColumnDefinitions boundColumns) {
List<ColumnMetadata> partitionKeyColumns = null;
int[] pkIndexes = null;
KeyspaceMetadata km = clusterMetadata.getKeyspace(Metadata.quote(boundColumns.getKeyspace(0)));
if (km != null) {
TableMetadata tm = km.getTable(Metadata.quote(boundColumns.getTable(0)));
if (tm != null) {
partitionKeyColumns = tm.getPartitionKey();
pkIndexes = new int[partitionKeyColumns.size()];
for (int i = 0; i < pkIndexes.length; ++i) pkIndexes[i] = -1;
}
}
// Note: we rely on the fact CQL queries cannot span multiple tables. If that change, we'll have
// to get smarter.
for (int i = 0; i < boundColumns.size(); i++)
maybeGetIndex(boundColumns.getName(i), i, partitionKeyColumns, pkIndexes);
return allSet(pkIndexes) ? pkIndexes : null;
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
return childPolicy.newQueryPlan(keyspace, statement);
final Set<Host> replicas = clusterMetadata.getReplicas(Metadata.quote(keyspace), partitionKey);
if (replicas.isEmpty()) return childPolicy.newQueryPlan(loggedKeyspace, statement);
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
/**
* @test_category queries:builder
* @jira_ticket JAVA-1286
* @jira_ticket CASSANDRA-7423
*/
@Test(groups = "unit")
public void should_handle_retrieving_udt_fields() throws Exception {
assertThat(select().path("a", Metadata.quote("B")).raw("c.\"D\"").from("tbl").getQueryString())
.isEqualTo("SELECT a.\"B\",c.\"D\" FROM tbl;");
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
@BeforeMethod(groups = "unit")
public void initMocks() {
CodecRegistry codecRegistry = new CodecRegistry();
cluster = mock(Cluster.class);
Configuration configuration = mock(Configuration.class);
ProtocolOptions protocolOptions = mock(ProtocolOptions.class);
Metadata metadata = mock(Metadata.class);
childPolicy = mock(LoadBalancingPolicy.class);
when(cluster.getConfiguration()).thenReturn(configuration);
when(configuration.getCodecRegistry()).thenReturn(codecRegistry);
when(configuration.getProtocolOptions()).thenReturn(protocolOptions);
when(protocolOptions.getProtocolVersion()).thenReturn(ProtocolVersion.NEWEST_SUPPORTED);
when(cluster.getMetadata()).thenReturn(metadata);
when(metadata.getReplicas(Metadata.quote("keyspace"), routingKey))
.thenReturn(Sets.newLinkedHashSet(host1, host2));
when(childPolicy.newQueryPlan("keyspace", statement))
.thenReturn(Sets.newLinkedHashSet(host4, host3, host2, host1).iterator());
when(childPolicy.distance(any(Host.class))).thenReturn(HostDistance.LOCAL);
when(host1.isUp()).thenReturn(true);
when(host2.isUp()).thenReturn(true);
when(host3.isUp()).thenReturn(true);
when(host4.isUp()).thenReturn(true);
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
@Test(groups = "short")
public void testCaseSensitiveKeyspace() throws Throwable {
String ksName = "\"MyKeyspace2\"";
session().execute(String.format(CREATE_KEYSPACE_SIMPLE_FORMAT, ksName, 1));
assertExists(ksName, "MyKeyspace2");
assertExists(Metadata.quote("MyKeyspace2"), "MyKeyspace2");
assertNotExists("mykeyspace2");
assertNotExists("MyKeyspace2");
assertNotExists("MYKEYSPACE2");
}
代码示例来源:origin: com.facebook.presto.cassandra/cassandra-driver
/**
* Quotes a columnName to make it case sensitive.
*
* @param columnName the column name to quote.
* @return the quoted column name.
* @see Metadata#quote(String)
*/
public static String quote(String columnName) {
return Metadata.quote(columnName);
}
代码示例来源:origin: com.yugabyte/cassandra-driver-core
/**
* Quotes a columnName to make it case sensitive.
*
* @param columnName the column name to quote.
* @return the quoted column name.
* @see Metadata#quote(String)
*/
public static String quote(String columnName) {
return Metadata.quote(columnName);
}
代码示例来源:origin: io.prestosql.cassandra/cassandra-driver
protected static String escapeId(String ident) {
// we don't need to escape if it's lowercase and match non-quoted CQL3 ids.
return lowercaseAlphanumeric.matcher(ident).matches() ? ident : Metadata.quote(ident);
}
代码示例来源:origin: com.stratio.cassandra/cassandra-driver-core
static String escapeId(String ident) {
// we don't need to escape if it's lowercase and match non-quoted CQL3 ids.
return lowercaseId.matcher(ident).matches() ? ident : quote(ident);
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
@Test(groups = "short")
public void should_store_and_retrieve_with_simple_statements() throws Exception {
int userId = 1;
UserType addrDef =
cluster().getMetadata().getKeyspace(keyspace).getUserType(quote("\"User Address\""));
UserType phoneDef = cluster().getMetadata().getKeyspace(keyspace).getUserType("phone");
UDTValue phone1 =
phoneDef.newValue().setString("alias", "home").setString("number", "0123548790");
UDTValue phone2 =
phoneDef.newValue().setString("alias", "work").setString("number", "0698265251");
UDTValue addr =
addrDef
.newValue()
.setString("street", "1600 Pennsylvania Ave NW")
.setInt(quote("ZIP\""), 20500)
.setSet("phones", ImmutableSet.of(phone1, phone2));
session().execute("INSERT INTO user(id, addr) VALUES (?, ?)", userId, addr);
Row r = session().execute("SELECT * FROM user WHERE id=?", userId).one();
assertThat(r.getInt("id")).isEqualTo(userId);
assertThat(r.getUDTValue("addr")).isEqualTo(addr);
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
throws Exception {
String c1 = Metadata.quote("quotes go \"\" here \"\" ");
String c2 = Metadata.quote("\\x00\\x25");
String c3 = Metadata.quote("columnfamily");
String c4 = Metadata.quote("select");
String c5 = Metadata.quote("who''s there'? ");
String c6 = Metadata.quote("faux )");
String c7 = Metadata.quote("COMPACT STORAGE");
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
@Test(groups = "short")
public void should_store_and_retrieve_with_prepared_statements() throws Exception {
int userId = 0;
PreparedStatement ins = session().prepare("INSERT INTO user(id, addr) VALUES (?, ?)");
PreparedStatement sel = session().prepare("SELECT * FROM user WHERE id=?");
UserType addrDef =
cluster().getMetadata().getKeyspace(keyspace).getUserType(quote("\"User Address\""));
UserType phoneDef = cluster().getMetadata().getKeyspace(keyspace).getUserType("phone");
UDTValue phone1 =
phoneDef.newValue().setString("alias", "home").setString("number", "0123548790");
UDTValue phone2 =
phoneDef.newValue().setString("alias", "work").setString("number", "0698265251");
UDTValue addr =
addrDef
.newValue()
.setString("street", "1600 Pennsylvania Ave NW")
.setInt(quote("ZIP\""), 20500)
.setSet("phones", ImmutableSet.of(phone1, phone2));
session().execute(ins.bind(userId, addr));
Row r = session().execute(sel.bind(userId)).one();
assertThat(r.getInt("id")).isEqualTo(0);
}
代码示例来源:origin: com.facebook.presto.cassandra/cassandra-driver
static String escapeId(String ident) {
// we don't need to escape if it's lowercase and match non-quoted CQL3 ids,
// and if it's not a CQL reserved keyword
return lowercaseAlphanumeric.matcher(ident).matches()
&& !isReservedCqlKeyword(ident) ?
ident : quote(ident);
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
@Test(groups = "short")
public void should_store_type_definitions_in_their_keyspace() throws Exception {
KeyspaceMetadata thisKeyspace = cluster().getMetadata().getKeyspace(this.keyspace);
// Types that don't exist don't have definitions
assertThat(thisKeyspace.getUserType("address1")).isNull();
assertThat(thisKeyspace.getUserType("phone1")).isNull();
// Types created by this test have definitions
assertThat(thisKeyspace.getUserType(quote("\"User Address\""))).isNotNull();
assertThat(thisKeyspace.getUserType("phone")).isNotNull();
// If we create another keyspace, it doesn't have the definitions of this keyspace
String otherKeyspaceName = this.keyspace + "_nonEx";
session()
.execute(
"CREATE KEYSPACE "
+ otherKeyspaceName
+ " "
+ "WITH replication = { 'class' : 'SimpleStrategy', 'replication_factor': '1'}");
KeyspaceMetadata otherKeyspace = cluster().getMetadata().getKeyspace(otherKeyspaceName);
assertThat(otherKeyspace.getUserType(quote("\"User Address\""))).isNull();
assertThat(otherKeyspace.getUserType("phone")).isNull();
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
@Test(groups = "short")
public void should_parse_nested_collection_types() {
Metadata metadata = cluster().getMetadata();
KeyspaceMetadata keyspaceMetadata = metadata.getKeyspace(this.keyspace);
assertThat(parse("list<list<int>>", cluster(), null, null, null, false, false))
.isEqualTo(list(list(cint())));
assertThat(
parse(
"set<list<frozen<map<bigint,varchar>>>>",
cluster(),
null,
null,
null,
false,
false))
.isEqualTo(set(list(map(bigint(), varchar(), true))));
UserType keyType = keyspaceMetadata.getUserType(quote("Incr,edibly\" EvilTy<>><<><p\"e"));
UserType valueType = keyspaceMetadata.getUserType(quote("A"));
assertThat(
parse(
"map<frozen<\"Incr,edibly\"\" EvilTy<>><<><p\"\"e\">,frozen<\"A\">>",
cluster(),
keyspace,
keyspaceMetadata.userTypes,
null,
false,
false))
.isEqualTo(map(keyType, valueType, false));
}
代码示例来源:origin: com.datastax.dse/dse-java-driver-core
/**
* @test_category queries:builder
* @jira_ticket JAVA-1286
* @jira_ticket CASSANDRA-7423
*/
@Test(groups = "unit")
public void should_handle_retrieving_udt_fields() throws Exception {
assertThat(select().path("a", Metadata.quote("B")).raw("c.\"D\"").from("tbl").getQueryString())
.isEqualTo("SELECT a.\"B\",c.\"D\" FROM tbl;");
}
代码示例来源:origin: com.datastax.dse/dse-java-driver-core
@Test(groups = "short")
public void testCaseSensitiveKeyspace() throws Throwable {
String ksName = "\"MyKeyspace2\"";
session().execute(String.format(CREATE_KEYSPACE_SIMPLE_FORMAT, ksName, 1));
assertExists(ksName, "MyKeyspace2");
assertExists(Metadata.quote("MyKeyspace2"), "MyKeyspace2");
assertNotExists("mykeyspace2");
assertNotExists("MyKeyspace2");
assertNotExists("MYKEYSPACE2");
}
内容来源于网络,如有侵权,请联系作者删除!