usergrid/usergrid — pull request #20 by snoopdave (2014-01-09 21:45:59+00:00)
Title: Unique properties

This pull request implements unique value verification for the new "Core Persistence" module.

**Unique Values verification**

Implemented in the Collection Module, in the mvcc.stage.write package

**How we do it.**

At the write-unique-verify stage we look at the entity to be stored. We loop through each field and if the field is marked as a unique field and we attempt to write row and a column in the Unique Values Column Family (CF).

```
Unique Values CF

Row-key is composite: Collection Scope + Field name + Field value
Column name is composite: Entity ID + Entity Version
```

When we write we use a TTL value so our row and column will only live for a couple of seconds.

After we write that row and column we load it back and if what we load does not match what we wrote then our value was not unique, and we throw a duplicate value exception. If there is no duplicate value then we go ahead to the write commit stage and we re-write all of the unique values we stored before, but this time with no TTL because they are final.

**Here are the key interfaces and classes:**

```
UniqueValue: object that gets stored in the Unique Values column family
UniqueValueImpl

EntityVersion: entity ID and version, serves as Column Name in Unique Values CF
EntityVersionSerializer
EntityVersionSerializerTest

FieldSerializer: serializes a Field, only works for primative types (for now)
FieldSerializerTest

UniqueValueSerializationStrategy: writes and loads UniqueValues in Cassandra
UniqueValueSerializationStrategyImpl
UniqueValueSerializationStrategyImplTest

WriteCommit: re-writes any unique values with with no TTL

WriteUniqueVerify: checks for duplicates by writing and reading from Unique Values CF
```