com.netflix.astyanax.recipes.uniqueness
Class MultiRowUniquenessConstraint

java.lang.Object
  extended by com.netflix.astyanax.recipes.uniqueness.MultiRowUniquenessConstraint
All Implemented Interfaces:
UniquenessConstraint

public class MultiRowUniquenessConstraint
extends Object
implements UniquenessConstraint

Check uniqueness for multiple rows. This test is done by 1. First writing a unique column to all rows, in a single batch. Include a TTL for some failure conditions. 2. Reading back the unique columns from each row (must be done in a separate call) and making sure there is only one such column 3. Committing the columns without a TTL

Author:
elandau

Constructor Summary
MultiRowUniquenessConstraint(Keyspace keyspace)
           
 
Method Summary
 void acquire()
          Acquire the row(s) for uniqueness.
 void acquireAndMutate(MutationBatch mutation)
          Acquire the uniqueness constraint and apply the final mutation if the row if found to be unique
 String getLockColumn()
          Return the lock column written to ALL rows
 void release()
          Release the uniqueness lock for this row.
 MultiRowUniquenessConstraint withColumnPrefix(String prefix)
          Specify the prefix that uniquely distinguishes the lock columns from data columns
 MultiRowUniquenessConstraint withConsistencyLevel(ConsistencyLevel consistencyLevel)
          Consistency level used
 MultiRowUniquenessConstraint withLockId(String column)
          Override the autogenerated lock column.
 MultiRowUniquenessConstraint withRow(ColumnFamily<String,String> columnFamily, String rowKey)
          Add a row to the set of rows being tested for uniqueness
 MultiRowUniquenessConstraint withTtl(Integer ttl)
          TTL to use for the uniquness operation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MultiRowUniquenessConstraint

public MultiRowUniquenessConstraint(Keyspace keyspace)
Method Detail

withTtl

public MultiRowUniquenessConstraint withTtl(Integer ttl)
TTL to use for the uniquness operation. This is the TTL for the columns to expire in the event of a client crash before the uniqueness can be committed

Parameters:
ttl -
Returns:

withColumnPrefix

public MultiRowUniquenessConstraint withColumnPrefix(String prefix)
Specify the prefix that uniquely distinguishes the lock columns from data columns

Parameters:
prefix -
Returns:

withLockId

public MultiRowUniquenessConstraint withLockId(String column)
Override the autogenerated lock column.

Parameters:
column -
Returns:

withConsistencyLevel

public MultiRowUniquenessConstraint withConsistencyLevel(ConsistencyLevel consistencyLevel)
Consistency level used

Parameters:
consistencyLevel -
Returns:

withRow

public MultiRowUniquenessConstraint withRow(ColumnFamily<String,String> columnFamily,
                                            String rowKey)
Add a row to the set of rows being tested for uniqueness

Parameters:
columnFamily -
rowKey -
Returns:

getLockColumn

public String getLockColumn()
Return the lock column written to ALL rows

Returns:

acquire

public void acquire()
             throws NotUniqueException,
                    Exception
Description copied from interface: UniquenessConstraint
Acquire the row(s) for uniqueness. Call release() when the uniqueness on the row(s) is no longer needed, such as when deleting the rows.

Specified by:
acquire in interface UniquenessConstraint
Throws:
NotUniqueException
Exception

acquireAndMutate

public void acquireAndMutate(MutationBatch mutation)
                      throws NotUniqueException,
                             Exception
Description copied from interface: UniquenessConstraint
Acquire the uniqueness constraint and apply the final mutation if the row if found to be unique

Specified by:
acquireAndMutate in interface UniquenessConstraint
Throws:
NotUniqueException
Exception

release

public void release()
             throws Exception
Description copied from interface: UniquenessConstraint
Release the uniqueness lock for this row. Only call this when you no longer need the uniqueness lock

Specified by:
release in interface UniquenessConstraint
Throws:
Exception


Copyright © 2012. All Rights Reserved.