@Override public String toString() { return Metadata.quoteIfNecessary(name) + ' ' + type; } }
@Override public String toString() { String str = Metadata.quoteIfNecessary(name) + ' ' + type; return isStatic ? str + " static" : str; }
/** * @deprecated preserved for backward compatibility, use {@link Metadata#quoteIfNecessary(String)} * instead. */ @Deprecated protected static String escapeId(String ident) { return Metadata.quoteIfNecessary(ident); }
private StringBuilder appendClusteringOrder(StringBuilder sb) { sb.append("CLUSTERING ORDER BY ("); for (int i = 0; i < clusteringColumns.size(); i++) { if (i > 0) sb.append(", "); sb.append(Metadata.quoteIfNecessary(clusteringColumns.get(i).getName())) .append(' ') .append(clusteringOrder.get(i)); } return sb.append(')'); }
private void appendSignature(StringBuilder sb) { sb.append(Metadata.quoteIfNecessary(simpleName)).append('('); boolean first = true; for (DataType type : argumentTypes) { if (first) first = false; else sb.append(','); sb.append(type.asFunctionParameterString()); } sb.append(')'); }
@Override public String asFunctionParameterString() { return Metadata.quoteIfNecessary(getTypeName()); }
@Override public String format(T value) { if (value == null) return "NULL"; StringBuilder sb = new StringBuilder("{"); int i = 0; for (UserType.Field field : definition) { if (i > 0) sb.append(","); sb.append(Metadata.quoteIfNecessary(field.getName())); sb.append(":"); sb.append(formatField(value, Metadata.quoteIfNecessary(field.getName()))); i += 1; } sb.append("}"); return sb.toString(); }
@Override public String toString() { String str = Metadata.quoteIfNecessary(getKeyspace()) + "." + Metadata.quoteIfNecessary(getTypeName()); return isFrozen() ? "frozen<" + str + ">" : str; }
private String asCQLQuery(boolean formatted) { StringBuilder sb = new StringBuilder(); sb.append("CREATE TYPE ") .append(Metadata.quoteIfNecessary(keyspace)) .append('.') .append(Metadata.quoteIfNecessary(typeName)) .append(" ("); if (formatted) { TableMetadata.spaceOrNewLine(sb, true); } for (int i = 0; i < byIdx.length; i++) { sb.append(byIdx[i]); if (i < byIdx.length - 1) { sb.append(','); TableMetadata.spaceOrNewLine(sb, formatted); } else { TableMetadata.newLine(sb, formatted); } } return sb.append(");").toString(); }
private static String targetFromLegacyOptions( ColumnMetadata column, Map<String, String> options) { String columnName = Metadata.quoteIfNecessary(column.getName()); if (options.containsKey(INDEX_KEYS_OPTION_NAME)) return String.format("keys(%s)", columnName); if (options.containsKey(INDEX_ENTRIES_OPTION_NAME)) return String.format("entries(%s)", columnName); if (column.getType() instanceof DataType.CollectionType && column.getType().isFrozen()) return String.format("full(%s)", columnName); // Note: the keyword 'values' is not accepted as a valid index target function until 3.0 return columnName; }
Delete(TableMetadata table, List<Selector> columns) { this( Metadata.quoteIfNecessary(table.getKeyspace().getName()), Metadata.quoteIfNecessary(table.getName()), Arrays.asList(new Object[table.getPartitionKey().size()]), table.getPartitionKey(), columns); }
Update(TableMetadata table) { this( Metadata.quoteIfNecessary(table.getKeyspace().getName()), Metadata.quoteIfNecessary(table.getName()), Arrays.asList(new Object[table.getPartitionKey().size()]), table.getPartitionKey()); }
Truncate(TableMetadata table) { this( Metadata.quoteIfNecessary(table.getKeyspace().getName()), Metadata.quoteIfNecessary(table.getName()), Arrays.asList(new Object[table.getPartitionKey().size()]), table.getPartitionKey()); }
Insert(TableMetadata table) { this( Metadata.quoteIfNecessary(table.getKeyspace().getName()), Metadata.quoteIfNecessary(table.getName()), Arrays.asList(new Object[table.getPartitionKey().size()]), table.getPartitionKey()); }
Select(TableMetadata table, List<Object> columnNames, boolean isDistinct, boolean isJson) { this( Metadata.quoteIfNecessary(table.getKeyspace().getName()), Metadata.quoteIfNecessary(table.getName()), Arrays.asList(new Object[table.getPartitionKey().size()]), table.getPartitionKey(), columnNames, isDistinct, isJson); }
/** * Returns a CQL query representing this index. * * <p>This method returns a single 'CREATE INDEX' query corresponding to this index definition. * * @return the 'CREATE INDEX' query corresponding to this index. */ public String asCQLQuery() { String keyspaceName = Metadata.quoteIfNecessary(table.getKeyspace().getName()); String tableName = Metadata.quoteIfNecessary(table.getName()); String indexName = Metadata.quoteIfNecessary(this.name); return isCustomIndex() ? String.format( "CREATE CUSTOM INDEX %s ON %s.%s (%s) USING '%s' %s;", indexName, keyspaceName, tableName, getTarget(), getIndexClassName(), getOptionsAsCql()) : String.format( "CREATE INDEX %s ON %s.%s (%s);", indexName, keyspaceName, tableName, getTarget()); }
@Test(groups = "unit") public void escapeId_should_not_quote_lowercase_identifiers() { String id = "this_does_not_need_quoting_0123456789abcdefghijklmnopqrstuvwxyz"; assertThat(Metadata.quoteIfNecessary(id)).isEqualTo(id); }
@Test(groups = "unit") public void escapeId_should_quote_non_lowercase_identifiers() { assertThat(Metadata.quoteIfNecessary("This_Needs_Quoting_1234")) .isEqualTo("\"This_Needs_Quoting_1234\""); assertThat(Metadata.quoteIfNecessary("This Needs Quoting 1234!!")) .isEqualTo("\"This Needs Quoting 1234!!\""); }
@Test(groups = "unit") public void escapeId_should_quote_reserved_cql_keywords() { assertThat(Metadata.quoteIfNecessary("columnfamily")).isEqualTo("\"columnfamily\""); }
@Override public T deserialize(ByteBuffer bytes, ProtocolVersion protocolVersion) { if (bytes == null) return null; // empty byte buffers will result in empty values try { ByteBuffer input = bytes.duplicate(); T value = newInstance(); for (UserType.Field field : definition) { if (!input.hasRemaining()) break; int n = input.getInt(); ByteBuffer element = n < 0 ? null : CodecUtils.readBytes(input, n); value = deserializeAndSetField( element, value, Metadata.quoteIfNecessary(field.getName()), protocolVersion); } return value; } catch (BufferUnderflowException e) { throw new InvalidTypeException("Not enough bytes to deserialize a UDT", e); } }