/** * Build the datatype representation of a frozen UDT, to include in a schema builder statement. * * <p><code>frozen("foo")</code> will produce <code>frozen<foo></code>. * * @param udtName the name of the UDT. * @return the type. */ public static UDTType frozen(String udtName) { return UDTType.frozen(udtName); }
static UDTType list(UDTType elementType) { return new UDTType("list<" + elementType.asCQLString() + ">"); }
/** * Shorthand to add a column definition to this CREATE statement, when the type is a list of UDT. * * @param columnName the name of the column to be added * @param udtType the udt type of the column to be added. Use {@link * SchemaBuilder#frozen(String)}. * @return this CREATE statement. */ public T addUDTListColumn(String columnName, UDTType udtType) { validateNotEmpty(columnName, "Column name"); validateNotNull(udtType, "Column element type"); validateNotKeyWord( columnName, String.format( "The column name '%s' is not allowed because it is a reserved keyword", columnName)); simpleColumns.put(columnName, UDTType.list(udtType)); return self; }
/** * Define the new type of the altered column, when that type contains a UDT. * * @param udtType the UDT type. Use {@link SchemaBuilder#frozen(String)} or {@link * SchemaBuilder#udtLiteral(String)}. * @return the final statement. */ public SchemaStatement udtType(UDTType udtType) { return SchemaStatement.fromQueryString( alter.buildInternal() + " ALTER " + columnName + " TYPE " + udtType.asCQLString()); } }
static UDTType literal(String literal) { SchemaStatement.validateNotEmpty(literal, "UDT type literal"); return new UDTType(literal); } }
/** * Build the datatype representation of a complex UDT type, to include in a schema builder * statement. * * <p>As of Cassandra 2.1, this method is not strictly necessary because {@link Create} and {@link * Alter} provide specialized methods to express simple collections of UDTs, but future versions * will make it possible to use types such as <code> * map<text, map<text, frozen<user>>></code>. * * @param literal the type literal as it will appear in the final CQL statement. * @return the type. */ public static UDTType udtLiteral(String literal) { return UDTType.literal(literal); }
/** * Shorthand to add a column definition to this CREATE statement, when the type is a set of UDT. * * @param columnName the name of the column to be added * @param udtType the udt type of the column to be added. Use {@link * SchemaBuilder#frozen(String)}. * @return this CREATE statement. */ public T addUDTSetColumn(String columnName, UDTType udtType) { validateNotEmpty(columnName, "Column name"); validateNotNull(udtType, "Column element type"); validateNotKeyWord( columnName, String.format( "The column name '%s' is not allowed because it is a reserved keyword", columnName)); simpleColumns.put(columnName, UDTType.set(udtType)); return self; }
/** * Shorthand to add a column definition to this CREATE statement, when the type is a map with UDT * key and value types. * * <p>Example: * * <pre> * addUDTMapColumn("users", frozen("user"), frozen("address")); * </pre> * * @param columnName the name of the column to be added. * @param udtKeyType the key UDT type of the column to be added. Use {@link * SchemaBuilder#frozen(String)}. * @param udtValueType the value UDT type of the column to be added. Use {@link * SchemaBuilder#frozen(String)}. * @return this CREATE statement. */ public T addUDTMapColumn(String columnName, UDTType udtKeyType, UDTType udtValueType) { validateNotEmpty(columnName, "Column name"); validateNotNull(udtKeyType, "Map key UDT type"); validateNotNull(udtValueType, "Map value UDT type"); validateNotKeyWord( columnName, String.format( "The column name '%s' is not allowed because it is a reserved keyword", columnName)); simpleColumns.put(columnName, UDTType.mapWithUDTKeyAndValue(udtKeyType, udtValueType)); return self; }
/** * Shorthand to add a column definition to this CREATE statement, when the type is a map with a * UDT value type. * * <p>Example: * * <pre> * addUDTMapColumn("addresses", DataType.text(), frozen("address")); * </pre> * * @param columnName the name of the column to be added. * @param keyType the key type of the column to be added. * @param valueUdtType the value UDT type of the column to be added. Use {@link * SchemaBuilder#frozen(String)}. * @return this CREATE statement. */ public T addUDTMapColumn(String columnName, DataType keyType, UDTType valueUdtType) { validateNotEmpty(columnName, "Column name"); validateNotNull(keyType, "Map key type"); validateNotNull(valueUdtType, "Map value UDT type"); validateNotKeyWord( columnName, String.format( "The column name '%s' is not allowed because it is a reserved keyword", columnName)); simpleColumns.put(columnName, UDTType.mapWithUDTValue(keyType, valueUdtType)); return self; }
/** * Shorthand to add a column definition to this CREATE statement, when the type is a map with a * UDT key type. * * <p>Example: * * <pre> * addUDTMapColumn("roles", frozen("user"), DataType.text()); * </pre> * * @param columnName the name of the column to be added. * @param udtKeyType the key UDT type of the column to be added. Use {@link * SchemaBuilder#frozen(String)}. * @param valueType the value raw type of the column to be added. * @return this CREATE statement. */ public T addUDTMapColumn(String columnName, UDTType udtKeyType, DataType valueType) { validateNotEmpty(columnName, "Column name"); validateNotNull(udtKeyType, "Map key UDT type"); validateNotNull(valueType, "Map value type"); validateNotKeyWord( columnName, String.format( "The column name '%s' is not allowed because it is a reserved keyword", columnName)); simpleColumns.put(columnName, UDTType.mapWithUDTKey(udtKeyType, valueType)); return self; }
/** * Define the type of the added column, when that type contains a UDT. * * @param udtType the UDT type of the added column. * @return the final statement. */ public SchemaStatement udtType(UDTType udtType) { return SchemaStatement.fromQueryString( alter.buildInternal() + " ADD " + columnName + " " + udtType.asCQLString() + (staticColumn ? " static" : "")); } }
static UDTType frozen(String udtName) { SchemaStatement.validateNotEmpty(udtName, "UDT name"); return new UDTType("frozen<" + udtName + ">"); }
/** * Build the datatype representation of a complex UDT type, to include in a schema builder statement. * <p/> * As of Cassandra 2.1, this method is not strictly necessary because {@link Create} and {@link Alter} * provide specialized methods to express simple collections of UDTs, but future versions will make it * possible to use types such as <code>map<text, map<text, frozen<user>>></code>. * * @param literal the type literal as it will appear in the final CQL statement. * @return the type. */ public static UDTType udtLiteral(String literal) { return UDTType.literal(literal); }
/** * Shorthand to add a column definition to this CREATE statement, when the type is a set of UDT. * * @param columnName the name of the column to be added * @param udtType the udt type of the column to be added. Use {@link SchemaBuilder#frozen(String)}. * @return this CREATE statement. */ public T addUDTSetColumn(String columnName, UDTType udtType) { validateNotEmpty(columnName, "Column name"); validateNotNull(udtType, "Column element type"); validateNotKeyWord(columnName, String.format("The column name '%s' is not allowed because it is a reserved keyword", columnName)); simpleColumns.put(columnName, UDTType.set(udtType)); return self; }
/** * Shorthand to add a column definition to this CREATE statement, when the type is a map with UDT key and value types. * <p/> * Example: * <pre> * addUDTMapColumn("users", frozen("user"), frozen("address")); * </pre> * * @param columnName the name of the column to be added. * @param udtKeyType the key UDT type of the column to be added. Use {@link SchemaBuilder#frozen(String)}. * @param udtValueType the value UDT type of the column to be added. Use {@link SchemaBuilder#frozen(String)}. * @return this CREATE statement. */ public T addUDTMapColumn(String columnName, UDTType udtKeyType, UDTType udtValueType) { validateNotEmpty(columnName, "Column name"); validateNotNull(udtKeyType, "Map key UDT type"); validateNotNull(udtValueType, "Map value UDT type"); validateNotKeyWord(columnName, String.format("The column name '%s' is not allowed because it is a reserved keyword", columnName)); simpleColumns.put(columnName, UDTType.mapWithUDTKeyAndValue(udtKeyType, udtValueType)); return self; }
/** * Shorthand to add a column definition to this CREATE statement, when the type is a map with a UDT value type. * <p/> * Example: * <pre> * addUDTMapColumn("addresses", DataType.text(), frozen("address")); * </pre> * * @param columnName the name of the column to be added. * @param keyType the key type of the column to be added. * @param valueUdtType the value UDT type of the column to be added. Use {@link SchemaBuilder#frozen(String)}. * @return this CREATE statement. */ public T addUDTMapColumn(String columnName, DataType keyType, UDTType valueUdtType) { validateNotEmpty(columnName, "Column name"); validateNotNull(keyType, "Map key type"); validateNotNull(valueUdtType, "Map value UDT type"); validateNotKeyWord(columnName, String.format("The column name '%s' is not allowed because it is a reserved keyword", columnName)); simpleColumns.put(columnName, UDTType.mapWithUDTValue(keyType, valueUdtType)); return self; }
/** * Shorthand to add a column definition to this CREATE statement, when the type is a map with a UDT key type. * <p/> * Example: * <pre> * addUDTMapColumn("roles", frozen("user"), DataType.text()); * </pre> * * @param columnName the name of the column to be added. * @param udtKeyType the key UDT type of the column to be added. Use {@link SchemaBuilder#frozen(String)}. * @param valueType the value raw type of the column to be added. * @return this CREATE statement. */ public T addUDTMapColumn(String columnName, UDTType udtKeyType, DataType valueType) { validateNotEmpty(columnName, "Column name"); validateNotNull(udtKeyType, "Map key UDT type"); validateNotNull(valueType, "Map value type"); validateNotKeyWord(columnName, String.format("The column name '%s' is not allowed because it is a reserved keyword", columnName)); simpleColumns.put(columnName, UDTType.mapWithUDTKey(udtKeyType, valueType)); return self; }
static UDTType mapWithUDTKey(UDTType keyType, DataType valueType) { return new UDTType("map<" + keyType.asCQLString() + ", " + valueType + ">"); }
/** * Define the new type of the altered column, when that type contains a UDT. * * @param udtType the UDT type. Use {@link SchemaBuilder#frozen(String)} or {@link SchemaBuilder#udtLiteral(String)}. * @return the final statement. */ public SchemaStatement udtType(UDTType udtType) { return SchemaStatement.fromQueryString( alter.buildInternal() + " ALTER " + columnName + " TYPE " + udtType.asCQLString()); } }
static UDTType literal(String literal) { SchemaStatement.validateNotEmpty(literal, "UDT type literal"); return new UDTType(literal); } }