Java Code Examples for org.apache.cassandra.config.CFMetaData#getValueValidator()

The following examples show how to use org.apache.cassandra.config.CFMetaData#getValueValidator() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractCell.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
public void validateFields(CFMetaData metadata) throws MarshalException
{
    validateName(metadata);

    AbstractType<?> valueValidator = metadata.getValueValidator(name());
    if (valueValidator != null)
        valueValidator.validateCellValue(value());
}
 
Example 2
Source File: SSTableExport.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
/**
 * Serialize a given cell to a List of Objects that jsonMapper knows how to turn into strings.  Format is
 *
 * human_readable_name, value, timestamp, [flag, [options]]
 *
 * Value is normally the human readable value as rendered by the validator, but for deleted cells we
 * give the local deletion time instead.
 *
 * Flag may be exactly one of {d,e,c} for deleted, expiring, or counter:
 *  - No options for deleted cells
 *  - If expiring, options will include the TTL and local deletion time.
 *  - If counter, options will include timestamp of last delete
 *
 * @param cell     cell presentation
 * @param cfMetaData Column Family metadata (to get validator)
 * @return cell as serialized list
 */
private static List<Object> serializeColumn(Cell cell, CFMetaData cfMetaData)
{
    CellNameType comparator = cfMetaData.comparator;
    ArrayList<Object> serializedColumn = new ArrayList<Object>();

    serializedColumn.add(comparator.getString(cell.name()));

    if (cell instanceof DeletedCell)
    {
        serializedColumn.add(cell.getLocalDeletionTime());
    }
    else
    {
        AbstractType<?> validator = cfMetaData.getValueValidator(cell.name());
        serializedColumn.add(validator.getString(cell.value()));
    }

    serializedColumn.add(cell.timestamp());

    if (cell instanceof DeletedCell)
    {
        serializedColumn.add("d");
    }
    else if (cell instanceof ExpiringCell)
    {
        serializedColumn.add("e");
        serializedColumn.add(((ExpiringCell) cell).getTimeToLive());
        serializedColumn.add(cell.getLocalDeletionTime());
    }
    else if (cell instanceof CounterCell)
    {
        serializedColumn.add("c");
        serializedColumn.add(((CounterCell) cell).timestampOfLastDelete());
    }

    return serializedColumn;
}