Package com.datastax.oss.driver.api.core
Class CqlIdentifier
- java.lang.Object
-
- com.datastax.oss.driver.api.core.CqlIdentifier
-
- All Implemented Interfaces:
Serializable
@Immutable public class CqlIdentifier extends Object implements Serializable
The identifier of CQL element (keyspace, table, column, etc).It has two representations:
- the "CQL" form, which is how you would type the identifier in a CQL query. It is
case-insensitive unless enclosed in double quotation marks; in addition, identifiers that
contain special characters (anything other than alphanumeric and underscore), or match CQL
keywords, must be double-quoted (with inner double quotes escaped as
""). - the "internal" form, which is how the name is stored in Cassandra system tables. It is lower-case for case-sensitive identifiers, and in the exact case for case-sensitive identifiers.
This class provides a common representation and avoids any ambiguity about which form the identifier is in. Driver clients will generally want to create instances from the CQL form withExamples Create statement Case-sensitive? CQL id Internal id CREATE TABLE t(foo int PRIMARY KEY) No foo foo CREATE TABLE t(Foo int PRIMARY KEY) No foo foo CREATE TABLE t("Foo" int PRIMARY KEY) Yes "Foo" Foo CREATE TABLE t("foo bar" int PRIMARY KEY) Yes "foo bar" foo bar CREATE TABLE t("foo""bar" int PRIMARY KEY) Yes "foo""bar" foo"bar CREATE TABLE t("create" int PRIMARY KEY) Yes (reserved keyword) "create" create fromCql(String).There is no internal caching; if you reuse the same identifiers often, consider caching them in your application.
- See Also:
- Serialized Form
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description StringasCql(boolean pretty)Returns the identifier in a format appropriate for concatenation in a CQL query.StringasInternal()Returns the identifier in the "internal" format.booleanequals(Object other)static CqlIdentifierfromCql(String cql)Creates an identifier from itsCQL form.static CqlIdentifierfromInternal(String internal)Creates an identifier from itsinternal form.inthashCode()StringtoString()
-
-
-
Method Detail
-
fromCql
@NonNull public static CqlIdentifier fromCql(@NonNull String cql)
Creates an identifier from itsCQL form.
-
fromInternal
@NonNull public static CqlIdentifier fromInternal(@NonNull String internal)
Creates an identifier from itsinternal form.
-
asInternal
@NonNull public String asInternal()
Returns the identifier in the "internal" format.- Returns:
- the identifier in its exact case, unquoted.
-
asCql
@NonNull public String asCql(boolean pretty)
Returns the identifier in a format appropriate for concatenation in a CQL query.- Parameters:
pretty- iftrue, use the shortest possible representation: if the identifier is case-insensitive, an unquoted, lower-case string, otherwise the double-quoted form. Iffalse, always use the double-quoted form (this is slightly more efficient since we don't need to inspect the string).
-
-